00001 /* 00002 * This file is part of openMask � INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Universit� de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #include <OMKNameServer.h> 00019 #include <OMKPolator.h> 00020 #include "OMKOutgoingSynchronisationMessage.h" 00021 00022 using namespace std ; 00023 using namespace OMK ; 00024 00025 NameServer * Name::_nameServer = getNameServer() ; 00026 const Name::idType Name::_maxReservedId = 21 ; 00027 00028 NameServer * 00029 Name::getNameServer () 00030 { 00031 static bool initialised = false ; 00032 if ( ! initialised ) 00033 { 00034 _nameServer = new NameServer () ; 00035 initialised = true ; 00036 } 00037 return _nameServer ; 00038 } 00039 00040 00041 void 00042 Name::setNameServer ( NameServer * newNameServer ) 00043 { 00044 // the new name server is only installed if it has the same pairs <id,char *> as the old one. 00045 if ( newNameServer->includes( *_nameServer ) ) 00046 { 00047 _nameServer = newNameServer ; 00048 } 00049 else 00050 { 00051 OMMESSAGE( "WARNING : the name server wasn't changed because it wasn't equal to the old one" ); 00052 } 00053 } 00054 00055 00056 Name::Name(idType i) 00057 { 00058 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(idType " << i << " )" ) ; 00059 OMASSERT( i < _maxReservedId ) ; 00060 _identifier = i ; 00061 getNameServer()->created( _identifier , this ); 00062 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(idType) end" ) ; 00063 } 00064 00065 Name::Name() 00066 { 00067 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name()" ) ; 00068 _identifier=0; 00069 getNameServer()->created( _identifier, this ); 00070 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name() end" ) ; 00071 } 00072 00073 Name::Name(const char * name) 00074 { 00075 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const char * (" << (void*)name << ")\"" << name << "\" )" 00076 << endl <<"Name server = " << (void*)getNameServer() ) ; 00077 _identifier = getNameServer()->getIdentifier(std::string(name)); 00078 getNameServer()->created( _identifier, this ) ; 00079 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const char *) end" ); 00080 } 00081 00082 00083 00084 Name::Name(const std::string & name) 00085 { 00086 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const std::string & \"" << name << "\" )" 00087 << endl <<"Name server = " << (void*)getNameServer() ) ; 00088 _identifier = getNameServer()->getIdentifier(name); 00089 getNameServer()->created( _identifier, this ) ; 00090 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const std::string &) end" ) ; 00091 } 00092 00093 00094 Name::Name(const Name & aCopier) 00095 { 00096 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const Name & \"" << aCopier << "\") " << aCopier._identifier ) ; 00097 _identifier = aCopier._identifier; 00098 getNameServer()->created(_identifier,this); 00099 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::Name(const Name &) end" ) ; 00100 } 00101 00102 Name::~Name() 00103 { 00104 getNameServer()->deleted( _identifier, this ); 00105 } 00106 00107 00108 00109 OMK::Type::PolatorNT * Name::createPolator (void) 00110 { 00111 return new OMK::Type::Polator<Name>(); 00112 } 00113 00114 00115 const char * Name::getCString() const 00116 { 00117 //OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::getCString()" ) ; 00118 const char * result = ( getNameServer()->getStringAssociatedTo( _identifier ) ).c_str() ; 00119 //OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::getCString() returns \"" << resul << "\"" ) ; 00120 return result ; 00121 } 00122 00123 const std::string & Name::getString() const 00124 { 00125 OMTRACEID( OMK_DEBUG_OMK_NAME, "Name::getString()" ) ; 00126 return getNameServer()->getStringAssociatedTo( _identifier ) ; 00127 } 00128 00129 00130 void Name::insertInStream( ostream & out ) const 00131 { 00132 // cerr<<"Name::insertInStream of id "<<_identifier<<endl; 00133 // cerr<<"Name::insertInStream of "<<getNameServer()->getStringAssociatedTo(_identifier)<<endl; 00134 out << getNameServer()->getStringAssociatedTo( _identifier ); 00135 } 00136 00137 00138 void Name::extract(istream & in) 00139 { 00140 std::string name ; 00141 in >> name ; 00142 idType oldIdentifier = _identifier ; 00143 00144 _identifier = getNameServer()->getIdentifier ( name ); 00145 00146 getNameServer()->created( _identifier, this ); 00147 00148 getNameServer()->deleted( oldIdentifier, this ); 00149 } 00150 00151 00152 00153 00154 00155 00156 Name & Name::operator = (const std::string & original) 00157 { 00158 // copy into onself : creation must happen before deletion 00159 idType oldIdentifier = _identifier ; 00160 00161 _identifier = getNameServer()->getIdentifier( original ); 00162 00163 getNameServer()->created(_identifier, this); 00164 00165 getNameServer()->deleted( oldIdentifier, this ); 00166 00167 return *this; 00168 } 00169 00170 00171 Name & Name::operator = (const char * original) 00172 { 00173 return *this = std::string( original ) ; 00174 } 00175 00176 00177 Name & Name::operator = (const Name & aCopier) 00178 { 00179 // copy into onself 00180 idType oldIdentifier = _identifier ; 00181 00182 _identifier = aCopier._identifier; 00183 getNameServer()->created( _identifier, this ); 00184 00185 getNameServer()->deleted( oldIdentifier, this ); 00186 00187 return *this; 00188 } 00189 00190 00191 bool OMK::operator < (const Name & premier, const Name & second) 00192 { 00193 return premier._identifier < second._identifier; 00194 } 00195 00196 00197 bool OMK::operator > (const Name & premier, const Name & second) 00198 { 00199 return premier._identifier > second._identifier; 00200 } 00201 00202 00203 bool OMK::operator <= (const Name & premier, const Name & second) 00204 { 00205 return premier._identifier <= second._identifier; 00206 } 00207 00208 00209 00210 bool OMK::operator >= (const Name & premier, const Name & second) 00211 { 00212 return premier._identifier >= second._identifier; 00213 } 00214 00215 00216 void Name::unpack (IncomingSynchronisationMessage & in ) 00217 { 00218 idType oldIdentifier = _identifier ; 00219 00220 in>>_identifier ; 00221 getNameServer()->created( _identifier, this ); 00222 00223 getNameServer()->deleted( oldIdentifier, this ); 00224 } 00225 00226 00227 void Name::pack (OutgoingSynchronisationMessage & out) const 00228 { 00229 out << _identifier ; 00230 } 00231 00232 void Name::changeId ( idType oldId, idType newId ) 00233 { 00234 //cerr<<"Name::changeId ( "<<oldId< <", "<<newId<<" ) "<<endl; 00235 //this is called by the name server : do not need to call back to keep the books 00236 OMASSERTM( oldId == _identifier, "" ) ; 00237 00238 _identifier = newId ; 00239 } 00240 00241 00242
Documentation generated on Mon Jun 9 11:45:57 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |