00001 #ifndef MERCURYOBJECTFACTORY_H 00002 #define MERCURYOBJECTFACTORY_H 00003 00004 #include "MercuryObject.h" 00005 #include "MercuryUtil.h" 00006 00008 class MercuryObjectFactory 00009 { 00010 public: 00011 static MercuryObjectFactory& GetInstance(); 00012 MercuryObject * GenerateObject( const MString & sClass, const MString & sName ); 00013 bool RegisterObjectClass( const MString & sClassName, MakeObjectCommand pCmd ); 00014 00015 void FinalizeCallbacks(); //Fill out all callback trees 00016 void RegisterFunction( ClassCallback * pCallback, const MString & sClassName, const MString & sCallbackName ); 00017 ClassCallback * GetCallback( const MString & sClassName, const MString & sFunctionName ); 00018 void GetAllClasses( MVector< MString > & vRet ); 00019 void GetAllFunctions( const MString & sClass, MVector< MString > vRet ); 00020 private: 00021 MHash< MakeObjectCommand > m_mClasses; 00022 MHash< MHash< ClassCallback * > > m_mPreCallbacks; 00023 MHash< MHash< ClassCallback * > > m_mFinalCallbacks; 00024 MVector< MercuryObject * > m_vTemplateObjects; 00025 }; 00026 00027 //ensures proper destruction of the factory singleton 00028 //each include of this file increments the counter 00029 static InstanceCounter<MercuryObjectFactory> MOFcounter; 00030 00031 #define REGISTER_OBJECT_TYPE( x ) \ 00032 MercuryObject * CreateClassType##x( const MString & sName ) \ 00033 { \ 00034 x * ret = new x; \ 00035 ret->SetName( sName ); \ 00036 return (MercuryObject*)ret; \ 00037 } \ 00038 \ 00039 bool GlobalClassRegisterSuccess##x = MercuryObjectFactory::GetInstance().RegisterObjectClass( #x, CreateClassType##x ); 00040 00041 #endif