SimObjectRegistry.h

Go to the documentation of this file.
00001 #ifndef SIMOBJECTREGISTRY_H_
00002 #define SIMOBJECTREGISTRY_H_
00003 
00004 #include "SimEngine.h"
00005 #include "pcsim_hash.h"
00006 #include "PCSIMException.h"
00007 
00008 namespace PCSIM {
00009     class ObjectRegistryException : public PCSIM::Exception {
00010         public:
00011             ObjectRegistryException( string method, string msg ) :  PCSIM::Exception( method, msg ) {}
00012             ;
00013             virtual string name() const {
00014                 return string("PCSIM::ObjectRegistryException");
00015             };
00016     };
00017 }
00018 
00019 #include <typeinfo>
00020 using std::type_info;
00021 
00022 #include <map>
00023 using std::map;
00024 
00025 #include <string>
00026 using std::string;
00027 
00028 #include <limits>
00029 
00031 
00058 class SimObjectRegistry {
00059 
00060     public:
00061         SimObjectRegistry();
00062         virtual ~SimObjectRegistry();
00063 
00064         class FirstIndexOf {
00065             public:
00066                 static object_type_t AdvancePhase1;
00067                 static object_type_t SpikeDriven;
00068                 static object_type_t AdvancePhase2;
00069                 static object_type_t NoAdvance;
00070         };
00071 
00072         object_type_t registerSimObject( SimObject *obj, AdvancePhase::enum_t phase, string const& name= string(""), string const& description = string("") );
00073 
00074         void finalize();
00075         size_t nRegisteredObjectTypes(void);
00076 
00077         SimObject const& getObject( object_type_t tid );
00078         SimObjectFactory const& getSimObjectFactory( string name );
00079         
00080     private:
00081         vector< vector< SimObject* > > reg_per_phase;
00082         vector< SimObject* > reg_orderd;
00083         hash_map< const char*, object_type_t > type_id_map;
00084         hash_map< string, SimObject*, PCSIM::hash<string> > name_factory_map;
00085         vector< SimObjectInformation* > simObjInfo;
00086 };
00087 
00088 inline size_t SimObjectRegistry::nRegisteredObjectTypes(void) {
00089     return reg_orderd.size();
00090 }
00091 
00093 extern SimObjectRegistry *theSimObjectRegistry;
00094 
00096 object_type_t registerSimObject( SimObject *obj, AdvancePhase::enum_t phase, string const& name= string(""), string const& description = string("") );
00097 
00098 
00099 #define REGISTER_SCALAR_FIELD( _class_, _type_, _field_, _desc_ ) \
00100         if( std::numeric_limits<_type_>::is_specialized ) \
00101            _class_::registerField( ScalarField< _type_ >( #_field_, _desc_, ( (char*)(&(_class_::model._field_))-(char*)(&_class_::model) ) ) );
00102 
00103 
00104 #define BEGIN_REGISTER_OBJECT( T, desc, advtype )                                 \
00105         T T::model;                                                               \
00106         SimObjectInformation *T::simObjectInfo = NULL;                            \
00107         object_type_t T::type = 0;                                                \
00108         void T::registerSimObject() {                                             \
00109                 T::type = ::registerSimObject(&T::model, advtype::enumval, #T, desc );\
00110         }                                                                         \
00111         void T::registerFields(void) {                                            \
00112 
00113 
00114 
00115 #define END_REGISTER_OBJECT( T ) }
00116 
00117 #endif /*SIMOBJECTREGISTRY_H_*/

Generated on Wed Jul 9 16:34:38 2008 for PCSIM by  doxygen 1.5.5