Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef TypInfo_INCLUDE_ONCE
00033 #define TypInfo_INCLUDE_ONCE
00034
00035 #include <vlCore/MurmurHash3.hpp>
00036
00037 namespace vl
00038 {
00044
00046 struct TypeInfo
00047 {
00049 TypeInfo(const char* name): mName(name)
00050 {
00051
00052 const char* ptr = name;
00053 while( *ptr ) ++ptr;
00054 vl::MurmurHash3_x86_32(name, (int)(ptr - name), 0, &mHash);
00055
00056 }
00057
00059 bool operator==(const TypeInfo& other) const { return mHash == other.mHash; }
00060
00062 bool operator<(const TypeInfo& other) const { return mHash < other.mHash; }
00063
00065 const char* name() const { return mName; }
00066
00068 u32 hash() const { return mHash; }
00069
00070 private:
00071
00072 u32 mHash;
00073 const char* mName;
00074 };
00075 }
00076
00077 #define VL_GROUP(...) __VA_ARGS__
00078 #define VL_TO_STR(...) #__VA_ARGS__
00079
00080 #define VL_INSTRUMENT_BASE_CLASS(ClassName) \
00081 public: \
00082 \
00083 \
00084 static const char* Name() { return VL_TO_STR(ClassName); } \
00085 \
00086 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00087 \
00088 \
00089 \
00090 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00091 \
00092 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00093 \
00094 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00095 { \
00096 return type == Type(); \
00097 } \
00098 \
00099 private:
00100
00101 #define VL_INSTRUMENT_ABSTRACT_BASE_CLASS(ClassName) \
00102 public: \
00103 \
00104 \
00105 static const char* Name() { return VL_TO_STR(ClassName); } \
00106 \
00107 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00108 \
00109 \
00110 \
00111 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00112 \
00113 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00114 \
00115 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00116 { \
00117 return type == Type(); \
00118 } \
00119 \
00120 private:
00121
00122 #define VL_INSTRUMENT_CLASS(ClassName, BaseClass) \
00123 private: \
00124 typedef BaseClass super; \
00125 public: \
00126 \
00127 \
00128 static const char* Name() { return VL_TO_STR(ClassName); } \
00129 \
00130 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00131 \
00132 \
00133 \
00134 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00135 \
00136 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00137 \
00138 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00139 { \
00140 return type == Type() || super::isOfType(type); \
00141 } \
00142 \
00143 private:
00144
00145 #define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass) \
00146 private: \
00147 typedef BaseClass super; \
00148 public: \
00149 \
00150 \
00151 static const char* Name() { return VL_TO_STR(ClassName); } \
00152 \
00153 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00154 \
00155 \
00156 \
00157 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00158 \
00159 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00160 \
00161 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00162 { \
00163 return type == Type() || super::isOfType(type); \
00164 } \
00165 \
00166 private:
00167
00168 #define VL_INSTRUMENT_CLASS_2(ClassName, BaseClass1, BaseClass2) \
00169 private: \
00170 typedef BaseClass1 super1; \
00171 typedef BaseClass2 super2; \
00172 public: \
00173 \
00174 \
00175 static const char* Name() { return VL_TO_STR(ClassName); } \
00176 \
00177 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00178 \
00179 \
00180 \
00181 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00182 \
00183 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00184 \
00185 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00186 { \
00187 return type == Type() || super1::isOfType(type) || super2::isOfType(type); \
00188 } \
00189 \
00190 private:
00191
00192 #define VL_INSTRUMENT_ABSTRACT_CLASS_2(ClassName, BaseClass1, BaseClass2) \
00193 private: \
00194 typedef BaseClass1 super1; \
00195 typedef BaseClass2 super2; \
00196 public: \
00197 \
00198 \
00199 static const char* Name() { return VL_TO_STR(ClassName); } \
00200 \
00201 static const ::vl::TypeInfo& Type() { static const ::vl::TypeInfo class_type(VL_TO_STR(ClassName)); return class_type; } \
00202 \
00203 \
00204 \
00205 virtual const char* className() const { return VL_TO_STR(ClassName); } \
00206 \
00207 virtual const ::vl::TypeInfo& classType() const { return Type(); } \
00208 \
00209 virtual bool isOfType(const ::vl::TypeInfo& type) const \
00210 { \
00211 return type == Type() || super1::isOfType(type) || super2::isOfType(type); \
00212 } \
00213 \
00214 private:
00215
00216 namespace vl
00217 {
00218 template<class B, class A>
00219 B* cast(A* obj)
00220 {
00221 if(obj && obj->isOfType(B::Type()))
00222 return static_cast<B*>(obj);
00223 else
00224 return NULL;
00225 }
00226
00227 template<class B, class A>
00228 const B* cast_const(const A* obj)
00229 {
00230 if(obj && obj->isOfType(B::Type()))
00231 return static_cast<const B*>(obj);
00232 else
00233 return NULL;
00234 }
00235 }
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 #endif