Go to the documentation of this file.
24 #ifndef __MYGUI_RTTI_H__
25 #define __MYGUI_RTTI_H__
36 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC && MYGUI_COMP_VER == 1310
37 #define MYGUI_DECLARE_TYPE_NAME( Type ) \
39 struct TypeNameHolder { const std::string& getClassTypeName() { static std::string type = #Type; return type; } }; \
41 static const std::string& getClassTypeName() { TypeNameHolder type; return type.getClassTypeName(); } \
43 virtual const std::string& getTypeName() const { return Type::getClassTypeName(); }
45 #define MYGUI_DECLARE_TYPE_NAME( Type ) \
47 static const std::string& getClassTypeName() { static std::string type = #Type; return type; } \
49 virtual const std::string& getTypeName() const { return Type::getClassTypeName(); }
52 #define MYGUI_RTTI_BASE( BaseType ) \
54 typedef BaseType RTTIBase; \
55 MYGUI_DECLARE_TYPE_NAME( BaseType ) \
57 virtual bool isType( const std::type_info& _type) const { return typeid( BaseType ) == _type; } \
59 template<typename Type> bool isType() const { return isType( typeid( Type )); } \
63 template<typename Type> Type* castType(bool _throw = true) \
65 if (this->isType<Type>()) return static_cast<Type*>( this ); \
66 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \
72 template<typename Type> const Type* castType(bool _throw = true) const \
74 if (this->isType<Type>()) return static_cast<Type*>( this ); \
75 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' .") \
79 #define MYGUI_RTTI_DERIVED( DerivedType ) \
81 MYGUI_DECLARE_TYPE_NAME( DerivedType ) \
82 typedef RTTIBase Base; \
83 typedef DerivedType RTTIBase; \
85 virtual bool isType( const std::type_info& _type ) const { return typeid( DerivedType ) == _type || Base::isType( _type ); } \
87 template<typename Type> bool isType() const { return isType( typeid( DerivedType )); }
90 #define MYGUI_RTTI_CHILD_HEADER( DerivedType, BaseType ) \
92 MYGUI_DECLARE_TYPE_NAME( DerivedType ) \
93 typedef BaseType Base; \
94 typedef DerivedType RTTIBase; \
96 virtual bool isType( const std::type_info& _type ) const { return typeid( DerivedType ) == _type || BaseType::isType( _type ); }
100 #define MYGUI_RTTI_BASE_HEADER( BaseType ) MYGUI_RTTI_BASE( BaseType )
104 #endif // __MYGUI_RTTI_H__