1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XTI constructors
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
7 // Copyright: (c) 1997 Julian Smart
8 // (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #if wxUSE_EXTENDED_RTTI
21 // ----------------------------------------------------------------------------
22 // Constructor Bridges
23 // ----------------------------------------------------------------------------
25 // A constructor bridge allows to call a ctor with an arbitrary number
26 // or parameters during runtime
27 class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
30 virtual ~wxObjectAllocatorAndCreator() { }
31 virtual bool Create(wxObject
* &o
, wxAny
*args
) = 0;
34 // a direct constructor bridge calls the operator new for this class and
35 // passes all params to the constructor. Needed for classes that cannot be
36 // instantiated using alloc-create semantics
37 class WXDLLIMPEXP_BASE wxObjectAllocator
: public wxObjectAllocatorAndCreator
40 virtual bool Create(wxObject
* &o
, wxAny
*args
) = 0;
44 // ----------------------------------------------------------------------------
45 // Constructor Bridges for all Numbers of Params
46 // ----------------------------------------------------------------------------
50 template<typename Class
>
51 struct wxObjectAllocatorAndCreator_0
: public wxObjectAllocatorAndCreator
53 bool Create(wxObject
* &o
, wxAny
*)
55 Class
*obj
= wx_dynamic_cast(Class
*, o
);
60 struct wxObjectAllocatorAndCreator_Dummy
: public wxObjectAllocatorAndCreator
62 bool Create(wxObject
*&, wxAny
*)
68 #define wxCONSTRUCTOR_0(klass) \
69 wxObjectAllocatorAndCreator_0<klass> constructor##klass; \
70 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
71 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
72 const int klass::ms_constructorPropertiesCount = 0;
74 #define wxCONSTRUCTOR_DUMMY(klass) \
75 wxObjectAllocatorAndCreator_Dummy constructor##klass; \
76 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
77 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
78 const int klass::ms_constructorPropertiesCount = 0;
80 // direct constructor version
82 template<typename Class
>
83 struct wxDirectConstructorBridge_0
: public wxObjectAllocator
85 bool Create(wxObject
* &o
, wxAny
*args
)
92 #define wxDIRECT_CONSTRUCTOR_0(klass) \
93 wxDirectConstructorBridge_0<klass> constructor##klass; \
94 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
95 const wxChar *klass::ms_constructorProperties[] = { NULL }; \
96 const int klass::ms_constructorPropertiesCount = 0;
101 template<typename Class
, typename T0
>
102 struct wxObjectAllocatorAndCreator_1
: public wxObjectAllocatorAndCreator
104 bool Create(wxObject
* &o
, wxAny
*args
)
106 Class
*obj
= wx_dynamic_cast(Class
*, o
);
108 (args
[0]).As(static_cast<T0
*>(NULL
))
113 #define wxCONSTRUCTOR_1(klass,t0,v0) \
114 wxObjectAllocatorAndCreator_1<klass,t0> constructor##klass; \
115 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
116 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
117 const int klass::ms_constructorPropertiesCount = 1;
119 // direct constructor version
121 template<typename Class
, typename T0
>
122 struct wxDirectConstructorBridge_1
: public wxObjectAllocator
124 bool Create(wxObject
* &o
, wxAny
*args
)
127 (args
[0]).As(static_cast<T0
*>(NULL
))
133 #define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
134 wxDirectConstructorBridge_1<klass,t0,t1> constructor##klass; \
135 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
136 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0) }; \
137 const int klass::ms_constructorPropertiesCount = 1;
142 template<typename Class
,
143 typename T0
, typename T1
>
144 struct wxObjectAllocatorAndCreator_2
: public wxObjectAllocatorAndCreator
146 bool Create(wxObject
* &o
, wxAny
*args
)
148 Class
*obj
= wx_dynamic_cast(Class
*, o
);
150 (args
[0]).As(static_cast<T0
*>(NULL
)),
151 (args
[1]).As(static_cast<T1
*>(NULL
))
156 #define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
157 wxObjectAllocatorAndCreator_2<klass,t0,t1> constructor##klass; \
158 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
159 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
160 const int klass::ms_constructorPropertiesCount = 2;
162 // direct constructor version
164 template<typename Class
,
165 typename T0
, typename T1
>
166 struct wxDirectConstructorBridge_2
: public wxObjectAllocator
168 bool Create(wxObject
* &o
, wxAny
*args
)
171 (args
[0]).As(static_cast<T0
*>(NULL
)),
172 (args
[1]).As(static_cast<T1
*>(NULL
))
178 #define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
179 wxDirectConstructorBridge_2<klass,t0,t1> constructor##klass; \
180 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
181 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1) }; \
182 const int klass::ms_constructorPropertiesCount = 2;
187 template<typename Class
,
188 typename T0
, typename T1
, typename T2
>
189 struct wxObjectAllocatorAndCreator_3
: public wxObjectAllocatorAndCreator
191 bool Create(wxObject
* &o
, wxAny
*args
)
193 Class
*obj
= wx_dynamic_cast(Class
*, o
);
195 (args
[0]).As(static_cast<T0
*>(NULL
)),
196 (args
[1]).As(static_cast<T1
*>(NULL
)),
197 (args
[2]).As(static_cast<T2
*>(NULL
))
202 #define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
203 wxObjectAllocatorAndCreator_3<klass,t0,t1,t2> constructor##klass; \
204 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
205 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
206 const int klass::ms_constructorPropertiesCount = 3;
208 // direct constructor version
210 template<typename Class
,
211 typename T0
, typename T1
, typename T2
>
212 struct wxDirectConstructorBridge_3
: public wxObjectAllocator
214 bool Create(wxObject
* &o
, wxAny
*args
)
217 (args
[0]).As(static_cast<T0
*>(NULL
)),
218 (args
[1]).As(static_cast<T1
*>(NULL
)),
219 (args
[2]).As(static_cast<T2
*>(NULL
))
225 #define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
226 wxDirectConstructorBridge_3<klass,t0,t1,t2> constructor##klass; \
227 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
228 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), wxT(#v2) }; \
229 const int klass::ms_constructorPropertiesCount = 3;
234 template<typename Class
,
235 typename T0
, typename T1
, typename T2
, typename T3
>
236 struct wxObjectAllocatorAndCreator_4
: public wxObjectAllocatorAndCreator
238 bool Create(wxObject
* &o
, wxAny
*args
)
240 Class
*obj
= wx_dynamic_cast(Class
*, o
);
242 (args
[0]).As(static_cast<T0
*>(NULL
)),
243 (args
[1]).As(static_cast<T1
*>(NULL
)),
244 (args
[2]).As(static_cast<T2
*>(NULL
)),
245 (args
[3]).As(static_cast<T3
*>(NULL
))
250 #define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
251 wxObjectAllocatorAndCreator_4<klass,t0,t1,t2,t3> constructor##klass; \
252 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
253 const wxChar *klass::ms_constructorProperties[] = \
254 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
255 const int klass::ms_constructorPropertiesCount = 4;
257 // direct constructor version
259 template<typename Class
,
260 typename T0
, typename T1
, typename T2
, typename T3
>
261 struct wxDirectConstructorBridge_4
: public wxObjectAllocator
263 bool Create(wxObject
* &o
, wxAny
*args
)
266 (args
[0]).As(static_cast<T0
*>(NULL
)),
267 (args
[1]).As(static_cast<T1
*>(NULL
)),
268 (args
[2]).As(static_cast<T2
*>(NULL
)),
269 (args
[3]).As(static_cast<T3
*>(NULL
))
275 #define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
276 wxDirectConstructorBridge_4<klass,t0,t1,t2,t3> constructor##klass; \
277 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
278 const wxChar *klass::ms_constructorProperties[] = \
279 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3) }; \
280 const int klass::ms_constructorPropertiesCount = 4;
285 template<typename Class
,
286 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
287 struct wxObjectAllocatorAndCreator_5
: public wxObjectAllocatorAndCreator
289 bool Create(wxObject
* &o
, wxAny
*args
)
291 Class
*obj
= wx_dynamic_cast(Class
*, o
);
293 (args
[0]).As(static_cast<T0
*>(NULL
)),
294 (args
[1]).As(static_cast<T1
*>(NULL
)),
295 (args
[2]).As(static_cast<T2
*>(NULL
)),
296 (args
[3]).As(static_cast<T3
*>(NULL
)),
297 (args
[4]).As(static_cast<T4
*>(NULL
))
302 #define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
303 wxObjectAllocatorAndCreator_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
304 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
305 const wxChar *klass::ms_constructorProperties[] = \
306 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
307 const int klass::ms_constructorPropertiesCount = 5;
309 // direct constructor version
311 template<typename Class
,
312 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
>
313 struct wxDirectConstructorBridge_5
: public wxObjectAllocator
315 bool Create(wxObject
* &o
, wxAny
*args
)
318 (args
[0]).As(static_cast<T0
*>(NULL
)),
319 (args
[1]).As(static_cast<T1
*>(NULL
)),
320 (args
[2]).As(static_cast<T2
*>(NULL
)),
321 (args
[3]).As(static_cast<T3
*>(NULL
)),
322 (args
[4]).As(static_cast<T4
*>(NULL
))
328 #define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
329 wxDirectConstructorBridge_5<klass,t0,t1,t2,t3,t4> constructor##klass; \
330 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
331 const wxChar *klass::ms_constructorProperties[] = \
332 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4) }; \
333 const int klass::ms_constructorPropertiesCount = 5;
338 template<typename Class
,
339 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
340 struct wxObjectAllocatorAndCreator_6
: public wxObjectAllocatorAndCreator
342 bool Create(wxObject
* &o
, wxAny
*args
)
344 Class
*obj
= wx_dynamic_cast(Class
*, o
);
346 (args
[0]).As(static_cast<T0
*>(NULL
)),
347 (args
[1]).As(static_cast<T1
*>(NULL
)),
348 (args
[2]).As(static_cast<T2
*>(NULL
)),
349 (args
[3]).As(static_cast<T3
*>(NULL
)),
350 (args
[4]).As(static_cast<T4
*>(NULL
)),
351 (args
[5]).As(static_cast<T5
*>(NULL
))
356 #define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
357 wxObjectAllocatorAndCreator_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
358 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
359 const wxChar *klass::ms_constructorProperties[] = \
360 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
361 const int klass::ms_constructorPropertiesCount = 6;
363 // direct constructor version
365 template<typename Class
,
366 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
>
367 struct wxDirectConstructorBridge_6
: public wxObjectAllocator
369 bool Create(wxObject
* &o
, wxAny
*args
)
372 (args
[0]).As(static_cast<T0
*>(NULL
)),
373 (args
[1]).As(static_cast<T1
*>(NULL
)),
374 (args
[2]).As(static_cast<T2
*>(NULL
)),
375 (args
[3]).As(static_cast<T3
*>(NULL
)),
376 (args
[4]).As(static_cast<T4
*>(NULL
)),
377 (args
[5]).As(static_cast<T5
*>(NULL
))
383 #define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
384 wxDirectConstructorBridge_6<klass,t0,t1,t2,t3,t4,t5> constructor##klass; \
385 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
386 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
387 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5) }; \
388 const int klass::ms_constructorPropertiesCount = 6;
393 template<typename Class
,
394 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
395 struct wxObjectAllocatorAndCreator_7
: public wxObjectAllocatorAndCreator
397 bool Create(wxObject
* &o
, wxAny
*args
)
399 Class
*obj
= wx_dynamic_cast(Class
*, o
);
401 (args
[0]).As(static_cast<T0
*>(NULL
)),
402 (args
[1]).As(static_cast<T1
*>(NULL
)),
403 (args
[2]).As(static_cast<T2
*>(NULL
)),
404 (args
[3]).As(static_cast<T3
*>(NULL
)),
405 (args
[4]).As(static_cast<T4
*>(NULL
)),
406 (args
[5]).As(static_cast<T5
*>(NULL
)),
407 (args
[6]).As(static_cast<T6
*>(NULL
))
412 #define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
413 wxObjectAllocatorAndCreator_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
414 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
415 const wxChar *klass::ms_constructorProperties[] = { wxT(#v0), wxT(#v1), \
416 wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
417 const int klass::ms_constructorPropertiesCount = 7;
419 // direct constructor version
421 template<typename Class
,
422 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, typename T6
>
423 struct wxDirectConstructorBridge_7
: public wxObjectAllocator
425 bool Create(wxObject
* &o
, wxAny
*args
)
428 (args
[0]).As(static_cast<T0
*>(NULL
)),
429 (args
[1]).As(static_cast<T1
*>(NULL
)),
430 (args
[2]).As(static_cast<T2
*>(NULL
)),
431 (args
[3]).As(static_cast<T3
*>(NULL
)),
432 (args
[4]).As(static_cast<T4
*>(NULL
)),
433 (args
[5]).As(static_cast<T5
*>(NULL
)),
434 (args
[6]).As(static_cast<T6
*>(NULL
))
440 #define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
441 wxDirectConstructorBridge_7<klass,t0,t1,t2,t3,t4,t5,t6> constructor##klass; \
442 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
443 const wxChar *klass::ms_constructorProperties[] = \
444 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6) }; \
445 const int klass::ms_constructorPropertiesCount = 7;
450 template<typename Class
,
451 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
452 typename T6
, typename T7
>
453 struct wxObjectAllocatorAndCreator_8
: public wxObjectAllocatorAndCreator
455 bool Create(wxObject
* &o
, wxAny
*args
)
457 Class
*obj
= wx_dynamic_cast(Class
*, o
);
459 (args
[0]).As(static_cast<T0
*>(NULL
)),
460 (args
[1]).As(static_cast<T1
*>(NULL
)),
461 (args
[2]).As(static_cast<T2
*>(NULL
)),
462 (args
[3]).As(static_cast<T3
*>(NULL
)),
463 (args
[4]).As(static_cast<T4
*>(NULL
)),
464 (args
[5]).As(static_cast<T5
*>(NULL
)),
465 (args
[6]).As(static_cast<T6
*>(NULL
)),
466 (args
[7]).As(static_cast<T7
*>(NULL
))
471 #define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
472 wxObjectAllocatorAndCreator_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
473 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
474 const wxChar *klass::ms_constructorProperties[] = \
475 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
476 const int klass::ms_constructorPropertiesCount = 8;
478 // direct constructor version
480 template<typename Class
,
481 typename T0
, typename T1
, typename T2
, typename T3
, typename T4
, typename T5
, \
482 typename T6
, typename T7
>
483 struct wxDirectConstructorBridge_8
: public wxObjectAllocator
485 bool Create(wxObject
* &o
, wxAny
*args
)
488 (args
[0]).As(static_cast<T0
*>(NULL
)),
489 (args
[1]).As(static_cast<T1
*>(NULL
)),
490 (args
[2]).As(static_cast<T2
*>(NULL
)),
491 (args
[3]).As(static_cast<T3
*>(NULL
)),
492 (args
[4]).As(static_cast<T4
*>(NULL
)),
493 (args
[5]).As(static_cast<T5
*>(NULL
)),
494 (args
[6]).As(static_cast<T6
*>(NULL
)),
495 (args
[7]).As(static_cast<T7
*>(NULL
))
501 #define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
502 wxDirectConstructorBridge_8<klass,t0,t1,t2,t3,t4,t5,t6,t7> constructor##klass; \
503 wxObjectAllocatorAndCreator* klass::ms_constructor = &constructor##klass; \
504 const wxChar *klass::ms_constructorProperties[] = \
505 { wxT(#v0), wxT(#v1), wxT(#v2), wxT(#v3), wxT(#v4), wxT(#v5), wxT(#v6), wxT(#v7) }; \
506 const int klass::ms_constructorPropertiesCount = 8;
508 #endif // wxUSE_EXTENDED_RTTI
509 #endif // _XTICTOR_H_