Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsNameServer Class Reference

Defines a name server for PsNames. More...

#include <PsNameServer.h>

Inheritance diagram for PsNameServer:

Inheritance graph
[legend]
List of all members.

Public Types

typedef PsList< PsPair< PsPair<
PsName::idType, PsString >,
int > > 
CanonicalRepresentationType
 define what the canonical representation is


Public Methods

 PsNameServer ()
 constructor, empty

virtual ~PsNameServer ()
 destructor, empty but needed because the default destructor is not created virtual

virtual long getIdentifier (const PsString &)=0
 get the id corresponding to a string if the string is unknown to the name server, a new id will be added

virtual long getSystemIdentifier (const PsString &)=0
 get the id corresponding to a string the string should correspond to a reserverd string

virtual const PsStringgetStringAssociatedTo (PsName::idType id) const=0
 get the string associated to an id

virtual void printToStream (ostream &out, const string &separator) const
 print contents.

virtual bool includes (const PsNameServer &otherNameServer)
 does the current name server include all the <id, string> pairs of otherNameServer

virtual void created (PsName::idType, PsName *)=0
 used by PsName for reference counting

virtual void deleted (PsName::idType, PsName *)=0
 used by PsName for referenve counting

virtual CanonicalRepresentationTypegetCanonicalRepresentation () const=0
 get the canonical representation once used, the result should be deleted

virtual const list< PsName * > & getNamesOfId (PsName::idType) const=0
 get a list of pointers to the PsNames corresponding to an id


Protected Methods

virtual void lock () const=0
 lock data in a multithread environment

virtual void unlock () const=0
 unlock data in a multithread environment

void changeNamesId (PsName *namePointer, PsName::idType oldId, PsName::idType newId)
 change the id of a name


Friends

bool operator== (const PsNameServer &, const PsNameServer &)
 Compare two name servers.


Detailed Description

Defines a name server for PsNames.

A name server is used so that instances of the PsName class only store an Id. The name server keeps track of the corresponding string used at the creation of the PsName. This enables fast creation and comparaison for equality between PsNames. It also means that comparaison is _not_ done using lexicographic order. the PsName 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 PsString, 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.

Author:
David Margery
Version:
2.0

Definition at line 41 of file PsNameServer.h.


Member Typedef Documentation

typedef PsList<PsPair<PsPair<PsName::idType,PsString>, int > > PsNameServer::CanonicalRepresentationType
 

define what the canonical representation is

Definition at line 91 of file PsNameServer.h.

Referenced by PsNoRefCountingNameServer< STLallocator >::getCanonicalRepresentation(), and PsNameServerT< STLallocator >::getCanonicalRepresentation().


Constructor & Destructor Documentation

PsNameServer::PsNameServer  
 

constructor, empty

Definition at line 22 of file PsNameServer.cxx.

00023 {
00024 }

PsNameServer::~PsNameServer   [virtual]
 

destructor, empty but needed because the default destructor is not created virtual

Definition at line 27 of file PsNameServer.cxx.

00028 {
00029 }


Member Function Documentation

void PsNameServer::changeNamesId PsName   namePointer,
PsName::idType    oldId,
PsName::idType    newId
[protected]
 

change the id of a name

Parameters:
namePointer to the PsName to change
oldId the names old id
newId the new id

Definition at line 114 of file PsNameServer.cxx.

References PsName::changeId(), and PsName::idType.

00115 {
00116    assert (namePointer != NULL ) ;
00117    namePointer->changeId ( oldId, newId ) ;
00118 }

virtual void PsNameServer::created PsName::idType   ,
PsName  
[pure virtual]
 

used by PsName for reference counting

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, PsPvmNameServer, and PsNameServerT< STL_ALLOC >.

Referenced by PsName::extract(), PsName::operator=(), PsName::PsName(), and PsName::unpack().

virtual void PsNameServer::deleted PsName::idType   ,
PsName  
[pure virtual]
 

used by PsName for referenve counting

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, PsPvmNameServer, and PsNameServerT< STL_ALLOC >.

Referenced by PsName::extract(), PsName::operator=(), PsName::unpack(), and PsName::~PsName().

virtual CanonicalRepresentationType* PsNameServer::getCanonicalRepresentation   const [pure virtual]
 

get the canonical representation once used, the result should be deleted

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

Referenced by includes(), operator==(), printToStream(), and PsMultiThreadedController::PsMultiThreadedController().

virtual long PsNameServer::getIdentifier const PsString   [pure virtual]
 

get the id corresponding to a string if the string is unknown to the name server, a new id will be added

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

Referenced by PsName::extract(), PsName::operator=(), and PsName::PsName().

virtual const list<PsName *>& PsNameServer::getNamesOfId PsName::idType    const [pure virtual]
 

get a list of pointers to the PsNames corresponding to an id

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

virtual const PsString& PsNameServer::getStringAssociatedTo PsName::idType    id const [pure virtual]
 

get the string associated to an id

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, PsPvmNameServer, and PsNameServerT< STL_ALLOC >.

Referenced by PsName::getPsString(), and PsName::insertInStream().

virtual long PsNameServer::getSystemIdentifier const PsString   [pure virtual]
 

get the id corresponding to a string the string should correspond to a reserverd string

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

bool PsNameServer::includes const PsNameServer &    otherNameServer [virtual]
 

does the current name server include all the <id, string> pairs of otherNameServer

Reimplemented in PsPvmNameServer.

Definition at line 44 of file PsNameServer.cxx.

References list< Type, allocator >::begin(), list< Type, allocator >::end(), getCanonicalRepresentation(), and printToStream().

Referenced by PsName::setNameServer().

00045 {
00046 #ifdef _DEBUGDISTRIBUTEDNAMESERVER
00047        cerr<<"PsNameServer::includes"<<endl;
00048 #endif
00049    PsNameServer::CanonicalRepresentationType * canonicalRepresentation1 = otherNameServer.getCanonicalRepresentation() ;
00050    PsNameServer::CanonicalRepresentationType * canonicalRepresentation2 = getCanonicalRepresentation() ;
00051    PsNameServer::CanonicalRepresentationType::const_iterator iter1 = canonicalRepresentation1->begin() ;
00052    PsNameServer::CanonicalRepresentationType::const_iterator iter2 = canonicalRepresentation2->begin() ;
00053    bool noMissingPairFound = true ;
00054    bool found ;
00055    while ( noMissingPairFound && 
00056            (iter1 != canonicalRepresentation1->end() ) )
00057      {
00058        // make sure (*iter1).first is in canonicalRepresentation2
00059 #ifdef _DEBUGDISTRIBUTEDNAMESERVER
00060        cerr<<"looking for <"<<(*iter1).first.first<<","<<(*iter1).first.second<<">"<<endl;
00061 #endif
00062        found = false ;
00063        while ( (iter2 != canonicalRepresentation2->end()) && 
00064                !found )
00065          {
00066 #ifdef _DEBUGDISTRIBUTEDNAMESERVER
00067            cerr<<"   examined <"<<(*iter2).first.first<<","<<(*iter2).first.second<<"> ";
00068 #endif
00069            if ( (*iter2).first == (*iter1).first )
00070              {
00071 #ifdef _DEBUGDISTRIBUTEDNAMESERVER
00072                cerr<<"identic"<<endl;
00073 #endif
00074                found = true ;
00075              }
00076            ++iter2 ;
00077          }
00078        if ( (iter2 == canonicalRepresentation2->end())
00079             && !found )
00080          {
00081            noMissingPairFound = false ;
00082 #ifdef _DEBUGDISTRIBUTEDNAMESERVER
00083            cerr<<"<"<<(*iter1).first.first<<","<<(*iter1).first.second<<"> not found in ";
00084            otherNameServer.printToStream (cout, " ");
00085 #endif
00086          }
00087        else
00088          {
00089            ++iter1 ;
00090          }
00091      }
00092    delete canonicalRepresentation1 ;
00093    delete canonicalRepresentation2 ;
00094    return noMissingPairFound ;
00095 }

virtual void PsNameServer::lock   const [protected, pure virtual]
 

lock data in a multithread environment

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

Referenced by printToStream().

void PsNameServer::printToStream ostream &    out,
const string &    separator
const [virtual]
 

print contents.

The default version prints the canonical representation

Definition at line 100 of file PsNameServer.cxx.

References list< Type, allocator >::begin(), list< Type, allocator >::end(), getCanonicalRepresentation(), lock(), and unlock().

Referenced by PsController::destroyObject(), and includes().

00101 {
00102    lock() ;
00103    CanonicalRepresentationType * canonicalRepresentation = getCanonicalRepresentation() ;
00104    for ( CanonicalRepresentationType::const_iterator i = canonicalRepresentation->begin() ;
00105          i != canonicalRepresentation->end() ;
00106          i++ )
00107       {
00108          out<<*i<<separator;
00109       } 
00110    out<<endl;
00111    unlock() ;
00112 }

virtual void PsNameServer::unlock   const [protected, pure virtual]
 

unlock data in a multithread environment

Implemented in PsNameServerT< STLallocator >, PsNoRefCountingNameServer< STLallocator >, and PsNameServerT< STL_ALLOC >.

Referenced by printToStream().


Friends And Related Function Documentation

bool operator== const PsNameServer &    source1,
const PsNameServer &    source2
[friend]
 

Compare two name servers.

Definition at line 32 of file PsNameServer.cxx.

00033 {
00034    PsNameServer::CanonicalRepresentationType * canonicalRepresentation1 = source1.getCanonicalRepresentation() ;
00035    PsNameServer::CanonicalRepresentationType * canonicalRepresentation2 = source2.getCanonicalRepresentation() ;
00036    bool resul = *canonicalRepresentation1 == *canonicalRepresentation2 ;
00037    delete canonicalRepresentation1 ;
00038    delete canonicalRepresentation2 ;
00039    return resul ;
00040 }


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:26:14 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001