23
23
#ifndef NOBJECTTYPE_H
24
24
#define NOBJECTTYPE_H
30
// TODO: write a nice is_instance (and is_derived_instance)
32
//template <typename T, typename I>
33
//bool is_instance(T const&
30
40
static const NObjectType Null_Type;
33
: m_Name (TEXT ("Null_Type") )
38
NObjectType (const TCHAR *Name, NObjectType *Super)
48
NObjectType(const char* type_name, NObjectType* super_type)
53
63
return !IsObjectType (Type);
56
//! Return the name of the type.
57
inline const TCHAR *GetName() const
62
66
//! Return true is this has the same type as the argument type.
63
67
inline bool IsObjectType (const NObjectType &Type) const
73
72
//! Return true if this has the same type as the argument type or is derived from it.
89
88
inline unsigned int SubClassDepth() const
91
const NObjectType *current_type = this;
90
const NObjectType* current_type = this;
92
91
unsigned int depth = 0;
94
93
while (current_type)
97
current_type = current_type->m_Super;
96
current_type = current_type->super;
104
103
#define NUX_DECLARE_OBJECT_TYPE(TypeName, SuperType) \
106
105
typedef SuperType SuperObject; \
107
static NObjectType StaticObjectType; \
106
static ::nux::NObjectType StaticObjectType; \
109
virtual NObjectType& Type() const { return StaticObjectType; } \
110
NObjectType& GetTypeInfo() const { return StaticObjectType; }
108
virtual ::nux::NObjectType& Type() const { return StaticObjectType; } \
109
::nux::NObjectType& GetTypeInfo() const { return StaticObjectType; }
113
112
#define NUX_IMPLEMENT_OBJECT_TYPE(TypeName) \
114
NObjectType TypeName::StaticObjectType(TEXT(#TypeName), &TypeName::SuperObject::StaticObjectType);
116
// #define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName) NUX_DECLARE_OBJECT_TYPE(TypeName, TypeName)
117
// #define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName) NUX_IMPLEMENT_OBJECT_TYPE(TypeName)
113
::nux::NObjectType TypeName::StaticObjectType(#TypeName, &TypeName::SuperObject::StaticObjectType);
119
115
#define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName) \
121
typedef NObjectType SuperObject; \
122
static NObjectType StaticObjectType; \
117
typedef ::nux::NObjectType SuperObject; \
118
static ::nux::NObjectType StaticObjectType; \
124
virtual NObjectType& Type() const { return StaticObjectType; } \
125
NObjectType& GetTypeInfo() const { return StaticObjectType; }
120
virtual ::nux::NObjectType& Type() const { return StaticObjectType; } \
121
::nux::NObjectType& GetTypeInfo() const { return StaticObjectType; }
127
123
#define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName) \
128
NObjectType TypeName::StaticObjectType(TEXT(#TypeName), 0);
124
::nux::NObjectType TypeName::StaticObjectType(#TypeName, 0);
130
128
#endif // NOBJECTTYPE_H