1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: old RTTI macros (use XTI when possible instead)
4 // Author: Julian Smart
5 // Modified by: Ron Lee
7 // RCS-ID: $Id: rtti.h 48412 2007-08-27 17:04:02Z FM $
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2001 Ron Lee <ron@debian.org>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 #if !wxUSE_EXTENDED_RTTI // XTI system is meant to replace these macros
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
22 #include "wx/memory.h"
24 // ----------------------------------------------------------------------------
25 // forward declarations
26 // ----------------------------------------------------------------------------
28 class WXDLLIMPEXP_FWD_BASE wxObject
;
29 class WXDLLIMPEXP_FWD_BASE wxClassInfo
;
30 class WXDLLIMPEXP_FWD_BASE wxHashTable
;
31 class WXDLLIMPEXP_FWD_BASE wxObject
;
32 class WXDLLIMPEXP_FWD_BASE wxPluginLibrary
;
33 class WXDLLIMPEXP_FWD_BASE wxHashTable_Node
;
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 typedef wxObject
*(*wxObjectConstructorFn
)(void);
41 class WXDLLIMPEXP_BASE wxClassInfo
43 friend class WXDLLIMPEXP_FWD_BASE wxObject
;
44 friend WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxString
& name
);
46 wxClassInfo( const wxChar
*className
,
47 const wxClassInfo
*baseInfo1
,
48 const wxClassInfo
*baseInfo2
,
50 wxObjectConstructorFn ctor
)
51 : m_className(className
)
53 , m_objectConstructor(ctor
)
54 , m_baseInfo1(baseInfo1
)
55 , m_baseInfo2(baseInfo2
)
64 wxObject
*CreateObject() const
65 { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
66 bool IsDynamic() const { return (NULL
!= m_objectConstructor
); }
68 const wxChar
*GetClassName() const { return m_className
; }
69 const wxChar
*GetBaseClassName1() const
70 { return m_baseInfo1
? m_baseInfo1
->GetClassName() : NULL
; }
71 const wxChar
*GetBaseClassName2() const
72 { return m_baseInfo2
? m_baseInfo2
->GetClassName() : NULL
; }
73 const wxClassInfo
*GetBaseClass1() const { return m_baseInfo1
; }
74 const wxClassInfo
*GetBaseClass2() const { return m_baseInfo2
; }
75 int GetSize() const { return m_objectSize
; }
77 wxObjectConstructorFn
GetConstructor() const
78 { return m_objectConstructor
; }
79 static const wxClassInfo
*GetFirst() { return sm_first
; }
80 const wxClassInfo
*GetNext() const { return m_next
; }
81 static wxClassInfo
*FindClass(const wxString
& className
);
83 // Climb upwards through inheritance hierarchy.
84 // Dual inheritance is catered for.
86 bool IsKindOf(const wxClassInfo
*info
) const
90 ( m_baseInfo1
&& m_baseInfo1
->IsKindOf(info
) ) ||
91 ( m_baseInfo2
&& m_baseInfo2
->IsKindOf(info
) ) );
94 wxDECLARE_CLASS_INFO_ITERATORS()
97 const wxChar
*m_className
;
99 wxObjectConstructorFn m_objectConstructor
;
101 // Pointers to base wxClassInfos
103 const wxClassInfo
*m_baseInfo1
;
104 const wxClassInfo
*m_baseInfo2
;
106 // class info object live in a linked list:
107 // pointers to its head and the next element in it
109 static wxClassInfo
*sm_first
;
112 static wxHashTable
*sm_classTable
;
115 // registers the class
119 DECLARE_NO_COPY_CLASS(wxClassInfo
)
122 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxChar
*name
);
124 // ----------------------------------------------------------------------------
125 // Dynamic class macros
126 // ----------------------------------------------------------------------------
128 #define wxDECLARE_ABSTRACT_CLASS(name) \
130 static wxClassInfo ms_classInfo; \
131 virtual wxClassInfo *GetClassInfo() const
133 #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
134 wxDECLARE_NO_ASSIGN_CLASS(name); \
135 wxDECLARE_DYNAMIC_CLASS(name)
137 #define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \
138 wxDECLARE_NO_COPY_CLASS(name); \
139 wxDECLARE_DYNAMIC_CLASS(name)
141 #define wxDECLARE_DYNAMIC_CLASS(name) \
142 wxDECLARE_ABSTRACT_CLASS(name); \
143 static wxObject* wxCreateObject()
145 #define wxDECLARE_CLASS(name) \
146 wxDECLARE_DYNAMIC_CLASS(name)
149 // common part of the macros below
150 #define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
151 wxClassInfo name::ms_classInfo(wxT(#name), \
152 &basename::ms_classInfo, \
154 (int) sizeof(name), \
157 wxClassInfo *name::GetClassInfo() const \
158 { return &name::ms_classInfo; }
160 #define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
161 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
163 #define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
164 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
166 // -----------------------------------
167 // for concrete classes
168 // -----------------------------------
170 // Single inheritance with one base class
171 #define wxIMPLEMENT_DYNAMIC_CLASS(name, basename) \
172 wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
173 wxObject* name::wxCreateObject() \
176 // Multiple inheritance with two base classes
177 #define wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
178 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
179 name::wxCreateObject) \
180 wxObject* name::wxCreateObject() \
183 // -----------------------------------
184 // for abstract classes
185 // -----------------------------------
187 // Single inheritance with one base class
188 #define wxIMPLEMENT_ABSTRACT_CLASS(name, basename) \
189 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
191 // Multiple inheritance with two base classes
192 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
193 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
195 #define wxIMPLEMENT_CLASS(name, basename) \
196 wxIMPLEMENT_ABSTRACT_CLASS(name, basename)
198 #define wxIMPLEMENT_CLASS2(name, basename1, basename2) \
199 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
201 // -----------------------------------
202 // XTI-compatible macros
203 // -----------------------------------
205 #include "wx/flags.h"
207 // these macros only do something when wxUSE_EXTENDED_RTTI=1
208 // (and in that case they are defined by xti.h); however to avoid
209 // to be forced to wrap these macros (in user's source files) with
211 // #if wxUSE_EXTENDED_RTTI
215 // blocks, we define them here as empty.
217 #define wxEMPTY_PARAMETER_VALUE /**/
219 #define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
220 #define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
221 #define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
223 #define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
225 #define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
226 #define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
227 #define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
229 #define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
231 #define wxHANDLER(name,eventClassType) wxEMPTY_PARAMETER_VALUE
232 #define wxBEGIN_HANDLERS_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
233 #define wxEND_HANDLERS_TABLE() wxEMPTY_PARAMETER_VALUE
235 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
236 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback ) \
237 wxEMPTY_PARAMETER_VALUE
239 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
241 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
243 fromString ) wxEMPTY_PARAMETER_VALUE
244 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) wxEMPTY_PARAMETER_VALUE
245 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
247 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
249 #define wxCONSTRUCTOR_0(klass) \
250 wxEMPTY_PARAMETER_VALUE
251 #define wxCONSTRUCTOR_DUMMY(klass) \
252 wxEMPTY_PARAMETER_VALUE
253 #define wxDIRECT_CONSTRUCTOR_0(klass) \
254 wxEMPTY_PARAMETER_VALUE
255 #define wxCONSTRUCTOR_1(klass,t0,v0) \
256 wxEMPTY_PARAMETER_VALUE
257 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
258 wxEMPTY_PARAMETER_VALUE
259 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
260 wxEMPTY_PARAMETER_VALUE
261 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
262 wxEMPTY_PARAMETER_VALUE
263 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
264 wxEMPTY_PARAMETER_VALUE
265 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
266 wxEMPTY_PARAMETER_VALUE
267 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
268 wxEMPTY_PARAMETER_VALUE
269 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
270 wxEMPTY_PARAMETER_VALUE
271 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
272 wxEMPTY_PARAMETER_VALUE
273 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
274 wxEMPTY_PARAMETER_VALUE
275 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
276 wxEMPTY_PARAMETER_VALUE
277 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
278 wxEMPTY_PARAMETER_VALUE
279 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
280 wxEMPTY_PARAMETER_VALUE
281 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
282 wxEMPTY_PARAMETER_VALUE
283 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
284 wxEMPTY_PARAMETER_VALUE
285 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
286 wxEMPTY_PARAMETER_VALUE
288 #define wxSETTER( property, Klass, valueType, setterMethod ) wxEMPTY_PARAMETER_VALUE
289 #define wxGETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
290 #define wxADDER( property, Klass, valueType, addermethod ) wxEMPTY_PARAMETER_VALUE
291 #define wxCOLLECTION_GETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
293 #define wxBEGIN_PROPERTIES_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
294 #define wxEND_PROPERTIES_TABLE() wxEMPTY_PARAMETER_VALUE
295 #define wxHIDE_PROPERTY( pname ) wxEMPTY_PARAMETER_VALUE
297 #define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
298 wxEMPTY_PARAMETER_VALUE
300 #define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
301 pflags, help, group) wxEMPTY_PARAMETER_VALUE
303 #define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
304 wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
306 #define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
307 pflags, help, group) wxEMPTY_PARAMETER_VALUE
309 #define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
310 flags, help, group ) wxEMPTY_PARAMETER_VALUE
312 #define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
313 flags, help, group) wxEMPTY_PARAMETER_VALUE
314 #define wxEVENT_PROPERTY( name, eventType, eventClass ) wxEMPTY_PARAMETER_VALUE
316 #define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
318 #define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
320 #define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
322 #endif // !wxUSE_EXTENDED_RTTI
323 #endif // _WX_RTTIH__