nux-0.9.48
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NOBJECTTYPE_H 00024 #define NOBJECTTYPE_H 00025 00026 struct NObjectType 00027 { 00028 const TCHAR *m_Name; 00029 NObjectType *m_Super; 00030 static const NObjectType Null_Type; 00031 00032 NObjectType() 00033 : m_Name (TEXT ("Null_Type") ) 00034 , m_Super (0) 00035 { 00036 } 00037 00038 NObjectType (const TCHAR *Name, NObjectType *Super) 00039 : m_Name (Name) 00040 , m_Super (Super) 00041 { 00042 } 00043 00045 inline bool operator == (const NObjectType &Type) const 00046 { 00047 return IsObjectType (Type); 00048 } 00049 00051 inline bool operator != (const NObjectType &Type) const 00052 { 00053 return !IsObjectType (Type); 00054 } 00055 00057 inline const TCHAR *GetName() const 00058 { 00059 return m_Name; 00060 } 00061 00063 inline bool IsObjectType (const NObjectType &Type) const 00064 { 00065 if (this == &Type) 00066 { 00067 return true; 00068 } 00069 00070 return false; 00071 } 00072 00074 inline bool IsDerivedFromType (const NObjectType &Type) const 00075 { 00076 const NObjectType *current_type = this; 00077 00078 while (current_type) 00079 { 00080 if (current_type == &Type) 00081 return true; 00082 00083 current_type = current_type->m_Super; 00084 } 00085 00086 return false; 00087 } 00088 00089 inline unsigned int SubClassDepth() const 00090 { 00091 const NObjectType *current_type = this; 00092 unsigned int depth = 0; 00093 00094 while (current_type) 00095 { 00096 depth++; 00097 current_type = current_type->m_Super; 00098 } 00099 00100 return depth; 00101 } 00102 }; 00103 00104 #define NUX_DECLARE_OBJECT_TYPE(TypeName, SuperType) \ 00105 public: \ 00106 typedef SuperType SuperObject; \ 00107 static NObjectType StaticObjectType; \ 00108 public: \ 00109 virtual NObjectType& Type() const { return StaticObjectType; } \ 00110 NObjectType& GetTypeInfo() const { return StaticObjectType; } 00111 00112 00113 #define NUX_IMPLEMENT_OBJECT_TYPE(TypeName) \ 00114 NObjectType TypeName::StaticObjectType(TEXT(#TypeName), &TypeName::SuperObject::StaticObjectType); 00115 00116 // #define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName) NUX_DECLARE_OBJECT_TYPE(TypeName, TypeName) 00117 // #define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName) NUX_IMPLEMENT_OBJECT_TYPE(TypeName) 00118 00119 #define NUX_DECLARE_ROOT_OBJECT_TYPE(TypeName) \ 00120 public: \ 00121 typedef NObjectType SuperObject; \ 00122 static NObjectType StaticObjectType; \ 00123 public: \ 00124 virtual NObjectType& Type() const { return StaticObjectType; } \ 00125 NObjectType& GetTypeInfo() const { return StaticObjectType; } 00126 00127 #define NUX_IMPLEMENT_ROOT_OBJECT_TYPE(TypeName) \ 00128 NObjectType TypeName::StaticObjectType(TEXT(#TypeName), 0); 00129 00130 #endif // NOBJECTTYPE_H 00131