1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: old RTTI macros (use XTI when possible instead)
4 // Author: Julian Smart
5 // Modified by: Ron Lee
7 // Copyright: (c) 1997 Julian Smart
8 // (c) 2001 Ron Lee <ron@debian.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if !wxUSE_EXTENDED_RTTI // XTI system is meant to replace these macros
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 #include "wx/memory.h"
23 // ----------------------------------------------------------------------------
24 // forward declarations
25 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_FWD_BASE wxObject
;
28 class WXDLLIMPEXP_FWD_BASE wxString
;
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 wxDECLARE_NO_COPY_CLASS(wxClassInfo
);
122 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxString
& 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_ABSTRACT_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 // -----------------------------------
196 // XTI-compatible macros
197 // -----------------------------------
199 #include "wx/flags.h"
201 // these macros only do something when wxUSE_EXTENDED_RTTI=1
202 // (and in that case they are defined by xti.h); however to avoid
203 // to be forced to wrap these macros (in user's source files) with
205 // #if wxUSE_EXTENDED_RTTI
209 // blocks, we define them here as empty.
211 #define wxEMPTY_PARAMETER_VALUE /**/
213 #define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
214 #define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
215 #define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
217 #define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
219 #define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
220 #define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
221 #define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
223 #define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
225 #define wxHANDLER(name,eventClassType) wxEMPTY_PARAMETER_VALUE
226 #define wxBEGIN_HANDLERS_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
227 #define wxEND_HANDLERS_TABLE() wxEMPTY_PARAMETER_VALUE
229 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
230 wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
231 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback ) \
232 wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
234 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
235 wxIMPLEMENT_DYNAMIC_CLASS( name, basename)
237 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
239 fromString ) wxEMPTY_PARAMETER_VALUE
240 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) wxEMPTY_PARAMETER_VALUE
241 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
243 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
245 #define wxCONSTRUCTOR_0(klass) \
246 wxEMPTY_PARAMETER_VALUE
247 #define wxCONSTRUCTOR_DUMMY(klass) \
248 wxEMPTY_PARAMETER_VALUE
249 #define wxDIRECT_CONSTRUCTOR_0(klass) \
250 wxEMPTY_PARAMETER_VALUE
251 #define wxCONSTRUCTOR_1(klass,t0,v0) \
252 wxEMPTY_PARAMETER_VALUE
253 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
254 wxEMPTY_PARAMETER_VALUE
255 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
256 wxEMPTY_PARAMETER_VALUE
257 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
258 wxEMPTY_PARAMETER_VALUE
259 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
260 wxEMPTY_PARAMETER_VALUE
261 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
262 wxEMPTY_PARAMETER_VALUE
263 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
264 wxEMPTY_PARAMETER_VALUE
265 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
266 wxEMPTY_PARAMETER_VALUE
267 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
268 wxEMPTY_PARAMETER_VALUE
269 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
270 wxEMPTY_PARAMETER_VALUE
271 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
272 wxEMPTY_PARAMETER_VALUE
273 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
274 wxEMPTY_PARAMETER_VALUE
275 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
276 wxEMPTY_PARAMETER_VALUE
277 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
278 wxEMPTY_PARAMETER_VALUE
279 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
280 wxEMPTY_PARAMETER_VALUE
281 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
282 wxEMPTY_PARAMETER_VALUE
284 #define wxSETTER( property, Klass, valueType, setterMethod ) wxEMPTY_PARAMETER_VALUE
285 #define wxGETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
286 #define wxADDER( property, Klass, valueType, addermethod ) wxEMPTY_PARAMETER_VALUE
287 #define wxCOLLECTION_GETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
289 #define wxBEGIN_PROPERTIES_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
290 #define wxEND_PROPERTIES_TABLE() wxEMPTY_PARAMETER_VALUE
291 #define wxHIDE_PROPERTY( pname ) wxEMPTY_PARAMETER_VALUE
293 #define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
294 wxEMPTY_PARAMETER_VALUE
296 #define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
297 pflags, help, group) wxEMPTY_PARAMETER_VALUE
299 #define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
300 wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
302 #define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
303 pflags, help, group) wxEMPTY_PARAMETER_VALUE
305 #define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
306 flags, help, group ) wxEMPTY_PARAMETER_VALUE
308 #define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
309 flags, help, group) wxEMPTY_PARAMETER_VALUE
310 #define wxEVENT_PROPERTY( name, eventType, eventClass ) wxEMPTY_PARAMETER_VALUE
312 #define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
314 #define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
316 #define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
318 #endif // !wxUSE_EXTENDED_RTTI
319 #endif // _WX_RTTIH__