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

PsNoRefCountingNameServer< STLallocator > Class Template Reference

templated name server, that doesn't do any ref counting this class is templated by the allocator used for allocation of it's internal data. More...

#include <PsNoRefCountingNameServer.h>

Inheritance diagram for PsNoRefCountingNameServer< STLallocator >:

Inheritance graph
[legend]
Collaboration diagram for PsNoRefCountingNameServer< STLallocator >:

Collaboration graph
[legend]
List of all members.

Public Methods

virtual ~PsNoRefCountingNameServer ()
 destructor

 PsNoRefCountingNameServer (const PsNameServer::CanonicalRepresentationType *canonicalRepresentation)
 construction of a name server conformant to a canonical representation

virtual long getIdentifier (const PsString &)
 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 &)
 get the id corresponding to a string the string should correspond to a reserverd string

virtual long getIdentifierAsFrom (const PsString &, long *nextId)
 get the id corresponding to a string, using a specified nextId counter used to implement getIdentifier and getSystemIdentifier

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

void * operator new (size_t)
 redefine new so that the nameserver is located in the same memory space than it's data structures and their elements

void operator delete (void *ptr, size_t n)
 redefine delete 'cause new was redefined

virtual void created (PsName::idType id, PsName *)
 a new PsName of id id was created

virtual void deleted (PsName::idType id, PsName *)
 a PsName of id id was deleted

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

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


Protected Types

typedef hash_map< PsString,
long, PsString_hash,equal_to<
PsString >, STLallocator<
pair< PsString, long > > > 
correspondenceContainerType
 reference data structure type

typedef map< long, typename
correspondenceContainerType::iterator,
less< long >, STLallocator<
pair< const long, typename
correspondenceContainerType::iterator > > > 
fastStringAccessTableType
 fast access data structure type


Protected Methods

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

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


Protected Attributes

PsnMutexLock _ourDataLock
 the lock for multi-threaded environements

long _nextIdentifier
 nextIdentifier to use

long _nextSystemIdentifier
 next System Identifier to use

fastStringAccessTableType _fastStringAccessTable
 fast access data structure

correspondenceContainerType _stringToIdCorrespondenceContainer
 table holding String - id correspondance


Detailed Description

template<template< typename T > class STLallocator>
class PsNoRefCountingNameServer< STLallocator >

templated name server, that doesn't do any ref counting this class is templated by the allocator used for allocation of it's internal data.

Therefore, it comes in two flavours, depending of the type of allocators used by the underlying standard library.

Author:
David Margery
Version:
1.0 : version working with old or new allocators

Definition at line 37 of file PsNoRefCountingNameServer.h.


Member Typedef Documentation

template<template< typename T > class STLallocator>
typedef hash_map<PsString,long, PsString_hash ,equal_to<PsString>,STLallocator<pair <PsString,long> > > PsNoRefCountingNameServer< STLallocator >::correspondenceContainerType [protected]
 

reference data structure type

Definition at line 115 of file PsNoRefCountingNameServer.h.

template<template< typename T > class STLallocator>
typedef map<long, typename correspondenceContainerType::iterator,less<long>,STLallocator<pair<const long, typename correspondenceContainerType::iterator> > > PsNoRefCountingNameServer< STLallocator >::fastStringAccessTableType [protected]
 

fast access data structure type

Definition at line 118 of file PsNoRefCountingNameServer.h.


Constructor & Destructor Documentation

template<template< typename T > class STLallocator>
PsNoRefCountingNameServer< STLallocator >::~PsNoRefCountingNameServer   [virtual]
 

destructor

Definition at line 168 of file PsNoRefCountingNameServer.h.

00170 {
00171    //nothing to do   

template<template< typename T > class STLallocator>
PsNoRefCountingNameServer< STLallocator >::PsNoRefCountingNameServer const PsNameServer::CanonicalRepresentationType   canonicalRepresentation
 

construction of a name server conformant to a canonical representation

Definition at line 134 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_fastStringAccessTable, PsNoRefCountingNameServer< STLallocator >::_nextIdentifier, PsNoRefCountingNameServer< STLallocator >::_stringToIdCorrespondenceContainer, list< Type, allocator >::begin(), list< Type, allocator >::end(), map< long, typename correspondenceContainerType::iterator, less< long >, STLallocator< pair< const long, typename correspondenceContainerType::iterator > > >::insert(), and hash_map< Key, T, HashFcn, EqualKey, Alloc >::insert().

00136 {
00137    //cerr<<"PsNoRefCountingNameServer<STLallocator>:"<<this<<":PsNoRefCountingNameServer(const PsNameServer::CanonicalRepresentationType * canonicalRepresentation)"<<endl;
00138     for ( CanonicalRepresentationType::const_iterator i = canonicalRepresentation->begin() ;
00139          i != canonicalRepresentation->end() ;
00140          i++ )
00141       {
00142          //(*i) is < <PsName::idType,PsString> , numberOfInstances> therefore
00143          //(*i).first.first is the id,
00144          //(*i).first.second is the associated string
00145          //(*i).second is the number of instances of PsNames with id as id
00146 
00147          //first create an entry in the hash_table for the associated string
00148 #ifdef _TYPENAMENOTIMPLICIT
00149          typename correspondenceContainerType::iterator ii=(_stringToIdCorrespondenceContainer.insert(typename correspondenceContainerType::value_type((*i).first.second,(*i).first.first))).first;
00150          // then reference that entry in the iterator table 
00151          _fastStringAccessTable.insert(pair<const long, typename correspondenceContainerType::iterator>((*i).first.first,ii));   
00152 #else
00153          correspondenceContainerType::iterator ii=(_stringToIdCorrespondenceContainer.insert(correspondenceContainerType::value_type((*i).first.second,(*i).first.first))).first;
00154          // then reference that entry in the iterator table 
00155          _fastStringAccessTable.insert(pair<const long, correspondenceContainerType::iterator>((*i).first.first,ii));    
00156 #endif
00157 
00158          //try and find a reasonnable next id
00159          _nextIdentifier = (*i).first.first + 1 ;
00160       }


Member Function Documentation

template<template< typename T > class STLallocator>
void PsNoRefCountingNameServer< STLallocator >::created PsName::idType    id,
PsName  
[virtual]
 

a new PsName of id id was created

Implements PsNameServer.

Definition at line 325 of file PsNoRefCountingNameServer.h.

References PsName::idType.

00327 {

template<template< typename T > class STLallocator>
void PsNoRefCountingNameServer< STLallocator >::deleted PsName::idType    id,
PsName  
[virtual]
 

a PsName of id id was deleted

Implements PsNameServer.

Definition at line 334 of file PsNoRefCountingNameServer.h.

References PsName::idType.

00336 {

template<template< typename T > class STLallocator>
PsNameServer::CanonicalRepresentationType * PsNoRefCountingNameServer< STLallocator >::getCanonicalRepresentation   const [virtual]
 

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

Implements PsNameServer.

Definition at line 269 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_stringToIdCorrespondenceContainer, hash_map< Key, T, HashFcn, EqualKey, Alloc >::begin(), PsNameServer::CanonicalRepresentationType, hash_map< Key, T, HashFcn, EqualKey, Alloc >::end(), list< Type, allocator >::push_back(), and list< Type, allocator >::sort().

00271 {
00272    PsNameServer::CanonicalRepresentationType * canonicalRepresentation = new PsNameServer::CanonicalRepresentationType () ;
00273 #ifdef _TYPENAMENOTIMPLICIT
00274    typename
00275 #endif
00276    PsNoRefCountingNameServer<STLallocator>::correspondenceContainerType::const_iterator i;
00277    for (i=_stringToIdCorrespondenceContainer.begin(); i!=_stringToIdCorrespondenceContainer.end();i++) 
00278       {
00279          canonicalRepresentation->push_back(PsPair<PsPair<PsName::idType,PsString>, int>(PsPair<PsName::idType,PsString>((*i).second,(*i).first),1)) ;
00280       }
00281    canonicalRepresentation->sort() ;
00282    return canonicalRepresentation ;

template<template< typename T > class STLallocator>
PsName::idType PsNoRefCountingNameServer< STLallocator >::getIdentifier const PsString   [virtual]
 

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

Implements PsNameServer.

Definition at line 180 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_nextIdentifier, PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom(), and PsName::idType.

00182 {
00183    PsName::idType res;
00184    //cerr<<this<<" "<<_nextIdentifier<<" ";
00185    res = getIdentifierAsFrom(name, &_nextIdentifier) ;
00186    //cerr<<"("<<res<<","<<name<<") added to name server "<<_nextIdentifier<<endl;
00187    return res;

template<template< typename T > class STLallocator>
PsName::idType PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom const PsString  ,
long *    nextId
[virtual]
 

get the id corresponding to a string, using a specified nextId counter used to implement getIdentifier and getSystemIdentifier

Definition at line 215 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_fastStringAccessTable, PsNoRefCountingNameServer< STLallocator >::_stringToIdCorrespondenceContainer, hash_map< Key, T, HashFcn, EqualKey, Alloc >::end(), hash_map< Key, T, HashFcn, EqualKey, Alloc >::find(), pair< T1, T2 >::first, PsName::idType, hash_map< Key, T, HashFcn, EqualKey, Alloc >::insert(), PsNoRefCountingNameServer< STLallocator >::lock(), and PsNoRefCountingNameServer< STLallocator >::unlock().

Referenced by PsNoRefCountingNameServer< STLallocator >::getIdentifier(), and PsNoRefCountingNameServer< STLallocator >::getSystemIdentifier().

00216                                                                                                    {
00217 
00218 #ifdef _TYPENAMENOTIMPLICIT
00219    typename
00220 #endif
00221    correspondenceContainerType::iterator i = _stringToIdCorrespondenceContainer.find( name );
00222 
00223    if (i == _stringToIdCorrespondenceContainer.end()) 
00224       {
00225          //we are going to change the values contained in the PsNameServer
00226          lock() ; 
00227 
00228          i = _stringToIdCorrespondenceContainer.find( name ) ; //name might have been added by an other process
00229 
00230          if (i == _stringToIdCorrespondenceContainer.end() ) //we have to add name
00231             { 
00232 
00233 #ifdef _TYPENAMENOTIMPLICIT
00234                pair<typename correspondenceContainerType::iterator,bool> res = _stringToIdCorrespondenceContainer.insert(typename correspondenceContainerType::value_type(name,*nextId)) ;
00235 #else
00236                pair<correspondenceContainerType::iterator,bool> res = _stringToIdCorrespondenceContainer.insert(correspondenceContainerType::value_type(name,*nextId)) ;
00237 #endif
00238  
00239                _fastStringAccessTable[*nextId] = res.first ;
00240 
00241                *nextId = *nextId + 1 ;
00242                
00243                i = res.first ;
00244          }
00245 
00246          unlock() ;
00247       }
00248    return (*i).second;

template<template< typename T > class STLallocator>
const list< PsName * > & PsNoRefCountingNameServer< STLallocator >::getNamesOfId PsName::idType    const [virtual]
 

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

Implements PsNameServer.

Definition at line 365 of file PsNoRefCountingNameServer.h.

References PsName::idType.

00367 {
00368    static list<PsName *> emptyResult ;
00369    return emptyResult ;

template<template< typename T > class STLallocator>
const PsString & PsNoRefCountingNameServer< STLallocator >::getStringAssociatedTo PsName::idType    id const [virtual]
 

get the string associated to an id

Implements PsNameServer.

Definition at line 256 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_fastStringAccessTable, PsNoRefCountingNameServer< STLallocator >::_nextIdentifier, map< long, typename correspondenceContainerType::iterator, less< long >, STLallocator< pair< const long, typename correspondenceContainerType::iterator > > >::find(), and PsName::idType.

00258 {
00259    assert ( id<_nextIdentifier) ;
00260    //assert ( _fastStringAccessTable.find(id) != _fastStringAccessTable.end() ) ;
00261    return  (*(*_fastStringAccessTable.find(id)).second).first ;

template<template< typename T > class STLallocator>
PsName::idType PsNoRefCountingNameServer< STLallocator >::getSystemIdentifier const PsString   [virtual]
 

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

Implements PsNameServer.

Definition at line 196 of file PsNoRefCountingNameServer.h.

References PsName::_maxReservedId, PsNoRefCountingNameServer< STLallocator >::_nextSystemIdentifier, PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom(), and PsName::idType.

00198 {
00199 
00200    PsName::idType result = getIdentifierAsFrom(name, &_nextSystemIdentifier) ;
00201    // this assertion could fail if a PsName corresponding to a reserved id was staticaly created
00202    assert ( result <= PsName::_maxReservedId ) ;
00203    //this would fail if more reserved Id's are created than originaly planned for
00204    assert ( _nextSystemIdentifier <= PsName::_maxReservedId ) ;
00205 
00206    return result ;

template<template< typename T > class STLallocator>
void PsNoRefCountingNameServer< STLallocator >::lock   const [protected, virtual]
 

lock data in a multithread environment

Implements PsNameServer.

Definition at line 345 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_ourDataLock, and PsnMutexLock::protect().

Referenced by PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom().

00347 {
00348    _ourDataLock.protect() ;

template<template< typename T > class STLallocator>
void PsNoRefCountingNameServer< STLallocator >::operator delete void *    ptr,
size_t    n
 

redefine delete 'cause new was redefined

Definition at line 313 of file PsNoRefCountingNameServer.h.

00315 {
00316    STLallocator<PsNoRefCountingNameServer<STLallocator> > anAllocator;
00317    anAllocator.deallocate((PsNoRefCountingNameServer<STLallocator> *)ptr,n);

template<template< typename T > class STLallocator>
void * PsNoRefCountingNameServer< STLallocator >::operator new size_t   
 

redefine new so that the nameserver is located in the same memory space than it's data structures and their elements

Definition at line 296 of file PsNoRefCountingNameServer.h.

00298 {
00299    STLallocator<PsNoRefCountingNameServer<STLallocator> > anAllocator;
00300    return anAllocator.allocate(size);

template<template< typename T > class STLallocator>
void PsNoRefCountingNameServer< STLallocator >::unlock   const [protected, virtual]
 

unlock data in a multithread environment

Implements PsNameServer.

Definition at line 356 of file PsNoRefCountingNameServer.h.

References PsNoRefCountingNameServer< STLallocator >::_ourDataLock, and PsnMutexLock::unprotect().

Referenced by PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom().

00358 {
00359    _ourDataLock.unprotect() ;


Member Data Documentation

template<template< typename T > class STLallocator>
fastStringAccessTableType PsNoRefCountingNameServer< STLallocator >::_fastStringAccessTable [protected]
 

fast access data structure

Definition at line 121 of file PsNoRefCountingNameServer.h.

Referenced by PsNoRefCountingNameServer< STLallocator >::getIdentifierAsFrom(), PsNoRefCountingNameServer< STLallocator >::getStringAssociatedTo(), and PsNoRefCountingNameServer< STLallocator >::PsNoRefCountingNameServer().

template<template< typename T > class STLallocator>
long PsNoRefCountingNameServer< STLallocator >::_nextIdentifier [protected]
 

nextIdentifier to use

Definition at line 102 of file PsNoRefCountingNameServer.h.

Referenced by PsNoRefCountingNameServer< STLallocator >::getIdentifier(), PsNoRefCountingNameServer< STLallocator >::getStringAssociatedTo(), and PsNoRefCountingNameServer< STLallocator >::PsNoRefCountingNameServer().

template<template< typename T > class STLallocator>
long PsNoRefCountingNameServer< STLallocator >::_nextSystemIdentifier [protected]
 

next System Identifier to use

Definition at line 106 of file PsNoRefCountingNameServer.h.

Referenced by PsNoRefCountingNameServer< STLallocator >::getSystemIdentifier().

template<template< typename T > class STLallocator>
PsnMutexLock PsNoRefCountingNameServer< STLallocator >::_ourDataLock [mutable, protected]
 

the lock for multi-threaded environements

Definition at line 98 of file PsNoRefCountingNameServer.h.

Referenced by PsNoRefCountingNameServer< STLallocator >::lock(), and PsNoRefCountingNameServer< STLallocator >::unlock().

template<template< typename T > class STLallocator>
correspondenceContainerType PsNoRefCountingNameServer< STLallocator >::_stringToIdCorrespondenceContainer [protected]
 

table holding String - id correspondance

Definition at line 124 of file PsNoRefCountingNameServer.h.

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


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

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

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