#include <OMKNameServer.h>
Inheritance diagram for OMK::NameServer:
Public Member Functions | |
NameServer () | |
default constructor. | |
NameServer (const NameServer::CanonicalRepresentationType *) | |
construction of a name server conformant to a canonical representation | |
virtual | ~NameServer () |
destructor | |
virtual void | printToStream (std::ostream &out, const std::string &separator) const |
print contents. | |
virtual bool | includes (const NameServer &otherNameServer) |
does the current name server include all the <id, string> pairs of otherNameServer | |
virtual Name::idType | getIdentifier (const std::string &) |
get the id corresponding to a string if the string is unknown to the name server, a new id will be added | |
virtual Name::idType | getSystemIdentifier (const std::string &) |
get the id corresponding to a string the string should correspond to a reserverd string | |
virtual Name::idType | getIdentifierAsFrom (const std::string &, Name::idType *nextId) |
get the id corresponding to a string, using a specified nextId counter used to implement getIdentifier and getSystemIdentifier | |
virtual const std::string & | getStringAssociatedTo (Name::idType id) const |
get the string associated to an id | |
virtual void | created (Name::idType id, Name *) |
a new Name of id id was created | |
virtual void | deleted (Name::idType id, Name *) |
a Name of id id was deleted | |
CanonicalRepresentationType * | getCanonicalRepresentation () const |
get the canonical representation once used, the result should be deleted | |
virtual const std::list< Name * > & | getNamesOfId (Name::idType) const |
get a list of pointers to the OMKNames corresponding to an id | |
Protected Types | |
typedef HASH_NAME_SPACE::hash_map< std::string, Name::idType, hash_compare_string > | correspondenceContainerType |
reference data structure type | |
typedef HASH_NAME_SPACE::hash_map< Name::idType, int, HASH_NAME_SPACE::hash< Name::idType > > | referenceCountingContainerType |
reference counting data structure type | |
typedef HASH_NAME_SPACE::hash_map< Name::idType, std::list< Name * > *, HASH_NAME_SPACE::hash< Name::idType > > | placeOfNamesContainerType |
reference counting data structure type | |
typedef std::map< Name::idType, correspondenceContainerType::iterator > | fastStringAccessTableType |
fast access data structure type | |
Protected Member Functions | |
void | changeNamesId (Name *namePointer, Name::idType oldId, Name::idType newId) |
change the id of a name | |
Protected Attributes | |
Name::idType | _nextIdentifier |
nextIdentifier to use | |
Name::idType | _nextSystemIdentifier |
next System Identifier to use | |
fastStringAccessTableType | _fastStringAccessTable |
fast access data structure | |
correspondenceContainerType | _stringToIdCorrespondenceContainer |
table holding String - id correspondance | |
referenceCountingContainerType | _tableNbInstances |
table holding reference counting | |
placeOfNamesContainerType | _idToNamesUsingIdContainer |
table holding the list of OMKNames memory spaces using a given id | |
Private Types | |
typedef std::pair< std::pair< Name::idType, std::string >, int > | CanonicalRepresentationItemType |
define what the canonical representation is | |
typedef std::list< CanonicalRepresentationItemType > | CanonicalRepresentationType |
Friends | |
OMK_API bool | operator== (const NameServer &, const NameServer &) |
Compare two name servers. | |
Classes | |
struct | hash_compare_string |
A name server is used so that instances of the Name class only store an Id. The name server keeps track of the corresponding string used at the creation of the Name. This enables fast creation and comparaison for equality between OMKNames. It also means that comparaison is _not_ done using lexicographic order. the Name class acts as a singleton ( see singleton pattern ) for name servers, so only one instance of a name server can be used at a time, and making sure the change of name server doesn't affect the string associated to the name ids. This is an abstract class, defining a canonical external representation for name servers so that they can be compared. This canonical representation is a list of pairs of id and their associated string, pair with the numer of occurences of the pair, ordered on the first element of the pair (the id). This representation is used for the construction of new name servers that don't change any string associated with a given id.
Definition at line 40 of file OMKNameServer.h.
typedef std::pair<std::pair<Name::idType,std::string>, int > OMK::NameServer::CanonicalRepresentationItemType [private] |
typedef std::list< CanonicalRepresentationItemType > OMK::NameServer::CanonicalRepresentationType [private] |
Definition at line 44 of file OMKNameServer.h.
typedef HASH_NAME_SPACE::hash_map<std::string, Name::idType, hash_compare_string > OMK::NameServer::correspondenceContainerType [protected] |
typedef HASH_NAME_SPACE::hash_map<Name::idType, int, HASH_NAME_SPACE::hash<Name::idType> > OMK::NameServer::referenceCountingContainerType [protected] |
typedef HASH_NAME_SPACE::hash_map<Name::idType, std::list<Name *> *, HASH_NAME_SPACE::hash<Name::idType> > OMK::NameServer::placeOfNamesContainerType [protected] |
typedef std::map<Name::idType, correspondenceContainerType::iterator > OMK::NameServer::fastStringAccessTableType [protected] |
NameServer::NameServer | ( | ) |
default constructor.
Definition at line 26 of file OMKNameServer.cpp.
References _fastStringAccessTable, OMK::Name::_maxReservedId, _nextIdentifier, _nextSystemIdentifier, _stringToIdCorrespondenceContainer, and _tableNbInstances.
00027 { 00028 _nextIdentifier = Name::_maxReservedId + 1 ; 00029 _nextSystemIdentifier = 1 ; 00030 00031 // keep id 0 reserved and associated to the string "Uninitialised Name" 00032 _tableNbInstances.insert ( referenceCountingContainerType::value_type(0, 0) ); 00033 correspondenceContainerType::iterator i=(_stringToIdCorrespondenceContainer.insert( correspondenceContainerType::value_type( std::string( "Uninitialised Name" ), 0 ) ) ).first; 00034 _fastStringAccessTable.clear(); 00035 _fastStringAccessTable.insert(std::pair<Name::idType, correspondenceContainerType::iterator>(0,i)); 00036 }
NameServer::NameServer | ( | const NameServer::CanonicalRepresentationType * | ) |
construction of a name server conformant to a canonical representation
Definition at line 38 of file OMKNameServer.cpp.
References _fastStringAccessTable, _nextIdentifier, _stringToIdCorrespondenceContainer, and _tableNbInstances.
00039 { 00040 for ( CanonicalRepresentationType::const_iterator i = canonicalRepresentation->begin() ; 00041 i != canonicalRepresentation->end() ; 00042 i++ ) 00043 { 00044 //(*i) is < <Name::idType,std::string> , numberOfInstances> therefore 00045 //(*i).first.first is the id, 00046 //(*i).first.second is the associated string 00047 //(*i).second is the number of instances of OMKNames with id as id 00048 00049 //first create an entry is the hash_table for the associated string 00050 correspondenceContainerType::iterator ii=(_stringToIdCorrespondenceContainer.insert( correspondenceContainerType::value_type((*i).first.second,(*i).first.first))).first; 00051 // then reference that entry in the iterator table 00052 _fastStringAccessTable.insert(std::pair<Name::idType, correspondenceContainerType::iterator>((*i).first.first,ii)); 00053 00054 //then take care of keeping care of the number of copies of id in the system 00055 _tableNbInstances[(*i).first.first] = (*i).second ; 00056 00057 //try and find a reasonnable next id 00058 _nextIdentifier = (*i).first.first + 1 ; 00059 } 00060 }
NameServer::~NameServer | ( | ) | [virtual] |
void NameServer::printToStream | ( | std::ostream & | out, | |
const std::string & | separator | |||
) | const [virtual] |
print contents.
The default version prints the canonical representation
Definition at line 291 of file OMKNameServer.cpp.
References getCanonicalRepresentation().
Referenced by includes(), and OMK::PvmNameServer::PvmNameServer().
00292 { 00293 //lock() ; 00294 CanonicalRepresentationType * canonicalRepresentation = getCanonicalRepresentation() ; 00295 for ( CanonicalRepresentationType::const_iterator i = canonicalRepresentation->begin() ; 00296 i != canonicalRepresentation->end() ; 00297 i++ ) 00298 { 00299 out << i->first.first << " " << i->first.second << " " << i->second << separator; 00300 } 00301 out<<endl; 00302 delete canonicalRepresentation; 00303 //unlock() ; 00304 }
bool NameServer::includes | ( | const NameServer & | otherNameServer | ) | [virtual] |
does the current name server include all the <id, string> pairs of otherNameServer
Reimplemented in OMK::PvmNameServer.
Definition at line 244 of file OMKNameServer.cpp.
References getCanonicalRepresentation(), OMK_DEBUG_OMK_NAME, OMTRACEID, and printToStream().
Referenced by OMK::Name::setNameServer().
00245 { 00246 OMTRACEID( OMK_DEBUG_OMK_NAME, "NameServer::includes" ) ; 00247 NameServer::CanonicalRepresentationType * canonicalRepresentation1 = otherNameServer.getCanonicalRepresentation() ; 00248 NameServer::CanonicalRepresentationType * canonicalRepresentation2 = getCanonicalRepresentation() ; 00249 NameServer::CanonicalRepresentationType::const_iterator iter1 = canonicalRepresentation1->begin() ; 00250 NameServer::CanonicalRepresentationType::const_iterator iter2 = canonicalRepresentation2->begin() ; 00251 bool noMissingPairFound = true ; 00252 bool found ; 00253 while ( noMissingPairFound && ( iter1 != canonicalRepresentation1->end() ) ) 00254 { 00255 // make sure (*iter1).first is in canonicalRepresentation2 00256 OMTRACEID( OMK_DEBUG_OMK_NAME, "looking for <" <<(*iter1).first.first << "," << (*iter1).first.second<< ">" ) ; 00257 found = false ; 00258 while ( (iter2 != canonicalRepresentation2->end()) && !found ) 00259 { 00260 OMTRACEID( OMK_DEBUG_OMK_NAME, "examined <"<<(*iter2).first.first<<","<<(*iter2).first.second<<"> " ) ; 00261 if ( (*iter2).first == (*iter1).first ) 00262 { 00263 OMTRACEID( OMK_DEBUG_OMK_NAME, "identic" ) ; 00264 found = true ; 00265 } 00266 ++iter2 ; 00267 } 00268 if ( ( iter2 == canonicalRepresentation2->end() ) && !found ) 00269 { 00270 noMissingPairFound = false ; 00271 #if !defined NDEBUG 00272 std::ostringstream msg ; 00273 msg << "<"<<(*iter1).first.first<<","<<(*iter1).first.second<<"> not found in " ; 00274 otherNameServer.printToStream( msg, " " ); 00275 OMTRACEID( OMK_DEBUG_OMK_NAME, msg.str() ) ; 00276 #endif 00277 } 00278 else 00279 { 00280 ++iter1 ; 00281 } 00282 } 00283 delete canonicalRepresentation1 ; 00284 delete canonicalRepresentation2 ; 00285 return noMissingPairFound ; 00286 }
Name::idType NameServer::getIdentifier | ( | const std::string & | ) | [virtual] |
get the id corresponding to a string if the string is unknown to the name server, a new id will be added
Definition at line 68 of file OMKNameServer.cpp.
References _nextIdentifier, and getIdentifierAsFrom().
Referenced by OMK::Name::extract(), OMK::Name::Name(), OMK::Name::operator=(), OMK::Svm::serveNameRequestsUntilEnd(), and OMK::PvmCentralNameServer::verifyCompatibilityWithLocalNameServer().
00069 { 00070 return getIdentifierAsFrom( name, &_nextIdentifier ) ; 00071 }
Name::idType NameServer::getSystemIdentifier | ( | const std::string & | ) | [virtual] |
get the id corresponding to a string the string should correspond to a reserverd string
Definition at line 74 of file OMKNameServer.cpp.
References OMK::Name::_maxReservedId, _nextSystemIdentifier, getIdentifierAsFrom(), and OMASSERTM.
00075 { 00076 00077 Name::idType result = getIdentifierAsFrom(name, &_nextSystemIdentifier) ; 00078 // this assertion could fail if a Name corresponding to a reserved id was staticaly created 00079 OMASSERTM( result <= Name::_maxReservedId, "" ) ; 00080 //this would fail if more reserved Id's are created than originaly planned for 00081 OMASSERTM( _nextSystemIdentifier <= Name::_maxReservedId, "" ) ; 00082 00083 return result ; 00084 }
Name::idType NameServer::getIdentifierAsFrom | ( | const std::string & | , | |
Name::idType * | nextId | |||
) | [virtual] |
get the id corresponding to a string, using a specified nextId counter used to implement getIdentifier and getSystemIdentifier
Reimplemented in OMK::PvmNameServer.
Definition at line 87 of file OMKNameServer.cpp.
References _fastStringAccessTable, and _stringToIdCorrespondenceContainer.
Referenced by getIdentifier(), and getSystemIdentifier().
00088 { 00089 correspondenceContainerType::iterator i = _stringToIdCorrespondenceContainer.find( name.c_str() ); 00090 00091 if (i == _stringToIdCorrespondenceContainer.end()) 00092 { 00093 //we are going to change the values contained in the NameServer 00094 //lock() ; 00095 00096 i = _stringToIdCorrespondenceContainer.find( name ) ; //name might have been added by an other process 00097 00098 if (i == _stringToIdCorrespondenceContainer.end() ) //we have to add name 00099 { 00100 std::pair<correspondenceContainerType::iterator,bool> res = _stringToIdCorrespondenceContainer.insert(correspondenceContainerType::value_type(name,*nextId)) ; 00101 00102 _fastStringAccessTable[*nextId] = res.first ; 00103 00104 *nextId = *nextId + 1 ; 00105 00106 i = res.first ; 00107 } 00108 00109 //unlock() ; 00110 } 00111 return (*i).second; 00112 }
const std::string & NameServer::getStringAssociatedTo | ( | Name::idType | id | ) | const [virtual] |
get the string associated to an id
Reimplemented in OMK::PvmNameServer.
Definition at line 114 of file OMKNameServer.cpp.
References _fastStringAccessTable, _nextIdentifier, and OMASSERTM.
Referenced by OMK::Name::getCString(), OMK::Name::getString(), OMK::Name::insertInStream(), and OMK::Svm::serveNameRequestsUntilEnd().
00115 { 00116 OMASSERTM( id<_nextIdentifier, "" ) ; 00117 return (*(*_fastStringAccessTable.find(id)).second).first ; 00118 }
void NameServer::created | ( | Name::idType | id, | |
Name * | ||||
) | [virtual] |
a new Name of id id was created
Reimplemented in OMK::PvmNameServer.
Definition at line 133 of file OMKNameServer.cpp.
References _idToNamesUsingIdContainer, _tableNbInstances, and OMASSERTM.
Referenced by OMK::Name::extract(), OMK::Name::Name(), OMK::Name::operator=(), and OMK::Name::unpack().
00134 { 00135 //lock() ; 00136 referenceCountingContainerType::iterator i = _tableNbInstances.find(id); 00137 if ( i == _tableNbInstances.end() ) 00138 { 00139 i = _tableNbInstances.insert(referenceCountingContainerType::value_type(id,1)).first; 00140 } 00141 else 00142 { 00143 ++(*i).second; 00144 } 00145 // do the same for _idToNamesUsingIdContainer 00146 placeOfNamesContainerType::iterator j = _idToNamesUsingIdContainer.find(id); 00147 if ( j == _idToNamesUsingIdContainer.end() ) 00148 { 00149 j = _idToNamesUsingIdContainer.insert(placeOfNamesContainerType::value_type(id,new std::list<Name *>() ) ).first ; 00150 } 00151 OMASSERTM( (*j).second != NULL, "" ) ; 00152 (*j).second->push_front( name ) ; 00153 00154 //unlock() ; 00155 }
void NameServer::deleted | ( | Name::idType | id, | |
Name * | ||||
) | [virtual] |
a Name of id id was deleted
Reimplemented in OMK::PvmNameServer.
Definition at line 157 of file OMKNameServer.cpp.
References _fastStringAccessTable, _idToNamesUsingIdContainer, _nextIdentifier, _stringToIdCorrespondenceContainer, _tableNbInstances, OMASSERTM, and OMERROR.
Referenced by OMK::Name::extract(), OMK::Name::operator=(), OMK::Name::unpack(), and OMK::Name::~Name().
00158 { 00159 //lock() ; 00160 00161 referenceCountingContainerType::iterator i( _tableNbInstances.find( id ) ) ; 00162 if ( i != _tableNbInstances.end() ) 00163 { 00164 --( i->second ); 00165 00166 //must remove name from _idToNamesUsingIdContainer, once 00167 placeOfNamesContainerType::iterator j = _idToNamesUsingIdContainer.find(id); 00168 if ( j != _idToNamesUsingIdContainer.end() ) 00169 { 00170 OMASSERTM((*j).second != NULL, "a problem has occured" ) ; 00171 std::list<Name *>::iterator k = (*j).second->begin() ; 00172 while ( *k != name ) 00173 { 00174 OMASSERTM( k != (*j).second->end(), "" ) ; 00175 ++k ; 00176 } 00177 00178 OMASSERTM( k != (*j).second->end(), "a problem has occured" ) ; 00179 00180 (*j).second->erase ( k ) ; 00181 } 00182 else 00183 { 00184 //there has been a problem 00185 OMASSERTM( false, "" ) ; 00186 } 00187 00188 //keep the string associated to id 0 00189 if( ( (*i).second <= 0) && ( id != 0 ) ) 00190 { 00191 //if a string correponds, delete it 00192 if ( _fastStringAccessTable.find(id) != _fastStringAccessTable.end() ) 00193 { 00194 _stringToIdCorrespondenceContainer.erase(_fastStringAccessTable[id]); 00195 _fastStringAccessTable.erase(_fastStringAccessTable.find(id)); 00196 } 00197 00198 _tableNbInstances.erase(i); 00199 00200 OMASSERTM((*j).second != NULL, "a problem has occured" ) ; 00201 delete (*j).second ; 00202 _idToNamesUsingIdContainer.erase (j) ; 00203 00204 OMASSERTM( _tableNbInstances.find(id) == _tableNbInstances.end(), "" ) ; 00205 00206 if (id==_nextIdentifier-1) 00207 { 00208 _nextIdentifier=_nextIdentifier-1; 00209 } 00210 } 00211 } 00212 else 00213 { 00214 OMERROR( id ) ; 00215 } 00216 00217 //unlock() ; 00218 }
NameServer::CanonicalRepresentationType * NameServer::getCanonicalRepresentation | ( | ) | const |
get the canonical representation once used, the result should be deleted
Definition at line 121 of file OMKNameServer.cpp.
References _stringToIdCorrespondenceContainer, and _tableNbInstances.
Referenced by includes(), OMK::operator==(), and printToStream().
00122 { 00123 NameServer::CanonicalRepresentationType * canonicalRepresentation = new NameServer::CanonicalRepresentationType() ; 00124 NameServer::correspondenceContainerType::const_iterator i; 00125 for (i=_stringToIdCorrespondenceContainer.begin(); i!=_stringToIdCorrespondenceContainer.end();i++) 00126 { 00127 canonicalRepresentation->push_back(CanonicalRepresentationItemType(std::pair<Name::idType,std::string>((*i).second,(*i).first),(*(_tableNbInstances.find((*i).second))).second)) ; 00128 } 00129 canonicalRepresentation->sort() ; 00130 return canonicalRepresentation ; 00131 }
const std::list< Name * > & NameServer::getNamesOfId | ( | Name::idType | ) | const [virtual] |
get a list of pointers to the OMKNames corresponding to an id
Definition at line 220 of file OMKNameServer.cpp.
References _idToNamesUsingIdContainer, and OMASSERTM.
Referenced by OMK::PvmCentralNameServer::PvmCentralNameServer(), and OMK::PvmNameServer::PvmNameServer().
00221 { 00222 placeOfNamesContainerType::const_iterator j = _idToNamesUsingIdContainer.find(id); 00223 00224 OMASSERTM( j != _idToNamesUsingIdContainer.end(), "" ) ; 00225 00226 OMASSERTM( (*j).second != NULL, "" ) ; 00227 00228 return *(*j).second ; 00229 }
void NameServer::changeNamesId | ( | Name * | namePointer, | |
Name::idType | oldId, | |||
Name::idType | newId | |||
) | [protected] |
change the id of a name
namePointer | to the Name to change | |
oldId | the names old id | |
newId | the new id |
Definition at line 306 of file OMKNameServer.cpp.
References OMK::Name::changeId(), and OMASSERTM.
Referenced by OMK::PvmNameServer::PvmNameServer().
00307 { 00308 OMASSERTM( namePointer != NULL, "Must be a valid pointer" ) ; 00309 namePointer->changeId ( oldId, newId ) ; 00310 }
OMK_API bool operator== | ( | const NameServer & | source1, | |
const NameServer & | source2 | |||
) | [friend] |
Compare two name servers.
Definition at line 232 of file OMKNameServer.cpp.
00233 { 00234 NameServer::CanonicalRepresentationType * canonicalRepresentation1 = source1.getCanonicalRepresentation() ; 00235 NameServer::CanonicalRepresentationType * canonicalRepresentation2 = source2.getCanonicalRepresentation() ; 00236 bool resul = *canonicalRepresentation1 == *canonicalRepresentation2 ; 00237 delete canonicalRepresentation1 ; 00238 delete canonicalRepresentation2 ; 00239 return resul ; 00240 }
Name::idType OMK::NameServer::_nextIdentifier [protected] |
nextIdentifier to use
Definition at line 107 of file OMKNameServer.h.
Referenced by deleted(), getIdentifier(), getStringAssociatedTo(), OMK::PvmNameServer::getStringAssociatedToOnCentralServer(), NameServer(), OMK::PvmNameServer::PvmNameServer(), and OMK::PvmCentralNameServer::verifyCompatibilityWithLocalNameServer().
Name::idType OMK::NameServer::_nextSystemIdentifier [protected] |
next System Identifier to use
Definition at line 111 of file OMKNameServer.h.
Referenced by getSystemIdentifier(), and NameServer().
fast access data structure
Definition at line 151 of file OMKNameServer.h.
Referenced by deleted(), OMK::PvmNameServer::getIdentifierAsFrom(), getIdentifierAsFrom(), OMK::PvmNameServer::getStringAssociatedTo(), getStringAssociatedTo(), OMK::PvmNameServer::getStringAssociatedToOnCentralServer(), NameServer(), OMK::PvmNameServer::PvmNameServer(), and OMK::PvmCentralNameServer::verifyCompatibilityWithLocalNameServer().
table holding String - id correspondance
Definition at line 154 of file OMKNameServer.h.
Referenced by deleted(), getCanonicalRepresentation(), OMK::PvmNameServer::getIdentifierAsFrom(), getIdentifierAsFrom(), OMK::PvmNameServer::getStringAssociatedToOnCentralServer(), NameServer(), OMK::PvmCentralNameServer::PvmCentralNameServer(), OMK::PvmNameServer::PvmNameServer(), and OMK::PvmCentralNameServer::verifyCompatibilityWithLocalNameServer().
table holding reference counting
Definition at line 157 of file OMKNameServer.h.
Referenced by created(), deleted(), getCanonicalRepresentation(), NameServer(), OMK::PvmCentralNameServer::PvmCentralNameServer(), and OMK::PvmNameServer::PvmNameServer().
table holding the list of OMKNames memory spaces using a given id
Definition at line 160 of file OMKNameServer.h.
Referenced by created(), deleted(), getNamesOfId(), OMK::PvmCentralNameServer::PvmCentralNameServer(), and OMK::PvmNameServer::PvmNameServer().
Documentation generated on Mon Jun 9 11:46:02 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |