]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xtictor.h
remove DoSetSize override, unneeded after r72001
[wxWidgets.git] / include / wx / xtictor.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/xtictor.h
3 // Purpose: XTI constructors
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _XTICTOR_H_
14 #define _XTICTOR_H_
15
16 #include "wx/defs.h"
17
18 #if wxUSE_EXTENDED_RTTI
19
20 #include "wx/xti.h"
21
22 // ----------------------------------------------------------------------------
23 // Constructor Bridges
24 // ----------------------------------------------------------------------------
25
26 // A constructor bridge allows to call a ctor with an arbitrary number
27 // or parameters during runtime
28 class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
29 {
30 public:
31 virtual ~wxObjectAllocatorAndCreator() { }
32 virtual bool Create(wxObject * &o, wxAny *args) = 0;
33 };
34
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
39 {
40 public:
41 virtual bool Create(wxObject * &o, wxAny *args) = 0;
42 };
43
44
45 // ----------------------------------------------------------------------------
46 // Constructor Bridges for all Numbers of Params
47 // ----------------------------------------------------------------------------
48
49 // no params
50
51 template<typename Class>
52 struct wxObjectAllocatorAndCreator_0 : public wxObjectAllocatorAndCreator
53 {
54 bool Create(wxObject * &o, wxAny *)
55 {
56 Class *obj = wx_dynamic_cast(Class*, o);
57 return obj->Create();
58 }
59 };
60
61 struct wxObjectAllocatorAndCreator_Dummy : public wxObjectAllocatorAndCreator
62 {
63 bool Create(wxObject *&, wxAny *)
64 {
65 return true;
66 }
67 };
68
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;
74
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;
80
81 // direct constructor version
82
83 template<typename Class>
84 struct wxDirectConstructorBridge_0 : public wxObjectAllocator
85 {
86 bool Create(wxObject * &o, wxAny *args)
87 {
88 o = new Class( );
89 return o != NULL;
90 }
91 };
92
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;
98
99
100 // 1 param
101
102 template<typename Class, typename T0>
103 struct wxObjectAllocatorAndCreator_1 : public wxObjectAllocatorAndCreator
104 {
105 bool Create(wxObject * &o, wxAny *args)
106 {
107 Class *obj = wx_dynamic_cast(Class*, o);
108 return obj->Create(
109 (args[0]).As(static_cast<T0*>(NULL))
110 );
111 }
112 };
113
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;
119
120 // direct constructor version
121
122 template<typename Class, typename T0>
123 struct wxDirectConstructorBridge_1 : public wxObjectAllocator
124 {
125 bool Create(wxObject * &o, wxAny *args)
126 {
127 o = new Class(
128 (args[0]).As(static_cast<T0*>(NULL))
129 );
130 return o != NULL;
131 }
132 };
133
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;
139
140
141 // 2 params
142
143 template<typename Class,
144 typename T0, typename T1>
145 struct wxObjectAllocatorAndCreator_2 : public wxObjectAllocatorAndCreator
146 {
147 bool Create(wxObject * &o, wxAny *args)
148 {
149 Class *obj = wx_dynamic_cast(Class*, o);
150 return obj->Create(
151 (args[0]).As(static_cast<T0*>(NULL)),
152 (args[1]).As(static_cast<T1*>(NULL))
153 );
154 }
155 };
156
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;
162
163 // direct constructor version
164
165 template<typename Class,
166 typename T0, typename T1>
167 struct wxDirectConstructorBridge_2 : public wxObjectAllocator
168 {
169 bool Create(wxObject * &o, wxAny *args)
170 {
171 o = new Class(
172 (args[0]).As(static_cast<T0*>(NULL)),
173 (args[1]).As(static_cast<T1*>(NULL))
174 );
175 return o != NULL;
176 }
177 };
178
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;
184
185
186 // 3 params
187
188 template<typename Class,
189 typename T0, typename T1, typename T2>
190 struct wxObjectAllocatorAndCreator_3 : public wxObjectAllocatorAndCreator
191 {
192 bool Create(wxObject * &o, wxAny *args)
193 {
194 Class *obj = wx_dynamic_cast(Class*, o);
195 return obj->Create(
196 (args[0]).As(static_cast<T0*>(NULL)),
197 (args[1]).As(static_cast<T1*>(NULL)),
198 (args[2]).As(static_cast<T2*>(NULL))
199 );
200 }
201 };
202
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;
208
209 // direct constructor version
210
211 template<typename Class,
212 typename T0, typename T1, typename T2>
213 struct wxDirectConstructorBridge_3 : public wxObjectAllocator
214 {
215 bool Create(wxObject * &o, wxAny *args)
216 {
217 o = new Class(
218 (args[0]).As(static_cast<T0*>(NULL)),
219 (args[1]).As(static_cast<T1*>(NULL)),
220 (args[2]).As(static_cast<T2*>(NULL))
221 );
222 return o != NULL;
223 }
224 };
225
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;
231
232
233 // 4 params
234
235 template<typename Class,
236 typename T0, typename T1, typename T2, typename T3>
237 struct wxObjectAllocatorAndCreator_4 : public wxObjectAllocatorAndCreator
238 {
239 bool Create(wxObject * &o, wxAny *args)
240 {
241 Class *obj = wx_dynamic_cast(Class*, o);
242 return obj->Create(
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))
247 );
248 }
249 };
250
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;
257
258 // direct constructor version
259
260 template<typename Class,
261 typename T0, typename T1, typename T2, typename T3>
262 struct wxDirectConstructorBridge_4 : public wxObjectAllocator
263 {
264 bool Create(wxObject * &o, wxAny *args)
265 {
266 o = new Class(
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))
271 );
272 return o != NULL;
273 }
274 };
275
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;
282
283
284 // 5 params
285
286 template<typename Class,
287 typename T0, typename T1, typename T2, typename T3, typename T4>
288 struct wxObjectAllocatorAndCreator_5 : public wxObjectAllocatorAndCreator
289 {
290 bool Create(wxObject * &o, wxAny *args)
291 {
292 Class *obj = wx_dynamic_cast(Class*, o);
293 return obj->Create(
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))
299 );
300 }
301 };
302
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;
309
310 // direct constructor version
311
312 template<typename Class,
313 typename T0, typename T1, typename T2, typename T3, typename T4>
314 struct wxDirectConstructorBridge_5 : public wxObjectAllocator
315 {
316 bool Create(wxObject * &o, wxAny *args)
317 {
318 o = new Class(
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))
324 );
325 return o != NULL;
326 }
327 };
328
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;
335
336
337 // 6 params
338
339 template<typename Class,
340 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
341 struct wxObjectAllocatorAndCreator_6 : public wxObjectAllocatorAndCreator
342 {
343 bool Create(wxObject * &o, wxAny *args)
344 {
345 Class *obj = wx_dynamic_cast(Class*, o);
346 return obj->Create(
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))
353 );
354 }
355 };
356
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;
363
364 // direct constructor version
365
366 template<typename Class,
367 typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
368 struct wxDirectConstructorBridge_6 : public wxObjectAllocator
369 {
370 bool Create(wxObject * &o, wxAny *args)
371 {
372 o = new Class(
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))
379 );
380 return o != NULL;
381 }
382 };
383
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;
390
391
392 // 7 params
393
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
397 {
398 bool Create(wxObject * &o, wxAny *args)
399 {
400 Class *obj = wx_dynamic_cast(Class*, o);
401 return obj->Create(
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))
409 );
410 }
411 };
412
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;
419
420 // direct constructor version
421
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
425 {
426 bool Create(wxObject * &o, wxAny *args)
427 {
428 o = new Class(
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))
436 );
437 return o != NULL;
438 }
439 };
440
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;
447
448
449 // 8 params
450
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
455 {
456 bool Create(wxObject * &o, wxAny *args)
457 {
458 Class *obj = wx_dynamic_cast(Class*, o);
459 return obj->Create(
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))
468 );
469 }
470 };
471
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;
478
479 // direct constructor version
480
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
485 {
486 bool Create(wxObject * &o, wxAny *args)
487 {
488 o = new Class(
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))
497 );
498 return o != NULL;
499 }
500 };
501
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;
508
509 #endif // wxUSE_EXTENDED_RTTI
510 #endif // _XTICTOR_H_