]> git.saurik.com Git - wxWidgets.git/blob - include/wx/rtti.h
add methods needed for XTI
[wxWidgets.git] / include / wx / rtti.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/rtti.h
3 // Purpose: old RTTI macros (use XTI when possible instead)
4 // Author: Julian Smart
5 // Modified by: Ron Lee
6 // Created: 01/02/97
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 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _WX_RTTIH__
14 #define _WX_RTTIH__
15
16 #if !wxUSE_EXTENDED_RTTI // XTI system is meant to replace these macros
17
18 // ----------------------------------------------------------------------------
19 // headers
20 // ----------------------------------------------------------------------------
21
22 #include "wx/memory.h"
23
24 // ----------------------------------------------------------------------------
25 // forward declarations
26 // ----------------------------------------------------------------------------
27
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;
34
35 // ----------------------------------------------------------------------------
36 // wxClassInfo
37 // ----------------------------------------------------------------------------
38
39 typedef wxObject *(*wxObjectConstructorFn)(void);
40
41 class WXDLLIMPEXP_BASE wxClassInfo
42 {
43 friend class WXDLLIMPEXP_FWD_BASE wxObject;
44 friend WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
45 public:
46 wxClassInfo( const wxChar *className,
47 const wxClassInfo *baseInfo1,
48 const wxClassInfo *baseInfo2,
49 int size,
50 wxObjectConstructorFn ctor )
51 : m_className(className)
52 , m_objectSize(size)
53 , m_objectConstructor(ctor)
54 , m_baseInfo1(baseInfo1)
55 , m_baseInfo2(baseInfo2)
56 , m_next(sm_first)
57 {
58 sm_first = this;
59 Register();
60 }
61
62 ~wxClassInfo();
63
64 wxObject *CreateObject() const
65 { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
66 bool IsDynamic() const { return (NULL != m_objectConstructor); }
67
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; }
76
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);
82
83 // Climb upwards through inheritance hierarchy.
84 // Dual inheritance is catered for.
85
86 bool IsKindOf(const wxClassInfo *info) const
87 {
88 return info != 0 &&
89 ( info == this ||
90 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
91 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
92 }
93
94 wxDECLARE_CLASS_INFO_ITERATORS()
95
96 private:
97 const wxChar *m_className;
98 int m_objectSize;
99 wxObjectConstructorFn m_objectConstructor;
100
101 // Pointers to base wxClassInfos
102
103 const wxClassInfo *m_baseInfo1;
104 const wxClassInfo *m_baseInfo2;
105
106 // class info object live in a linked list:
107 // pointers to its head and the next element in it
108
109 static wxClassInfo *sm_first;
110 wxClassInfo *m_next;
111
112 static wxHashTable *sm_classTable;
113
114 protected:
115 // registers the class
116 void Register();
117 void Unregister();
118
119 DECLARE_NO_COPY_CLASS(wxClassInfo)
120 };
121
122 WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
123
124 // ----------------------------------------------------------------------------
125 // Dynamic class macros
126 // ----------------------------------------------------------------------------
127
128 #define wxDECLARE_ABSTRACT_CLASS(name) \
129 public: \
130 static wxClassInfo ms_classInfo; \
131 virtual wxClassInfo *GetClassInfo() const
132
133 #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
134 wxDECLARE_NO_ASSIGN_CLASS(name); \
135 wxDECLARE_DYNAMIC_CLASS(name)
136
137 #define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \
138 wxDECLARE_NO_COPY_CLASS(name); \
139 wxDECLARE_DYNAMIC_CLASS(name)
140
141 #define wxDECLARE_DYNAMIC_CLASS(name) \
142 wxDECLARE_ABSTRACT_CLASS(name); \
143 static wxObject* wxCreateObject()
144
145 #define wxDECLARE_CLASS(name) \
146 wxDECLARE_DYNAMIC_CLASS(name)
147
148
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, \
153 baseclsinfo2, \
154 (int) sizeof(name), \
155 func); \
156 \
157 wxClassInfo *name::GetClassInfo() const \
158 { return &name::ms_classInfo; }
159
160 #define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
161 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
162
163 #define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
164 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
165
166 // -----------------------------------
167 // for concrete classes
168 // -----------------------------------
169
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() \
174 { return new name; }
175
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() \
181 { return new name; }
182
183 // -----------------------------------
184 // for abstract classes
185 // -----------------------------------
186
187 // Single inheritance with one base class
188 #define wxIMPLEMENT_ABSTRACT_CLASS(name, basename) \
189 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
190
191 // Multiple inheritance with two base classes
192 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
193 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
194
195 #define wxIMPLEMENT_CLASS(name, basename) \
196 wxIMPLEMENT_ABSTRACT_CLASS(name, basename)
197
198 #define wxIMPLEMENT_CLASS2(name, basename1, basename2) \
199 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
200
201 // -----------------------------------
202 // XTI-compatible macros
203 // -----------------------------------
204
205 #include "wx/flags.h"
206
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
210 //
211 // #if wxUSE_EXTENDED_RTTI
212 // ...
213 // #endif
214 //
215 // blocks, we define them here as empty.
216
217 #define wxEMPTY_PARAMETER_VALUE /**/
218
219 #define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
220 #define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
221 #define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
222
223 #define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
224
225 #define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
226 #define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
227 #define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
228
229 #define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
230
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
234
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
238
239 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
240
241 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
242 unit, toString, \
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
246
247 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
248
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
287
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
292
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
296
297 #define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
298 wxEMPTY_PARAMETER_VALUE
299
300 #define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue, \
301 pflags, help, group) wxEMPTY_PARAMETER_VALUE
302
303 #define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
304 wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
305
306 #define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue, \
307 pflags, help, group) wxEMPTY_PARAMETER_VALUE
308
309 #define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter, \
310 flags, help, group ) wxEMPTY_PARAMETER_VALUE
311
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
315
316 #define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
317
318 #define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
319
320 #define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
321
322 #endif // !wxUSE_EXTENDED_RTTI
323 #endif // _WX_RTTIH__