LAMA
|
00001 00034 #ifndef LAMA_LAMAINTERREGISTRY_HPP_ 00035 #define LAMA_LAMAINTERREGISTRY_HPP_ 00036 00037 // for dll_import 00038 #include <lama/config.hpp> 00039 00040 // others 00041 #include <lama/LAMAInterface.hpp> 00042 #include <lama/Context.hpp> 00043 00044 // macros 00045 #include <lama/macros/unique_name.hpp> 00046 00047 #include <map> 00048 00049 namespace lama 00050 { 00051 00052 class LAMA_DLL_IMPORTEXPORT LAMAInterfaceRegistry 00053 { 00054 public: 00055 00056 virtual ~LAMAInterfaceRegistry(); 00057 00058 static LAMAInterfaceRegistry& getRegistry( ); 00059 00060 void addInterface( 00061 const ContextType location, 00062 LAMAInterface* lamaInterface); 00063 00064 const LAMAInterface* getInterface( const ContextType location ) const; 00065 00066 bool hasInterface( const ContextType location ) const; 00067 00068 private: 00069 LAMAInterfaceRegistry(); 00070 LAMAInterfaceRegistry( const LAMAInterfaceRegistry& other ); 00071 00072 LAMAInterfaceRegistry& operator=(const LAMAInterfaceRegistry& other ); 00073 00074 static LAMAInterfaceRegistry* instance; 00075 00076 typedef std::map<ContextType, LAMAInterface*> InterfaceMapType; 00077 00078 InterfaceMapType mInterfaceMap; 00079 00080 class CGuard 00081 { 00082 public: 00083 CGuard( ); 00084 ~CGuard( ); 00085 }; 00086 friend class CGuard; 00087 }; 00088 00089 template<typename T> 00090 class LAMAInterfaceRegistration 00091 { 00092 public: 00093 00094 LAMAInterfaceRegistration( const ContextType location ) 00095 { 00096 LAMAInterfaceRegistry& reg = LAMAInterfaceRegistry::getRegistry(); 00097 reg.addInterface( location, new T() ); 00098 } 00099 }; 00100 00101 #define LAMA_LAMAINTERFACE_REGISTRATION( location, type ) \ 00102 static lama::LAMAInterfaceRegistration<type > \ 00103 LAMA_UNIQUE_NAME( lamaInterfaceRegObj, type )( location ) 00104 } 00105 00106 #endif // LAMA_LAMAINTERREGISTRY_HPP_