Go to the documentation of this file.
23 #ifndef __MYGUI_RTTI_H__
24 #define __MYGUI_RTTI_H__
30 #ifndef MYGUI_RTTI_DISABLE_TYPE_INFO
36 #ifndef MYGUI_RTTI_DISABLE_TYPE_INFO
37 #define MYGUI_RTTI_TYPE const std::type_info&
38 #define MYGUI_RTTI_GET_TYPE(type) typeid(type)
40 #define MYGUI_RTTI_TYPE const std::string&
41 #define MYGUI_RTTI_GET_TYPE(type) type::getClassTypeName()
45 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER <= 1310
46 #define MYGUI_DECLARE_TYPE_NAME(Type) \
48 struct TypeNameHolder { const std::string& getClassTypeName() { static std::string type = #Type; return type; } }; \
50 static const std::string& getClassTypeName() { TypeNameHolder type; return type.getClassTypeName(); } \
52 virtual const std::string& getTypeName() const { return getClassTypeName(); }
54 #define MYGUI_DECLARE_TYPE_NAME(Type) \
56 static const std::string& getClassTypeName() { static std::string type = #Type; return type; } \
58 virtual const std::string& getTypeName() const { return getClassTypeName(); }
61 #define MYGUI_RTTI_BASE(BaseType) \
63 typedef BaseType RTTIBase; \
64 MYGUI_DECLARE_TYPE_NAME(BaseType) \
66 virtual bool isType(MYGUI_RTTI_TYPE _type) const { return MYGUI_RTTI_GET_TYPE(BaseType) == _type; } \
68 template<typename Type> bool isType() const { return isType(MYGUI_RTTI_GET_TYPE(Type)); } \
72 template<typename Type> Type* castType(bool _throw = true) \
74 if (this->isType<Type>()) return static_cast<Type*>(this); \
75 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \
81 template<typename Type> const Type* castType(bool _throw = true) const \
83 if (this->isType<Type>()) return static_cast<Type*>(this); \
84 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \
88 #define MYGUI_RTTI_DERIVED(DerivedType) \
90 MYGUI_DECLARE_TYPE_NAME(DerivedType) \
91 typedef RTTIBase Base; \
92 typedef DerivedType RTTIBase; \
94 virtual bool isType(MYGUI_RTTI_TYPE _type) const { return MYGUI_RTTI_GET_TYPE(DerivedType) == _type || Base::isType(_type); } \
96 template<typename Type> bool isType() const { return isType(MYGUI_RTTI_GET_TYPE(Type)); }
100 #endif // __MYGUI_RTTI_H__