19#define MYGUI_DECLARE_TYPE_NAME(Type, Override) \
21 static const std::string& getClassTypeName() { static std::string type = #Type; return type; } \
23 virtual const std::string& getTypeName() const Override { return getClassTypeName(); }
25#define MYGUI_RTTI_BASE(BaseType) \
27 typedef BaseType RTTIBase; \
28 MYGUI_DECLARE_TYPE_NAME(BaseType,) \
30 virtual bool isType(const std::type_info& _type) const { return typeid(BaseType) == _type; } \
32 template<typename Type> bool isType() const { return isType(typeid(Type)); } \
36 template<typename Type> Type* castType(bool _throw = true) \
38 if (this->isType<Type>()) return static_cast<Type*>(this); \
39 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' ."); \
45 template<typename Type> const Type* castType(bool _throw = true) const \
47 if (this->isType<Type>()) return static_cast<Type*>(this); \
48 MYGUI_ASSERT(!_throw, "Error cast type '" << this->getTypeName() << "' to type '" << Type::getClassTypeName() << "' ."); \
52#define MYGUI_RTTI_DERIVED(DerivedType) \
54 MYGUI_DECLARE_TYPE_NAME(DerivedType, override) \
55 typedef RTTIBase Base; \
56 typedef DerivedType RTTIBase; \
58 virtual bool isType(const std::type_info& _type) const override { return typeid(DerivedType) == _type || Base::isType(_type); } \
60 template<typename Type> bool isType() const { return isType(typeid(Type)); }