00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GZ_TYPE_H__
00022 #define __GZ_TYPE_H__
00023
00059 #include "gzBasicTypes.h"
00060
00061 const gzULong GZ_TYPE_MAX_NAME_LEN=100;
00062
00063 #define GZ_DECLARE_TYPE_INTERFACE_EXPORT(exporter) exporter static gzType s_type;\
00064 exporter static gzType *getClassType() { return &s_type; }\
00065 exporter virtual gzType *getType() const { return getClassType(); }
00066
00067 #define GZ_DECLARE_TYPE_INTERFACE static gzType s_type;\
00068 static gzType *getClassType() { return &s_type; }\
00069 virtual gzType *getType() const { return getClassType(); }
00070
00071 #define GZ_DECLARE_TYPE_BASE(base,name) gzType base::s_type(0,name)
00072
00073 #define GZ_DECLARE_TYPE_CHILD(parent,child,name) gzType child::s_type(&parent::s_type,name)
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 class GZ_BASE_EXPORT gzType
00091 {
00092 public:
00093 gzType(gzType *parent, const char *name );
00094 gzType(const gzType &right );
00095 gzType &operator=(const gzType &right );
00096 virtual ~gzType();
00097
00098 const char *getName() const;
00099
00100 gzType *getParent() const;
00101
00102 gzBool isDerivedFrom(gzType *ancestor) const;
00103
00104 gzULong hash() const;
00105
00106 inline gzBool operator==(const gzType &type)
00107 {
00108 return (m_name==type.m_name);
00109 }
00110
00111
00112 private:
00113
00114 gzType *m_parent;
00115 char *m_name;
00116 gzBool m_created;
00117
00118 };
00119
00121 typedef gzType * gzTypePtr;
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 class GZ_BASE_EXPORT gzTypeInterface
00139 {
00140 public:
00141
00142 gzTypeInterface(){};
00143
00144 virtual ~gzTypeInterface(){};
00145
00146 inline gzBool isExactType( gzType *type ) const
00147 {
00148 if(getType()==type)
00149 return TRUE;
00150 else
00151 return FALSE;
00152 }
00153
00154 gzBool isOfType(gzType *type ) const;
00155
00156 virtual gzType *getType() const = 0;
00157
00158 const char *getTypeName() const;
00159 };
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 template<class T> T * gzDynamic_Cast(gzTypeInterface* pObject)
00176 {
00177 if (pObject == NULL)
00178 return NULL;
00179
00180 if ( pObject->isOfType( T::getClassType() ) )
00181 return (T *)pObject;
00182
00183 return NULL;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 template<class T1 , class T2> T2 * gzDynamic_Instance_Cast(gzTypeInterface* pObject)
00201 {
00202 if (pObject == NULL)
00203 return NULL;
00204
00205 if ( pObject->isOfType( T1::getClassType() ) )
00206 return (T2 *)(*(T1 *)pObject);
00207
00208 return NULL;
00209 }
00210
00211
00212 #endif