ML Reference
|
00001 // **InsertLicense** code 00002 //------------------------------------------------------------------------- 00008 00012 //------------------------------------------------------------------------- 00013 #ifndef __mlRuntimeType_H 00014 #define __mlRuntimeType_H 00015 00016 //ML-includes 00017 #ifndef __mlUtilsSystem_H 00018 #include "mlUtilsSystem.h" 00019 #endif 00020 00021 #include "mlAtomicCounter.h" 00022 00023 ML_UTILS_START_NAMESPACE 00024 00025 //------------------------------------------------------------------------- 00030 00048 //------------------------------------------------------------------------- 00049 class RuntimeType { 00050 public: 00053 typedef void* RuntimeTypeCreateCB(); 00054 00055 //---------------------------------------------------------- 00057 00058 //---------------------------------------------------------- 00065 ML_UTILS_EXPORT RuntimeType(const RuntimeType *parent = NULL, 00066 const char *className = NULL, 00067 RuntimeTypeCreateCB *callback = NULL, 00068 const char *dllName = NULL); 00069 00071 ML_UTILS_EXPORT ~RuntimeType(); 00072 00077 ML_UTILS_EXPORT bool isDerivedFrom(const RuntimeType* runtimeType) const; 00078 00080 inline const char* getName() const { return _className ? _className : "BadType"; } 00081 00083 inline const char* getDllName() const { return _dllName ? _dllName : ""; } 00084 00087 inline const RuntimeType* getParent() const { return _parent; } 00088 00090 inline bool canCreateInstance() const { return _callback!=NULL; } 00091 00094 inline void* createInstance() const { return _callback ? (*_callback)() : NULL; } 00095 00097 inline RuntimeTypeCreateCB * getCallback() const { return _callback; } 00098 00100 inline MLint getId() const { return _id; } 00101 00103 00104 private: 00106 char* _className; 00107 00109 char* _dllName; 00110 00112 const RuntimeType* _parent; 00113 00115 MLint _id; 00116 00118 RuntimeTypeCreateCB* _callback; 00119 }; 00120 00121 ML_UTILS_END_NAMESPACE 00122 00123 00124 //----------------------------------------------------------------------------------- 00125 // Stream output for std::ostream 00126 //----------------------------------------------------------------------------------- 00127 namespace std { 00128 00130 inline ostream& operator<<(ostream& s, const ML_UTILS_NAMESPACE::RuntimeType &rt) 00131 { 00132 s << "Class: " 00133 << " Name :" << rt.getName() 00134 << " DllName :" << rt.getDllName() 00135 << " Parent: " << (rt.getParent() ? rt.getParent()->getName() : "NULL") 00136 << " Abstract: " << (rt.getCallback() ? "No" : "Yes") 00137 << std::endl; 00138 return s; 00139 } 00140 00141 } 00142 00143 #endif // __mlRuntimeType_H 00144 00145