1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: old RTTI macros (use XTI when possible instead)
4 // Author: Julian Smart
5 // Modified by: Ron Lee
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 wxString
;
30 class WXDLLIMPEXP_FWD_BASE wxClassInfo
;
31 class WXDLLIMPEXP_FWD_BASE wxHashTable
;
32 class WXDLLIMPEXP_FWD_BASE wxObject
;
33 class WXDLLIMPEXP_FWD_BASE wxPluginLibrary
;
34 class WXDLLIMPEXP_FWD_BASE wxHashTable_Node
;
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 typedef wxObject
*(*wxObjectConstructorFn
)(void);
42 class WXDLLIMPEXP_BASE wxClassInfo
44 friend class WXDLLIMPEXP_FWD_BASE wxObject
;
45 friend WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxString
& name
);
47 wxClassInfo( const wxChar
*className
,
48 const wxClassInfo
*baseInfo1
,
49 const wxClassInfo
*baseInfo2
,
51 wxObjectConstructorFn ctor
)
52 : m_className(className
)
54 , m_objectConstructor(ctor
)
55 , m_baseInfo1(baseInfo1
)
56 , m_baseInfo2(baseInfo2
)
65 wxObject
*CreateObject() const
66 { return m_objectConstructor
? (*m_objectConstructor
)() : 0; }
67 bool IsDynamic() const { return (NULL
!= m_objectConstructor
); }
69 const wxChar
*GetClassName() const { return m_className
; }
70 const wxChar
*GetBaseClassName1() const
71 { return m_baseInfo1
? m_baseInfo1
->GetClassName() : NULL
; }
72 const wxChar
*GetBaseClassName2() const
73 { return m_baseInfo2
? m_baseInfo2
->GetClassName() : NULL
; }
74 const wxClassInfo
*GetBaseClass1() const { return m_baseInfo1
; }
75 const wxClassInfo
*GetBaseClass2() const { return m_baseInfo2
; }
76 int GetSize() const { return m_objectSize
; }
78 wxObjectConstructorFn
GetConstructor() const
79 { return m_objectConstructor
; }
80 static const wxClassInfo
*GetFirst() { return sm_first
; }
81 const wxClassInfo
*GetNext() const { return m_next
; }
82 static wxClassInfo
*FindClass(const wxString
& className
);
84 // Climb upwards through inheritance hierarchy.
85 // Dual inheritance is catered for.
87 bool IsKindOf(const wxClassInfo
*info
) const
91 ( m_baseInfo1
&& m_baseInfo1
->IsKindOf(info
) ) ||
92 ( m_baseInfo2
&& m_baseInfo2
->IsKindOf(info
) ) );
95 wxDECLARE_CLASS_INFO_ITERATORS();
98 const wxChar
*m_className
;
100 wxObjectConstructorFn m_objectConstructor
;
102 // Pointers to base wxClassInfos
104 const wxClassInfo
*m_baseInfo1
;
105 const wxClassInfo
*m_baseInfo2
;
107 // class info object live in a linked list:
108 // pointers to its head and the next element in it
110 static wxClassInfo
*sm_first
;
113 static wxHashTable
*sm_classTable
;
116 // registers the class
120 wxDECLARE_NO_COPY_CLASS(wxClassInfo
);
123 WXDLLIMPEXP_BASE wxObject
*wxCreateDynamicObject(const wxString
& name
);
125 // ----------------------------------------------------------------------------
126 // Dynamic class macros
127 // ----------------------------------------------------------------------------
129 #define wxDECLARE_ABSTRACT_CLASS(name) \
131 static wxClassInfo ms_classInfo; \
132 virtual wxClassInfo *GetClassInfo() const
134 #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
135 wxDECLARE_NO_ASSIGN_CLASS(name); \
136 wxDECLARE_DYNAMIC_CLASS(name)
138 #define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \
139 wxDECLARE_NO_COPY_CLASS(name); \
140 wxDECLARE_DYNAMIC_CLASS(name)
142 #define wxDECLARE_DYNAMIC_CLASS(name) \
143 wxDECLARE_ABSTRACT_CLASS(name); \
144 static wxObject* wxCreateObject()
146 #define wxDECLARE_CLASS(name) \
147 wxDECLARE_ABSTRACT_CLASS(name)
150 // common part of the macros below
151 #define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
152 wxClassInfo name::ms_classInfo(wxT(#name), \
153 &basename::ms_classInfo, \
155 (int) sizeof(name), \
158 wxClassInfo *name::GetClassInfo() const \
159 { return &name::ms_classInfo; }
161 #define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
162 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
164 #define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
165 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
167 // -----------------------------------
168 // for concrete classes
169 // -----------------------------------
171 // Single inheritance with one base class
172 #define wxIMPLEMENT_DYNAMIC_CLASS(name, basename) \
173 wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
174 wxObject* name::wxCreateObject() \
177 // Multiple inheritance with two base classes
178 #define wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
179 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
180 name::wxCreateObject) \
181 wxObject* name::wxCreateObject() \
184 // -----------------------------------
185 // for abstract classes
186 // -----------------------------------
188 // Single inheritance with one base class
189 #define wxIMPLEMENT_ABSTRACT_CLASS(name, basename) \
190 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
192 // Multiple inheritance with two base classes
193 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
194 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
196 // -----------------------------------
197 // XTI-compatible macros
198 // -----------------------------------
200 #include "wx/flags.h"
202 // these macros only do something when wxUSE_EXTENDED_RTTI=1
203 // (and in that case they are defined by xti.h); however to avoid
204 // to be forced to wrap these macros (in user's source files) with
206 // #if wxUSE_EXTENDED_RTTI
210 // blocks, we define them here as empty.
212 #define wxEMPTY_PARAMETER_VALUE /**/
214 #define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
215 #define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
216 #define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
218 #define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
220 #define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
221 #define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
222 #define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
224 #define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
226 #define wxHANDLER(name,eventClassType) wxEMPTY_PARAMETER_VALUE
227 #define wxBEGIN_HANDLERS_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
228 #define wxEND_HANDLERS_TABLE() wxEMPTY_PARAMETER_VALUE
230 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
231 wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
232 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback ) \
233 wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
235 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
236 wxIMPLEMENT_DYNAMIC_CLASS( name, basename)
238 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
240 fromString ) wxEMPTY_PARAMETER_VALUE
241 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) wxEMPTY_PARAMETER_VALUE
242 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
244 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
246 #define wxCONSTRUCTOR_0(klass) \
247 wxEMPTY_PARAMETER_VALUE
248 #define wxCONSTRUCTOR_DUMMY(klass) \
249 wxEMPTY_PARAMETER_VALUE
250 #define wxDIRECT_CONSTRUCTOR_0(klass) \
251 wxEMPTY_PARAMETER_VALUE
252 #define wxCONSTRUCTOR_1(klass,t0,v0) \
253 wxEMPTY_PARAMETER_VALUE
254 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
255 wxEMPTY_PARAMETER_VALUE
256 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
257 wxEMPTY_PARAMETER_VALUE
258 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
259 wxEMPTY_PARAMETER_VALUE
260 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
261 wxEMPTY_PARAMETER_VALUE
262 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
263 wxEMPTY_PARAMETER_VALUE
264 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
265 wxEMPTY_PARAMETER_VALUE
266 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
267 wxEMPTY_PARAMETER_VALUE
268 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
269 wxEMPTY_PARAMETER_VALUE
270 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
271 wxEMPTY_PARAMETER_VALUE
272 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
273 wxEMPTY_PARAMETER_VALUE
274 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
275 wxEMPTY_PARAMETER_VALUE
276 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
277 wxEMPTY_PARAMETER_VALUE
278 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
279 wxEMPTY_PARAMETER_VALUE
280 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
281 wxEMPTY_PARAMETER_VALUE
282 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
283 wxEMPTY_PARAMETER_VALUE
285 #define wxSETTER( property, Klass, valueType, setterMethod ) wxEMPTY_PARAMETER_VALUE
286 #define wxGETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
287 #define wxADDER( property, Klass, valueType, addermethod ) wxEMPTY_PARAMETER_VALUE
288 #define wxCOLLECTION_GETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
290 #define wxBEGIN_PROPERTIES_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
291 #define wxEND_PROPERTIES_TABLE() wxEMPTY_PARAMETER_VALUE
292 #define wxHIDE_PROPERTY( pname ) wxEMPTY_PARAMETER_VALUE
294 #define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
295 wxEMPTY_PARAMETER_VALUE
297 #define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
298 pflags, help, group) wxEMPTY_PARAMETER_VALUE
300 #define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
301 wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
303 #define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
304 pflags, help, group) wxEMPTY_PARAMETER_VALUE
306 #define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
307 flags, help, group ) wxEMPTY_PARAMETER_VALUE
309 #define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter, \
310 flags, help, group) wxEMPTY_PARAMETER_VALUE
311 #define wxEVENT_PROPERTY( name, eventType, eventClass ) wxEMPTY_PARAMETER_VALUE
313 #define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
315 #define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
317 #define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
319 #endif // !wxUSE_EXTENDED_RTTI
320 #endif // _WX_RTTIH__