Go to the documentation of this file. 18 #define MYGUI_RTTI_TYPE const std::type_info& 19 #define MYGUI_RTTI_GET_TYPE(type) typeid(type) 22 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER <= 1310 23 # define MYGUI_DECLARE_TYPE_NAME(Type) \ 25 struct TypeNameHolder { const std::string& getClassTypeName() { static std::string type = #Type; return type; } }; \ 27 static const std::string& getClassTypeName() { TypeNameHolder type; return type.getClassTypeName(); } \ 29 virtual const std::string& getTypeName() const { return getClassTypeName(); } 31 # define MYGUI_DECLARE_TYPE_NAME(Type) \ 33 static const std::string& getClassTypeName() { static std::string type = #Type; return type; } \ 35 virtual const std::string& getTypeName() const { return getClassTypeName(); } 38 #define MYGUI_RTTI_BASE(BaseType) \ 40 typedef BaseType RTTIBase; \ 41 MYGUI_DECLARE_TYPE_NAME(BaseType) \ 43 virtual bool isType(MYGUI_RTTI_TYPE _type) const { return MYGUI_RTTI_GET_TYPE(BaseType) == _type; } \ 45 template<typename Type> bool isType() const { return isType(MYGUI_RTTI_GET_TYPE(Type)); } \ 49 template<typename Type> Type* castType(bool _throw = true) \ 51 if (this->isType<Type>()) return static_cast<Type*>(this); \ 52 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \ 58 template<typename Type> const Type* castType(bool _throw = true) const \ 60 if (this->isType<Type>()) return static_cast<Type*>(this); \ 61 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \ 65 #define MYGUI_RTTI_DERIVED(DerivedType) \ 67 MYGUI_DECLARE_TYPE_NAME(DerivedType) \ 68 typedef RTTIBase Base; \ 69 typedef DerivedType RTTIBase; \ 71 virtual bool isType(MYGUI_RTTI_TYPE _type) const { return MYGUI_RTTI_GET_TYPE(DerivedType) == _type || Base::isType(_type); } \ 73 template<typename Type> bool isType() const { return isType(MYGUI_RTTI_GET_TYPE(Type)); } 77 #endif // MYGUI_RTTI_H_