NLMISC::CClassRegistry Class Reference

#include <class_registry.h>


Detailed Description

The Class registry where we can instanciate IClassable objects from their names.
Author:
Lionel Berenguier

Nevrax France

Date:
2000

Definition at line 88 of file class_registry.h.

Static Public Member Functions

bool checkObject (IClassable *obj)
 check if the object has been correctly registered. Must be used for debug only, and Must compile with RTTI.

IClassablecreate (const std::string &className) throw (ERegistry)
 Create an object from his class name.

void registerClass (const std::string &className, IClassable *(*creator)(), const std::string &typeidCheck) throw (ERegistry)
 Register your class for future Instanciation.


Private Types

typedef std::hash_map< std::string,
CClassNode
TClassMap

Static Private Member Functions

void init ()
 Inits the ClassRegistry (especially RegistredClasses).


Static Private Attributes

TClassMapRegistredClasses = NULL


Member Typedef Documentation

typedef std::hash_map<std::string, CClassNode> NLMISC::CClassRegistry::TClassMap [private]
 

Definition at line 108 of file class_registry.h.

Referenced by init().


Member Function Documentation

bool NLMISC::CClassRegistry::checkObject IClassable obj  )  [static]
 

check if the object has been correctly registered. Must be used for debug only, and Must compile with RTTI.

Definition at line 91 of file class_registry.cpp.

References NLMISC::IClassable::getClassName(), init(), and RegistredClasses.

00092 {
00093         init();
00094 
00095         TClassMap::iterator     it;     
00096         it=RegistredClasses->find(obj->getClassName());
00097         if(it==RegistredClasses->end())
00098                 return false;   
00099 
00100         if( it->second.TypeIdCheck != string(typeid(*obj).name()) )
00101                 return false;
00102 
00103         return true;
00104 }

IClassable * NLMISC::CClassRegistry::create const std::string &  className  )  throw (ERegistry) [static]
 

Create an object from his class name.

Definition at line 51 of file class_registry.cpp.

References nlassert.

00052 {
00053         init();
00054 
00055         TClassMap::iterator     it;     
00056         
00057         it=RegistredClasses->find(className);
00058 
00059         if(it==RegistredClasses->end())
00060                 return NULL;
00061         else
00062         {
00063                 IClassable      *ptr;
00064                 ptr=it->second.Creator();
00065                 #ifdef NL_DEBUG
00066                         nlassert(CClassRegistry::checkObject(ptr));
00067                 #endif
00068                 return ptr;
00069         }
00070 
00071 }

void NLMISC::CClassRegistry::init  )  [static, private]
 

Inits the ClassRegistry (especially RegistredClasses).

Definition at line 43 of file class_registry.cpp.

References RegistredClasses, and TClassMap.

Referenced by checkObject().

00044 {
00045         if (RegistredClasses == NULL)
00046                 RegistredClasses = new TClassMap;
00047 }

void NLMISC::CClassRegistry::registerClass const std::string &  className,
IClassable *(*  creator)(),
const std::string &  typeidCheck
throw (ERegistry) [static]
 

Register your class for future Instanciation.

Definition at line 74 of file class_registry.cpp.

References NLMISC::CClassRegistry::CClassNode::Creator, nlstop, and NLMISC::CClassRegistry::CClassNode::TypeIdCheck.

00075 {
00076         init();
00077 
00078         CClassNode      node;   
00079         node.Creator=creator;
00080         node.TypeIdCheck= typeidCheck;
00081         std::pair<TClassMap::iterator, bool> result;
00082         result = RegistredClasses->insert(TClassMap::value_type(className, node));
00083         if(!result.second)
00084         {
00085                 nlstop;
00086                 throw ERegisteredClass();
00087         }       
00088 }


Field Documentation

CClassRegistry::TClassMap * NLMISC::CClassRegistry::RegistredClasses = NULL [static, private]
 

Definition at line 39 of file class_registry.cpp.

Referenced by checkObject(), and init().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:06:15 2004 for NeL by doxygen 1.3.6