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
22 // ----------------------------------------------------------------------------
23 // Constructor Bridges
24 // ----------------------------------------------------------------------------
26 // A constructor bridge allows to call a ctor with an arbitrary number
27 // or parameters during runtime
28 class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
31 virtual ~wxObjectAllocatorAndCreator() { }
32 virtual bool Create(wxObject
* &o
, wxAny
*args
) = 0;
35 // a direct constructor bridge calls the operator new for this class and
36 // passes all params to the constructor. Needed for classes that cannot be
37 // instantiated using alloc-create semantics
38 class WXDLLIMPEXP_BASE wxObjectAllocator
: public wxObjectAllocatorAndCreator
41 virtual bool Create(wxObject
* &o
, wxAny
*args
) = 0;
45 // ----------------------------------------------------------------------------
46 // Constructor Bridges for all Numbers of Params
47 // ----------------------------------------------------------------------------
51 template<typename Class
>
52 struct wxObjectAllocatorAndCreator_0
: public wxObjectAllocatorAndCreator
54 bool Create(wxObject
* &o
, wxAny
*)
56 Class
*obj
= wx_dynamic_cast(Class
*, o
);
61 struct wxObjectAllocatorAndCreator_Dummy
: public wxObjectAllocatorAndCreator
63 bool Create(wxObject
*&, wxAny
*)
69 #define wxCONSTRUCTOR_0(klass) \
70 wxObjectAllocatorAndCreator_0<klass> constructor##klass; \
71 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
72 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
73 const int klass::ms_constructorPropertiesCount = 0;
75 #define wxCONSTRUCTOR_DUMMY(klass) \
76 wxObjectAllocatorAndCreator_Dummy constructor##klass; \
77 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
78 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
79 const int klass::ms_constructorPropertiesCount = 0;
81 // direct constructor version
83 template<typename Class
>
84 struct wxDirectConstructorBridge_0
: public wxObjectAllocator
86 bool Create(wxObject
* &o
, wxAny
*args
)
93 #define wxDIRECT_CONSTRUCTOR_0(klass) \
94 wxDirectConstructorBridge_0<klass> constructor##klass; \
95 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
96 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
97 const int klass::ms_constructorPropertiesCount = 0;
102 template<typename Class
, typename T0
>
103 struct wxObjectAllocatorAndCreator_1
: public wxObjectAllocatorAndCreator
105 bool Create(wxObject
* &o
, wxAny
*args
)
107 Class
*obj
= wx_dynamic_cast(Class
*, o
);
109 (args
[0]).As(static_cast<T0
*>(NULL
))
114 #define wxCONSTRUCTOR_1(klass,t0,v0) \
115 wxObjectAllocatorAndCreator_1<klass,t0> constructor##klass; \
116 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
117 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
118 const int klass::ms_constructorPropertiesCount = 1;
120 // direct constructor version
122 template<typename Class
, typename T0
>
123 struct wxDirectConstructorBridge_1
: public wxObjectAllocator
125 bool Create(wxObject
* &o
, wxAny
*args
)
128 (args
[0]).As(static_cast<T0
*>(NULL
))
134 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
135 wxDirectConstructorBridge_1<klass,t0,t1> constructor##klass; \
136 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
137 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
138 const int klass::ms_constructorPropertiesCount = 1;
143 template<typename Class
,
144 typename T0
, typename T1
>
145 struct wxObjectAllocatorAndCreator_2
: public wxObjectAllocatorAndCreator
147 bool Create(wxObject
* &o
, wxAny
*args
)
149 Class
*obj
= wx_dynamic_cast(Class
*, o
);
151 (args
[0]).As(static_cast<T0
*>(NULL
)),
152 (args
[1]).As(static_cast<T1
*>(NULL
))
157 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
158 wxObjectAllocatorAndCreator_2<klass,t0,t1> constructor##klass; \
159 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
160 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
161 const int klass::ms_constructorPropertiesCount = 2;
163 // direct constructor version
165 template<typename Class
,
166 typename T0
, typename T1
>
167 struct wxDirectConstructorBridge_2
: public wxObjectAllocator
169 bool Create(wxObject
* &o
, wxAny
*args
)
172 (args
[0]).As(static_cast<T0
*>(NULL
)),
173 (args
[1]).As(static_cast<T1
*>(NULL
))
179 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
180 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass; \
181 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
182 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
183 const int klass::ms_constructorPropertiesCount = 2;
188 template<typename Class
,
189 typename T0
, typename T1
, typename T2
>
190 struct wxObjectAllocatorAndCreator_3
: public wxObjectAllocatorAndCreator
192 bool Create(wxObject
* &o
, wxAny
*args
)
194 Class
*obj
= wx_dynamic_cast(Class
*, o
);
196 (args
[0]).As(static_cast<T0
*>(NULL
)),
197 (args
[1]).As(static_cast<T1
*>(NULL
)),
198 (args
[2]).As(static_cast<T2
*>(NULL
))
203 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
204 wxObjectAllocatorAndCreator_3<klass,t0,t1,t2> constructor##klass; \
205 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
206 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
207 const int klass::ms_constructorPropertiesCount = 3;
209 // direct constructor version
211 template<typename Class
,
212 typename T0
, typename T1
, typename T2
>
213 struct wxDirectConstructorBridge_3
: public wxObjectAllocator
215 bool Create(wxObject
* &o
, wxAny
*args
)
218 (args
[0]).As(static_cast<T0
*>(NULL
)),
219 (args
[1]).As(static_cast<T1
*>(NULL
)),
220 (args
[2]).As(static_cast<T2
*>(NULL
))
226 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
227 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass; \
228 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
229 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
230 const int klass::ms_constructorPropertiesCount = 3;
235 template<typename Class
,
236 typename T0
, typename T1
, typename T2
, typename T3
>
237 struct wxObjectAllocatorAndCreator_4
: public wxObjectAllocatorAndCreator
239 bool Create(wxObject
* &o
, wxAny
*args
)
241 Class
*obj
= wx_dynamic_cast(Class
*, o
);
243 (args
[0]).As(static_cast<T0
*>(NULL
)),
244 (args
[1]).As(static_cast<T1
*>(NULL
)),
245 (args
[2]).As(static_cast<T2
*>(NULL
)),
246 (args
[3]).As(static_cast<T3
*>(NULL
))
251 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
252 wxObjectAllocatorAndCreator_4<klass,t0,t1,t2,t3> constructor##klass; \
253 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
254 const wxChar *klass::ms_constructorProperties[] = \
255 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
256 const int klass::ms_constructorPropertiesCount = 4;
258 // direct constructor version
260 template<typename Class
,
261 typename T0
, typename T1
, typename T2
, typename T3
>
262 struct wxDirectConstructorBridge_4
: public wxObjectAllocator
264 bool Create(wxObject
* &o
, wxAny
*args
)
267 (args
[0]).As(static_cast<T0
*>(NULL
)),
268 (args
[1]).As(static_cast<T1
*>(NULL
)),
269 (args
[2]).As(static_cast<T2
*>(NULL
)),
270 (args
[3]).As(static_cast<T3
*>(NULL
))
276 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
277 wxDirectConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass; \
278 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
279 const wxChar *klass::ms_constructorProperties[] = \
280 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
281 const int klass::ms_constructorPropertiesCount = 4;
286 template<typename Class
,
287 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
288 struct wxObjectAllocatorAndCreator_5
: public wxObjectAllocatorAndCreator
290 bool Create(wxObject
* &o
, wxAny
*args
)
292 Class
*obj
= wx_dynamic_cast(Class
*, o
);
294 (args
[0]).As(static_cast<T0
*>(NULL
)),
295 (args
[1]).As(static_cast<T1
*>(NULL
)),
296 (args
[2]).As(static_cast<T2
*>(NULL
)),
297 (args
[3]).As(static_cast<T3
*>(NULL
)),
298 (args
[4]).As(static_cast<T4
*>(NULL
))
303 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
304 wxObjectAllocatorAndCreator_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
305 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
306 const wxChar *klass::ms_constructorProperties[] = \
307 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
308 const int klass::ms_constructorPropertiesCount = 5;
310 // direct constructor version
312 template<typename Class
,
313 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
314 struct wxDirectConstructorBridge_5
: public wxObjectAllocator
316 bool Create(wxObject
* &o
, wxAny
*args
)
319 (args
[0]).As(static_cast<T0
*>(NULL
)),
320 (args
[1]).As(static_cast<T1
*>(NULL
)),
321 (args
[2]).As(static_cast<T2
*>(NULL
)),
322 (args
[3]).As(static_cast<T3
*>(NULL
)),
323 (args
[4]).As(static_cast<T4
*>(NULL
))
329 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
330 wxDirectConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
331 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
332 const wxChar *klass::ms_constructorProperties[] = \
333 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
334 const int klass::ms_constructorPropertiesCount = 5;
339 template<typename Class
,
340 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
341 struct wxObjectAllocatorAndCreator_6
: public wxObjectAllocatorAndCreator
343 bool Create(wxObject
* &o
, wxAny
*args
)
345 Class
*obj
= wx_dynamic_cast(Class
*, o
);
347 (args
[0]).As(static_cast<T0
*>(NULL
)),
348 (args
[1]).As(static_cast<T1
*>(NULL
)),
349 (args
[2]).As(static_cast<T2
*>(NULL
)),
350 (args
[3]).As(static_cast<T3
*>(NULL
)),
351 (args
[4]).As(static_cast<T4
*>(NULL
)),
352 (args
[5]).As(static_cast<T5
*>(NULL
))
357 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
358 wxObjectAllocatorAndCreator_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
359 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
360 const wxChar *klass::ms_constructorProperties[] = \
361 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
362 const int klass::ms_constructorPropertiesCount = 6;
364 // direct constructor version
366 template<typename Class
,
367 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
368 struct wxDirectConstructorBridge_6
: public wxObjectAllocator
370 bool Create(wxObject
* &o
, wxAny
*args
)
373 (args
[0]).As(static_cast<T0
*>(NULL
)),
374 (args
[1]).As(static_cast<T1
*>(NULL
)),
375 (args
[2]).As(static_cast<T2
*>(NULL
)),
376 (args
[3]).As(static_cast<T3
*>(NULL
)),
377 (args
[4]).As(static_cast<T4
*>(NULL
)),
378 (args
[5]).As(static_cast<T5
*>(NULL
))
384 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
385 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
386 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
387 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
388 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
389 const int klass::ms_constructorPropertiesCount = 6;
394 template<typename Class
,
395 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
396 struct wxObjectAllocatorAndCreator_7
: public wxObjectAllocatorAndCreator
398 bool Create(wxObject
* &o
, wxAny
*args
)
400 Class
*obj
= wx_dynamic_cast(Class
*, o
);
402 (args
[0]).As(static_cast<T0
*>(NULL
)),
403 (args
[1]).As(static_cast<T1
*>(NULL
)),
404 (args
[2]).As(static_cast<T2
*>(NULL
)),
405 (args
[3]).As(static_cast<T3
*>(NULL
)),
406 (args
[4]).As(static_cast<T4
*>(NULL
)),
407 (args
[5]).As(static_cast<T5
*>(NULL
)),
408 (args
[6]).As(static_cast<T6
*>(NULL
))
413 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
414 wxObjectAllocatorAndCreator_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
415 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
416 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
417 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
418 const int klass::ms_constructorPropertiesCount = 7;
420 // direct constructor version
422 template<typename Class
,
423 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
424 struct wxDirectConstructorBridge_7
: public wxObjectAllocator
426 bool Create(wxObject
* &o
, wxAny
*args
)
429 (args
[0]).As(static_cast<T0
*>(NULL
)),
430 (args
[1]).As(static_cast<T1
*>(NULL
)),
431 (args
[2]).As(static_cast<T2
*>(NULL
)),
432 (args
[3]).As(static_cast<T3
*>(NULL
)),
433 (args
[4]).As(static_cast<T4
*>(NULL
)),
434 (args
[5]).As(static_cast<T5
*>(NULL
)),
435 (args
[6]).As(static_cast<T6
*>(NULL
))
441 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
442 wxDirectConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
443 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
444 const wxChar *klass::ms_constructorProperties[] = \
445 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
446 const int klass::ms_constructorPropertiesCount = 7;
451 template<typename Class
,
452 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
453 typename T6
, typename T7
>
454 struct wxObjectAllocatorAndCreator_8
: public wxObjectAllocatorAndCreator
456 bool Create(wxObject
* &o
, wxAny
*args
)
458 Class
*obj
= wx_dynamic_cast(Class
*, o
);
460 (args
[0]).As(static_cast<T0
*>(NULL
)),
461 (args
[1]).As(static_cast<T1
*>(NULL
)),
462 (args
[2]).As(static_cast<T2
*>(NULL
)),
463 (args
[3]).As(static_cast<T3
*>(NULL
)),
464 (args
[4]).As(static_cast<T4
*>(NULL
)),
465 (args
[5]).As(static_cast<T5
*>(NULL
)),
466 (args
[6]).As(static_cast<T6
*>(NULL
)),
467 (args
[7]).As(static_cast<T7
*>(NULL
))
472 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
473 wxObjectAllocatorAndCreator_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
474 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
475 const wxChar *klass::ms_constructorProperties[] = \
476 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
477 const int klass::ms_constructorPropertiesCount = 8;
479 // direct constructor version
481 template<typename Class
,
482 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
483 typename T6
, typename T7
>
484 struct wxDirectConstructorBridge_8
: public wxObjectAllocator
486 bool Create(wxObject
* &o
, wxAny
*args
)
489 (args
[0]).As(static_cast<T0
*>(NULL
)),
490 (args
[1]).As(static_cast<T1
*>(NULL
)),
491 (args
[2]).As(static_cast<T2
*>(NULL
)),
492 (args
[3]).As(static_cast<T3
*>(NULL
)),
493 (args
[4]).As(static_cast<T4
*>(NULL
)),
494 (args
[5]).As(static_cast<T5
*>(NULL
)),
495 (args
[6]).As(static_cast<T6
*>(NULL
)),
496 (args
[7]).As(static_cast<T7
*>(NULL
))
502 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
503 wxDirectConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
504 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
505 const wxChar *klass::ms_constructorProperties[] = \
506 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
507 const int klass::ms_constructorPropertiesCount = 8;
509 #endif // wxUSE_EXTENDED_RTTI
510 #endif // _XTICTOR_H_