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