]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xtictor.h
Fix wxOSX warnings about int-to-void* casts.
[wxWidgets.git] / include / wx / xtictor.h
CommitLineData
e1d3601a
PC
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/xtictor.h
3// Purpose: XTI constructors
4// Author: Stefan Csomor
5// Modified by: Francesco Montorsi
6// Created: 27/07/03
e1d3601a
PC
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
6c887dde 19#include "wx/xti.h"
e1d3601a
PC
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
27class WXDLLIMPEXP_BASE wxObjectAllocatorAndCreator
28{
29public:
30 virtual ~wxObjectAllocatorAndCreator() { }
6c887dde 31 virtual bool Create(wxObject * &o, wxAny *args) = 0;
e1d3601a
PC
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
37class WXDLLIMPEXP_BASE wxObjectAllocator : public wxObjectAllocatorAndCreator
38{
39public:
6c887dde 40 virtual bool Create(wxObject * &o, wxAny *args) = 0;
e1d3601a
PC
41};
42
43
44// ----------------------------------------------------------------------------
45// Constructor Bridges for all Numbers of Params
46// ----------------------------------------------------------------------------
47
48// no params
49
50template<typename Class>
51struct wxObjectAllocatorAndCreator_0 : public wxObjectAllocatorAndCreator
52{
6c887dde 53 bool Create(wxObject * &o, wxAny *)
e1d3601a
PC
54 {
55 Class *obj = wx_dynamic_cast(Class*, o);
56 return obj->Create();
57 }
58};
59
60struct wxObjectAllocatorAndCreator_Dummy : public wxObjectAllocatorAndCreator
61{
6c887dde 62 bool Create(wxObject *&, wxAny *)
e1d3601a
PC
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
82template<typename Class>
83struct wxDirectConstructorBridge_0 : public wxObjectAllocator
84{
6c887dde 85 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
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
101template<typename Class, typename T0>
102struct wxObjectAllocatorAndCreator_1 : public wxObjectAllocatorAndCreator
103{
6c887dde 104 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
105 {
106 Class *obj = wx_dynamic_cast(Class*, o);
107 return obj->Create(
6c887dde 108 (args[0]).As(static_cast<T0*>(NULL))
e1d3601a
PC
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
121template<typename Class, typename T0>
122struct wxDirectConstructorBridge_1 : public wxObjectAllocator
123{
6c887dde 124 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
125 {
126 o = new Class(
6c887dde 127 (args[0]).As(static_cast<T0*>(NULL))
e1d3601a
PC
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
142template<typename Class,
143typename T0, typename T1>
144struct wxObjectAllocatorAndCreator_2 : public wxObjectAllocatorAndCreator
145{
6c887dde 146 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
147 {
148 Class *obj = wx_dynamic_cast(Class*, o);
149 return obj->Create(
6c887dde
SC
150 (args[0]).As(static_cast<T0*>(NULL)),
151 (args[1]).As(static_cast<T1*>(NULL))
e1d3601a
PC
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
164template<typename Class,
165typename T0, typename T1>
166struct wxDirectConstructorBridge_2 : public wxObjectAllocator
167{
6c887dde 168 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
169 {
170 o = new Class(
6c887dde
SC
171 (args[0]).As(static_cast<T0*>(NULL)),
172 (args[1]).As(static_cast<T1*>(NULL))
e1d3601a
PC
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
187template<typename Class,
188typename T0, typename T1, typename T2>
189struct wxObjectAllocatorAndCreator_3 : public wxObjectAllocatorAndCreator
190{
6c887dde 191 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
192 {
193 Class *obj = wx_dynamic_cast(Class*, o);
194 return obj->Create(
6c887dde
SC
195 (args[0]).As(static_cast<T0*>(NULL)),
196 (args[1]).As(static_cast<T1*>(NULL)),
197 (args[2]).As(static_cast<T2*>(NULL))
e1d3601a
PC
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
210template<typename Class,
211typename T0, typename T1, typename T2>
212struct wxDirectConstructorBridge_3 : public wxObjectAllocator
213{
6c887dde 214 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
215 {
216 o = new Class(
6c887dde
SC
217 (args[0]).As(static_cast<T0*>(NULL)),
218 (args[1]).As(static_cast<T1*>(NULL)),
219 (args[2]).As(static_cast<T2*>(NULL))
e1d3601a
PC
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
234template<typename Class,
235typename T0, typename T1, typename T2, typename T3>
236struct wxObjectAllocatorAndCreator_4 : public wxObjectAllocatorAndCreator
237{
6c887dde 238 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
239 {
240 Class *obj = wx_dynamic_cast(Class*, o);
241 return obj->Create(
6c887dde
SC
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))
e1d3601a
PC
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
259template<typename Class,
260typename T0, typename T1, typename T2, typename T3>
261struct wxDirectConstructorBridge_4 : public wxObjectAllocator
262{
6c887dde 263 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
264 {
265 o = new Class(
6c887dde
SC
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))
e1d3601a
PC
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
285template<typename Class,
286typename T0, typename T1, typename T2, typename T3, typename T4>
287struct wxObjectAllocatorAndCreator_5 : public wxObjectAllocatorAndCreator
288{
6c887dde 289 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
290 {
291 Class *obj = wx_dynamic_cast(Class*, o);
292 return obj->Create(
6c887dde
SC
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))
e1d3601a
PC
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
311template<typename Class,
312typename T0, typename T1, typename T2, typename T3, typename T4>
313struct wxDirectConstructorBridge_5 : public wxObjectAllocator
314{
6c887dde 315 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
316 {
317 o = new Class(
6c887dde
SC
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))
e1d3601a
PC
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
338template<typename Class,
339typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
340struct wxObjectAllocatorAndCreator_6 : public wxObjectAllocatorAndCreator
341{
6c887dde 342 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
343 {
344 Class *obj = wx_dynamic_cast(Class*, o);
345 return obj->Create(
6c887dde
SC
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))
e1d3601a
PC
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
365template<typename Class,
366typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
367struct wxDirectConstructorBridge_6 : public wxObjectAllocator
368{
6c887dde 369 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
370 {
371 o = new Class(
6c887dde
SC
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))
e1d3601a
PC
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
393template<typename Class,
394typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
395struct wxObjectAllocatorAndCreator_7 : public wxObjectAllocatorAndCreator
396{
6c887dde 397 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
398 {
399 Class *obj = wx_dynamic_cast(Class*, o);
400 return obj->Create(
6c887dde
SC
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))
e1d3601a
PC
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
421template<typename Class,
422typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
423struct wxDirectConstructorBridge_7 : public wxObjectAllocator
424{
6c887dde 425 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
426 {
427 o = new Class(
6c887dde
SC
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))
e1d3601a
PC
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
450template<typename Class,
451typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, \
452typename T6, typename T7>
453struct wxObjectAllocatorAndCreator_8 : public wxObjectAllocatorAndCreator
454{
6c887dde 455 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
456 {
457 Class *obj = wx_dynamic_cast(Class*, o);
458 return obj->Create(
6c887dde
SC
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))
e1d3601a
PC
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
480template<typename Class,
481typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, \
482typename T6, typename T7>
483struct wxDirectConstructorBridge_8 : public wxObjectAllocator
484{
6c887dde 485 bool Create(wxObject * &o, wxAny *args)
e1d3601a
PC
486 {
487 o = new Class(
6c887dde
SC
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))
e1d3601a
PC
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_