1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XTI constructors
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
18 #if wxUSE_EXTENDED_RTTI
20 #include "wx/string.h"
21 #include "wx/variant.h"
23 class WXDLLIMPEXP_BASE wxObject
;
24 class WXDLLIMPEXP_BASE wxClassInfo
;
25 class WXDLLIMPEXP_BASE wxDynamicClassInfo
;
26 class WXDLLIMPEXP_BASE wxHashTable
;
27 class WXDLLIMPEXP_BASE wxHashTable_Node
;
28 class WXDLLIMPEXP_BASE wxObjectRefData
;
29 class WXDLLIMPEXP_BASE wxEvent
;
30 class WXDLLIMPEXP_BASE wxEvtHandler
;
32 // ----------------------------------------------------------------------------
33 // Constructor Bridges
34 // ----------------------------------------------------------------------------
36 // A constructor bridge allows to call a ctor with an arbitrary number
37 // or parameters during runtime
38 class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
41 virtual ~wxObjectAllocatorAndCreator() { }
42 virtual bool Create(wxObject
* &o
, wxVariantBase
*args
) = 0;
45 // a direct constructor bridge calls the operator new for this class and
46 // passes all params to the constructor. Needed for classes that cannot be
47 // instantiated using alloc-create semantics
48 class WXDLLIMPEXP_BASE wxObjectAllocator
: public wxObjectAllocatorAndCreator
51 virtual bool Create(wxObject
* &o
, wxVariantBase
*args
) = 0;
55 // ----------------------------------------------------------------------------
56 // Constructor Bridges for all Numbers of Params
57 // ----------------------------------------------------------------------------
61 template<typename Class
>
62 struct wxObjectAllocatorAndCreator_0
: public wxObjectAllocatorAndCreator
64 bool Create(wxObject
* &o
, wxVariantBase
*)
66 Class
*obj
= wx_dynamic_cast(Class
*, o
);
71 struct wxObjectAllocatorAndCreator_Dummy
: public wxObjectAllocatorAndCreator
73 bool Create(wxObject
*&, wxVariantBase
*)
79 #define wxCONSTRUCTOR_0(klass) \
80 wxObjectAllocatorAndCreator_0<klass> constructor##klass; \
81 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
82 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
83 const int klass::ms_constructorPropertiesCount = 0;
85 #define wxCONSTRUCTOR_DUMMY(klass) \
86 wxObjectAllocatorAndCreator_Dummy constructor##klass; \
87 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
88 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
89 const int klass::ms_constructorPropertiesCount = 0;
91 // direct constructor version
93 template<typename Class
>
94 struct wxDirectConstructorBridge_0
: public wxObjectAllocator
96 bool Create(wxObject
* &o
, wxVariantBase
*args
)
103 #define wxDIRECT_CONSTRUCTOR_0(klass) \
104 wxDirectConstructorBridge_0<klass> constructor##klass; \
105 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
106 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
107 const int klass::ms_constructorPropertiesCount = 0;
112 template<typename Class
, typename T0
>
113 struct wxObjectAllocatorAndCreator_1
: public wxObjectAllocatorAndCreator
115 bool Create(wxObject
* &o
, wxVariantBase
*args
)
117 Class
*obj
= wx_dynamic_cast(Class
*, o
);
119 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
)
124 #define wxCONSTRUCTOR_1(klass,t0,v0) \
125 wxObjectAllocatorAndCreator_1<klass,t0> constructor##klass; \
126 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
127 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
128 const int klass::ms_constructorPropertiesCount = 1;
130 // direct constructor version
132 template<typename Class
, typename T0
>
133 struct wxDirectConstructorBridge_1
: public wxObjectAllocator
135 bool Create(wxObject
* &o
, wxVariantBase
*args
)
138 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
)
144 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
145 wxDirectConstructorBridge_1<klass,t0,t1> constructor##klass; \
146 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
147 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
148 const int klass::ms_constructorPropertiesCount = 1;
153 template<typename Class
,
154 typename T0
, typename T1
>
155 struct wxObjectAllocatorAndCreator_2
: public wxObjectAllocatorAndCreator
157 bool Create(wxObject
* &o
, wxVariantBase
*args
)
159 Class
*obj
= wx_dynamic_cast(Class
*, o
);
161 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
162 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
167 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
168 wxObjectAllocatorAndCreator_2<klass,t0,t1> constructor##klass; \
169 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
170 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
171 const int klass::ms_constructorPropertiesCount = 2;
173 // direct constructor version
175 template<typename Class
,
176 typename T0
, typename T1
>
177 struct wxDirectConstructorBridge_2
: public wxObjectAllocator
179 bool Create(wxObject
* &o
, wxVariantBase
*args
)
182 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
183 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
)
189 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
190 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass; \
191 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
192 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
193 const int klass::ms_constructorPropertiesCount = 2;
198 template<typename Class
,
199 typename T0
, typename T1
, typename T2
>
200 struct wxObjectAllocatorAndCreator_3
: public wxObjectAllocatorAndCreator
202 bool Create(wxObject
* &o
, wxVariantBase
*args
)
204 Class
*obj
= wx_dynamic_cast(Class
*, o
);
206 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
207 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
208 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
213 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
214 wxObjectAllocatorAndCreator_3<klass,t0,t1,t2> constructor##klass; \
215 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
216 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
217 const int klass::ms_constructorPropertiesCount = 3;
219 // direct constructor version
221 template<typename Class
,
222 typename T0
, typename T1
, typename T2
>
223 struct wxDirectConstructorBridge_3
: public wxObjectAllocator
225 bool Create(wxObject
* &o
, wxVariantBase
*args
)
228 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
229 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
230 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
)
236 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
237 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass; \
238 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
239 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
240 const int klass::ms_constructorPropertiesCount = 3;
245 template<typename Class
,
246 typename T0
, typename T1
, typename T2
, typename T3
>
247 struct wxObjectAllocatorAndCreator_4
: public wxObjectAllocatorAndCreator
249 bool Create(wxObject
* &o
, wxVariantBase
*args
)
251 Class
*obj
= wx_dynamic_cast(Class
*, o
);
253 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
254 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
255 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
256 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
)
261 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
262 wxObjectAllocatorAndCreator_4<klass,t0,t1,t2,t3> constructor##klass; \
263 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
264 const wxChar *klass::ms_constructorProperties[] = \
265 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
266 const int klass::ms_constructorPropertiesCount = 4;
268 // direct constructor version
270 template<typename Class
,
271 typename T0
, typename T1
, typename T2
, typename T3
>
272 struct wxDirectConstructorBridge_4
: public wxObjectAllocator
274 bool Create(wxObject
* &o
, wxVariantBase
*args
)
277 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
278 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
279 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
280 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
)
286 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
287 wxDirectConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass; \
288 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
289 const wxChar *klass::ms_constructorProperties[] = \
290 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
291 const int klass::ms_constructorPropertiesCount = 4;
296 template<typename Class
,
297 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
298 struct wxObjectAllocatorAndCreator_5
: public wxObjectAllocatorAndCreator
300 bool Create(wxObject
* &o
, wxVariantBase
*args
)
302 Class
*obj
= wx_dynamic_cast(Class
*, o
);
304 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
305 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
306 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
307 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
308 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
)
313 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
314 wxObjectAllocatorAndCreator_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
315 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
316 const wxChar *klass::ms_constructorProperties[] = \
317 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
318 const int klass::ms_constructorPropertiesCount = 5;
320 // direct constructor version
322 template<typename Class
,
323 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
324 struct wxDirectConstructorBridge_5
: public wxObjectAllocator
326 bool Create(wxObject
* &o
, wxVariantBase
*args
)
329 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
330 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
331 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
332 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
333 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
)
339 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
340 wxDirectConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
341 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
342 const wxChar *klass::ms_constructorProperties[] = \
343 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
344 const int klass::ms_constructorPropertiesCount = 5;
349 template<typename Class
,
350 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
351 struct wxObjectAllocatorAndCreator_6
: public wxObjectAllocatorAndCreator
353 bool Create(wxObject
* &o
, wxVariantBase
*args
)
355 Class
*obj
= wx_dynamic_cast(Class
*, o
);
357 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
358 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
359 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
360 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
361 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
362 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
367 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
368 wxObjectAllocatorAndCreator_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
369 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
370 const wxChar *klass::ms_constructorProperties[] = \
371 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
372 const int klass::ms_constructorPropertiesCount = 6;
374 // direct constructor version
376 template<typename Class
,
377 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
378 struct wxDirectConstructorBridge_6
: public wxObjectAllocator
380 bool Create(wxObject
* &o
, wxVariantBase
*args
)
383 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
384 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
385 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
386 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
387 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
388 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
)
394 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
395 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
396 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
397 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
398 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
399 const int klass::ms_constructorPropertiesCount = 6;
404 template<typename Class
,
405 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
406 struct wxObjectAllocatorAndCreator_7
: public wxObjectAllocatorAndCreator
408 bool Create(wxObject
* &o
, wxVariantBase
*args
)
410 Class
*obj
= wx_dynamic_cast(Class
*, o
);
412 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
413 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
414 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
415 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
416 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
417 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
),
418 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
)
423 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
424 wxObjectAllocatorAndCreator_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
425 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
426 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
427 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
428 const int klass::ms_constructorPropertiesCount = 7;
430 // direct constructor version
432 template<typename Class
,
433 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
434 struct wxDirectConstructorBridge_7
: public wxObjectAllocator
436 bool Create(wxObject
* &o
, wxVariantBase
*args
)
439 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
440 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
441 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
442 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
443 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
444 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T5
),
445 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T6
)
451 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
452 wxDirectConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
453 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
454 const wxChar *klass::ms_constructorProperties[] = \
455 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
456 const int klass::ms_constructorPropertiesCount = 7;
461 template<typename Class
,
462 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
463 typename T6
, typename T7
>
464 struct wxObjectAllocatorAndCreator_8
: public wxObjectAllocatorAndCreator
466 bool Create(wxObject
* &o
, wxVariantBase
*args
)
468 Class
*obj
= wx_dynamic_cast(Class
*, o
);
470 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
471 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
472 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
473 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
474 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
475 args
[5].wxTEMPLATED_MEMBER_CALL(Get
, T5
),
476 args
[6].wxTEMPLATED_MEMBER_CALL(Get
, T6
),
477 args
[7].wxTEMPLATED_MEMBER_CALL(Get
, T7
)
482 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
483 wxObjectAllocatorAndCreator_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
484 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
485 const wxChar *klass::ms_constructorProperties[] = \
486 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
487 const int klass::ms_constructorPropertiesCount = 8;
489 // direct constructor version
491 template<typename Class
,
492 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
493 typename T6
, typename T7
>
494 struct wxDirectConstructorBridge_8
: public wxObjectAllocator
496 bool Create(wxObject
* &o
, wxVariantBase
*args
)
499 args
[0].wxTEMPLATED_MEMBER_CALL(Get
, T0
),
500 args
[1].wxTEMPLATED_MEMBER_CALL(Get
, T1
),
501 args
[2].wxTEMPLATED_MEMBER_CALL(Get
, T2
),
502 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T3
),
503 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T4
),
504 args
[3].wxTEMPLATED_MEMBER_CALL(Get
, T5
),
505 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T6
),
506 args
[4].wxTEMPLATED_MEMBER_CALL(Get
, T7
)
512 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
513 wxDirectConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
514 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
515 const wxChar *klass::ms_constructorProperties[] = \
516 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
517 const int klass::ms_constructorPropertiesCount = 8;
519 #endif // wxUSE_EXTENDED_RTTI
520 #endif // _XTICTOR_H_