NLAIC::CRegistry Class Reference

#include <registry.h>


Detailed Description

CRegistry is a class factory registry. This class share an std::map objects how it containe reference for ordering class. Class factory is order in the map by name, the name is define by a CIdentType and by index. Index is an index in a vector type. That make easy to manage object reference. Not that name is the word reference of an object and index is the locale reference.

Author:
Chafik sameh

Portier Pierre

Nevrax France

Date:
2000

Definition at line 49 of file registry.h.

Public Member Functions

IBasicInterfacecreateInstance (const sint32)
 Creates a new instance from a class using its registry index.

IBasicInterfacecreateInstance (const char *)
 Creates a new instance from a class using its class name in the registry.

IBasicInterfacecreateInstance (const CIdentType &)
 Creates a new instance from a class using its identifier.

 CRegistry ()
const bool existsClass (const char *) const
const IClassFactorygetFactory (sint32)
 Creates a new instance from a class using its registry index.

const IClassFactorygetFactory (const char *)
 Creates a new instance from a class using its class name in the registry.

const IClassFactorygetFactory (const CIdentType &)
 Creates a new instance from a class using its identifier.

const CIdentTypegetIdent (const char *)
 Returns the identifier of a class from its name.

const CIdentTypegetIdent (const sint32)
 Returns the identifier of a class from its registry index.

const sint32 getNumIdent (const char *)
 Returns the registry index of a class from its name.

const sint32 getNumIdent (const CIdentType &)
 Returns the registry index of a class from its identifier.

const CIdentTypeoperator[] (sint32 i) const
 Get CIdentType with an index.

sint32 registerClass (const CIdentType &, const IClassFactory &)
 Registers a new class.

sint32 size () const
 Get registry size.

void unRegisterClass (const CIdentType &)
 Removes a class from the registry.

 ~CRegistry ()

Private Types

typedef std::map< CIdentType,
CRegistryClass *, std::less<
CIdentType > > 
TMapRegistry

Private Attributes

TMapRegistry_MapRegistry
 Map Hows stored class factory instance.

std::vector< CRegistryClass * > _TableRegistry
 Table for class factory index.


Member Typedef Documentation

typedef std::map<CIdentType ,CRegistryClass *,std::less<CIdentType> > NLAIC::CRegistry::TMapRegistry [private]
 

Definition at line 63 of file registry.h.

Referenced by CRegistry().


Constructor & Destructor Documentation

NLAIC::CRegistry::CRegistry  ) 
 

Definition at line 41 of file registry.cpp.

References _MapRegistry, new, and TMapRegistry.

00041                             : _MapRegistry(*(new TMapRegistry))
00042         {
00043         }

NLAIC::CRegistry::~CRegistry  ) 
 

Definition at line 45 of file registry.cpp.

References _MapRegistry, _TableRegistry, and sint32.

00046         {
00047                 for(sint32 i = 0; i < (sint32) _TableRegistry.size(); i++) 
00048                 {
00049                         if ( _TableRegistry[i] )        
00050                         {
00051                                 delete _TableRegistry[i];
00052                         }
00053                 }
00054                 delete &_MapRegistry;
00055         }


Member Function Documentation

IBasicInterface * NLAIC::CRegistry::createInstance const  sint32  ) 
 

Creates a new instance from a class using its registry index.

Definition at line 161 of file registry.cpp.

References _TableRegistry, and sint32.

00162         {
00163                 IBasicInterface *instance = (IBasicInterface *)_TableRegistry[i]->FactoryClass->createInstance();
00164                 return instance;
00165         }

IBasicInterface * NLAIC::CRegistry::createInstance const char *   ) 
 

Creates a new instance from a class using its class name in the registry.

Definition at line 154 of file registry.cpp.

References _TableRegistry, and getNumIdent().

00155         {
00156                 IBasicInterface *instance = (IBasicInterface *)_TableRegistry[ getNumIdent(class_name) ]->FactoryClass->createInstance();
00157                 return instance;
00158         }

IBasicInterface * NLAIC::CRegistry::createInstance const CIdentType  ) 
 

Creates a new instance from a class using its identifier.

Definition at line 148 of file registry.cpp.

References getNumIdent().

Referenced by NLAIC::CIdentType::allocClass(), and NLAIC::createInstance().

00149         {
00150                 return createInstance(getNumIdent(ident));      
00151         }

const bool NLAIC::CRegistry::existsClass const char *   )  const
 

Definition at line 215 of file registry.cpp.

References _TableRegistry.

Referenced by NLAISCRIPT::CCompilateur::getTypeOfClass().

00216         {
00217                 std::vector<CRegistryClass *>::const_iterator it_rc = _TableRegistry.begin();
00218                 while ( it_rc != _TableRegistry.end() )
00219                 {
00220                         const char *rc_name = (const char *) (*it_rc)->NameClass;
00221                         if ( strcmp( class_name, rc_name ) == 0)
00222                                 return true;
00223                         it_rc++;
00224                 }
00225                 return false;
00226         }

const IClassFactory * NLAIC::CRegistry::getFactory sint32   ) 
 

Creates a new instance from a class using its registry index.

Definition at line 199 of file registry.cpp.

References _TableRegistry, and sint32.

00200         {
00201                 return (*(_TableRegistry.begin() + i))->FactoryClass;//_TableRegistry[i]->FactoryClass;
00202                 //return _TableRegistry[i]->FactoryClass;
00203         }

const IClassFactory * NLAIC::CRegistry::getFactory const char *   ) 
 

Creates a new instance from a class using its class name in the registry.

Definition at line 184 of file registry.cpp.

References id.

00185         {
00186                 try
00187                 {                               
00188                         CIdentType id(class_name);
00189                         return id.getFactory();
00190                 }
00191                 catch (NLAIE::IException &err)
00192                 {
00193                         throw NLAIE::CExceptionContainer(err.what());
00194                 }
00195                 return NULL;
00196         }

const IClassFactory * NLAIC::CRegistry::getFactory const CIdentType  ) 
 

Creates a new instance from a class using its identifier.

Definition at line 168 of file registry.cpp.

References _MapRegistry, NLAIC::stringGetBuild(), and t.

Referenced by NLAIC::CIdentType::getFactory().

00169         {
00170                 CRegistryClass *t;
00171                 TMapRegistry::iterator Itr = _MapRegistry.find(ident);
00172                 if(Itr != _MapRegistry.end()) t = (*Itr).second;
00173                 else 
00174                 {                       
00175                         std::string text;
00176                         text = NLAIC::stringGetBuild("can't find '%s' in the registry",(char *)((const char *)ident));
00177                         NLAIE::CExceptionUnRegisterClassError e(text.c_str());
00178                         throw e;
00179                 }
00180                 return t->FactoryClass;
00181         }

const CIdentType & NLAIC::CRegistry::getIdent const char *   ) 
 

Returns the identifier of a class from its name.

Definition at line 134 of file registry.cpp.

References _TableRegistry, sint32, and NLAIC::stringGetBuild().

00135         {
00136                 for ( sint32 i = 0; i < (sint32) _TableRegistry.size(); i++ )
00137                 {
00138                         if ( !strcmp( (const char *)_TableRegistry[i]->NameClass, class_name ) )
00139                                 return _TableRegistry[ i ]->NameClass;
00140                 }
00141                 std::string text;
00142                 text = NLAIC::stringGetBuild("can't find '%s' in the registry",(char *)class_name);
00143                 NLAIE::CExceptionUnRegisterClassError e(text.c_str());
00144                 throw e;
00145         }

const CIdentType & NLAIC::CRegistry::getIdent const  sint32  ) 
 

Returns the identifier of a class from its registry index.

Definition at line 128 of file registry.cpp.

References _TableRegistry, index, and sint32.

Referenced by NLAIC::CIdentType::serial().

00129         {
00130                 return _TableRegistry[index]->NameClass;
00131         }

const sint32 NLAIC::CRegistry::getNumIdent const char *   ) 
 

Returns the registry index of a class from its name.

Definition at line 112 of file registry.cpp.

References _TableRegistry, sint32, and NLAIC::stringGetBuild().

00113         {
00114                 for ( sint32 i = 0; i < (sint32) _TableRegistry.size(); i++ )
00115                 {
00116                         if ( !strcmp( (const char *)_TableRegistry[i]->NameClass, class_name ) )
00117                                 return i;
00118                 }
00119 
00120                 std::string text;
00121                 text = NLAIC::stringGetBuild("can't find '%s' in the registry",(char *)class_name);
00122                 NLAIE::CExceptionUnRegisterClassError e(text.c_str());
00123                 throw e;
00124                 return -1;
00125         }

const sint32 NLAIC::CRegistry::getNumIdent const CIdentType  ) 
 

Returns the registry index of a class from its identifier.

Definition at line 96 of file registry.cpp.

References _MapRegistry, sint32, NLAIC::stringGetBuild(), and t.

Referenced by createInstance(), NLAIC::CIdentType::serial(), and unRegisterClass().

00097         {
00098                 CRegistryClass *t;
00099                 TMapRegistry::iterator Itr = _MapRegistry.find(ident);
00100                 if(Itr != _MapRegistry.end()) t = (*Itr).second;
00101                 else 
00102                 {
00103                         std::string text;
00104                         text = NLAIC::stringGetBuild("can't find '%s' in the registry",(char *)((const char *)ident));
00105                         NLAIE::CExceptionUnRegisterClassError e(text.c_str());
00106                         throw e;
00107                 }
00108                 return t->Index;                        
00109         }

const CIdentType & NLAIC::CRegistry::operator[] sint32  i  )  const
 

Get CIdentType with an index.

Definition at line 205 of file registry.cpp.

References _TableRegistry, and sint32.

00206         {       
00207                 return _TableRegistry[i]->NameClass;
00208         }

sint32 NLAIC::CRegistry::registerClass const CIdentType ,
const IClassFactory
 

Registers a new class.

Definition at line 57 of file registry.cpp.

References _MapRegistry, _TableRegistry, sint32, and t.

Referenced by NLAIC::registerClass().

00058         {
00059                 // Recherche un emplacement vide
00060                 /*for(sint32 idx = 0; idx < (sint32) _TableRegistry.size(); idx++) 
00061                 {
00062                         if ( _TableRegistry[ idx ] == NULL )
00063                         {
00064                                 CRegistryClass *t = new CRegistryClass( ident, FactoryClass, idx );
00065                                 _TableRegistry[ idx ] = t;
00066                                 _MapRegistry.insert( TMapRegistry::value_type(t->NameClass, t) );
00067                                 return idx;
00068                         }
00069                 }*/
00070 
00071                 // Sinon met à la fin de la table
00072                 CRegistryClass *t = new CRegistryClass(ident, FactoryClass, _TableRegistry.size() );
00073                 _MapRegistry.insert( TMapRegistry::value_type(ident, t) );
00074                 _TableRegistry.push_back( t );          
00075                 return _TableRegistry.size() - 1;
00076         }

sint32 NLAIC::CRegistry::size  )  const
 

Get registry size.

Definition at line 210 of file registry.cpp.

References _TableRegistry, and sint32.

00211         {
00212                 return _TableRegistry.size();
00213         }

void NLAIC::CRegistry::unRegisterClass const CIdentType  ) 
 

Removes a class from the registry.

Definition at line 79 of file registry.cpp.

References _TableRegistry, getNumIdent(), and sint32.

00080         {                       
00081                 sint32 i;
00082                 try
00083                 {
00084                         i = getNumIdent(ident);
00085                 }
00086                 catch(NLAIE::IException &e)
00087                 {                               
00088                         throw NLAIE::CExceptionObjectNotFoundError(e.what());
00089                 }
00090                 delete _TableRegistry[i]->FactoryClass;
00091                 delete _TableRegistry[i];
00092                 _TableRegistry[i] = NULL;
00093         }


Field Documentation

TMapRegistry& NLAIC::CRegistry::_MapRegistry [private]
 

Map Hows stored class factory instance.

Definition at line 68 of file registry.h.

Referenced by CRegistry(), getFactory(), getNumIdent(), registerClass(), and ~CRegistry().

std::vector<CRegistryClass *> NLAIC::CRegistry::_TableRegistry [private]
 

Table for class factory index.

Definition at line 66 of file registry.h.

Referenced by createInstance(), existsClass(), getFactory(), getIdent(), getNumIdent(), operator[](), registerClass(), size(), unRegisterClass(), and ~CRegistry().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 10:22:14 2004 for NeL by doxygen 1.3.6