]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
derive wxConfig classes from wxObject and add wxRTTI macros to them (patch 1587607)
[wxWidgets.git] / include / wx / object.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
b2edef6f 2// Name: wx/object.h
c801d85f
KB
3// Purpose: wxObject class, plus run-time type information macros
4// Author: Julian Smart
0b9ab0bd 5// Modified by: Ron Lee
c801d85f
KB
6// Created: 01/02/97
7// RCS-ID: $Id$
371a5b4e 8// Copyright: (c) 1997 Julian Smart
0b9ab0bd 9// (c) 2001 Ron Lee <ron@debian.org>
65571936 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
34138703
JS
13#ifndef _WX_OBJECTH__
14#define _WX_OBJECTH__
c801d85f 15
0b9ab0bd
RL
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e55ad60e 20#include "wx/memory.h"
c801d85f 21
bddd7a8d 22class WXDLLIMPEXP_BASE wxObject;
c801d85f 23
4393b50c 24#ifndef wxUSE_EXTENDED_RTTI
6d553b5f 25#define wxUSE_EXTENDED_RTTI 0
a095505c
SC
26#endif
27
6d553b5f 28#if wxUSE_EXTENDED_RTTI
a095505c 29#include "wx/xti.h"
a095505c
SC
30#else
31
0b9ab0bd
RL
32// ----------------------------------------------------------------------------
33// conditional compilation
34// ----------------------------------------------------------------------------
35
bddd7a8d
VZ
36class WXDLLIMPEXP_BASE wxClassInfo;
37class WXDLLIMPEXP_BASE wxHashTable;
38class WXDLLIMPEXP_BASE wxObjectRefData;
c801d85f 39
0b9ab0bd
RL
40// ----------------------------------------------------------------------------
41// wxClassInfo
42// ----------------------------------------------------------------------------
43
44typedef wxObject *(*wxObjectConstructorFn)(void);
c801d85f 45
bddd7a8d 46class WXDLLIMPEXP_BASE wxClassInfo
c801d85f 47{
aac65598 48public:
38befbee 49 wxClassInfo( const wxChar *className,
d1d738f1
VS
50 const wxClassInfo *baseInfo1,
51 const wxClassInfo *baseInfo2,
38befbee
RL
52 int size,
53 wxObjectConstructorFn ctor )
0b9ab0bd 54 : m_className(className)
0b9ab0bd
RL
55 , m_objectSize(size)
56 , m_objectConstructor(ctor)
d1d738f1
VS
57 , m_baseInfo1(baseInfo1)
58 , m_baseInfo2(baseInfo2)
0b9ab0bd 59 , m_next(sm_first)
7e548f6b 60 {
d1d738f1
VS
61 sm_first = this;
62 Register();
63 }
0b9ab0bd 64
aa4b7ef9 65 ~wxClassInfo();
1d2eddff 66
4e124582
VZ
67 wxObject *CreateObject() const
68 { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
0c06c983 69 bool IsDynamic() const { return (NULL != m_objectConstructor); }
0b9ab0bd
RL
70
71 const wxChar *GetClassName() const { return m_className; }
469349b5
MB
72 const wxChar *GetBaseClassName1() const
73 { return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; }
74 const wxChar *GetBaseClassName2() const
75 { return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; }
0b9ab0bd
RL
76 const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
77 const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
78 int GetSize() const { return m_objectSize; }
79
4e124582
VZ
80 wxObjectConstructorFn GetConstructor() const
81 { return m_objectConstructor; }
0b9ab0bd
RL
82 static const wxClassInfo *GetFirst() { return sm_first; }
83 const wxClassInfo *GetNext() const { return m_next; }
84 static wxClassInfo *FindClass(const wxChar *className);
807d8487 85
0b9ab0bd
RL
86 // Climb upwards through inheritance hierarchy.
87 // Dual inheritance is catered for.
88
89 bool IsKindOf(const wxClassInfo *info) const
90 {
91 return info != 0 &&
92 ( info == this ||
93 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
94 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
95 }
3f4a0c5b 96
0c32066b 97public:
0b9ab0bd 98 const wxChar *m_className;
0b9ab0bd
RL
99 int m_objectSize;
100 wxObjectConstructorFn m_objectConstructor;
101
102 // Pointers to base wxClassInfos: set in InitializeClasses
103
104 const wxClassInfo *m_baseInfo1;
105 const wxClassInfo *m_baseInfo2;
106
107 // class info object live in a linked list:
108 // pointers to its head and the next element in it
109
110 static wxClassInfo *sm_first;
111 wxClassInfo *m_next;
112
1f428942
VZ
113 // FIXME: this should be private (currently used directly by way too
114 // many clients)
0b9ab0bd 115 static wxHashTable *sm_classTable;
1f428942
VZ
116
117private:
118 // InitializeClasses() helper
119 static wxClassInfo *GetBaseByName(const wxChar *name);
684242c6
GD
120
121 DECLARE_NO_COPY_CLASS(wxClassInfo)
7e548f6b
WS
122
123protected:
d1d738f1
VS
124 // registers the class
125 void Register();
126 void Unregister();
c801d85f
KB
127};
128
bddd7a8d 129WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
c801d85f 130
0b9ab0bd
RL
131// ----------------------------------------------------------------------------
132// Dynamic class macros
133// ----------------------------------------------------------------------------
134
14ca93a0
VZ
135#define DECLARE_ABSTRACT_CLASS(name) \
136 public: \
137 static wxClassInfo ms_classInfo; \
138 virtual wxClassInfo *GetClassInfo() const;
139
140#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \
141 DECLARE_NO_ASSIGN_CLASS(name) \
fc7a2a60
VZ
142 DECLARE_DYNAMIC_CLASS(name)
143
14ca93a0
VZ
144#define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \
145 DECLARE_NO_COPY_CLASS(name) \
fc7a2a60
VZ
146 DECLARE_DYNAMIC_CLASS(name)
147
14ca93a0
VZ
148#define DECLARE_DYNAMIC_CLASS(name) \
149 DECLARE_ABSTRACT_CLASS(name) \
150 static wxObject* wxCreateObject();
151
c801d85f
KB
152#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
153
14ca93a0
VZ
154
155// common part of the macros below
156#define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \
157 wxClassInfo name::ms_classInfo(wxT(#name), \
158 &basename::ms_classInfo, \
159 baseclsinfo2, \
160 (int) sizeof(name), \
161 (wxObjectConstructorFn) func); \
162 \
163 wxClassInfo *name::GetClassInfo() const \
164 { return &name::ms_classInfo; }
165
166#define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \
167 wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func)
168
169#define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \
2b199a38 170 wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
14ca93a0 171
0b9ab0bd
RL
172// -----------------------------------
173// for concrete classes
174// -----------------------------------
175
176 // Single inheritance with one base class
14ca93a0
VZ
177#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
178 wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \
179 wxObject* name::wxCreateObject() \
180 { return new name; }
c801d85f 181
0b9ab0bd 182 // Multiple inheritance with two base classes
14ca93a0
VZ
183#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
184 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \
185 name::wxCreateObject) \
186 wxObject* name::wxCreateObject() \
187 { return new name; }
c801d85f 188
0b9ab0bd
RL
189// -----------------------------------
190// for abstract classes
191// -----------------------------------
c801d85f 192
0b9ab0bd
RL
193 // Single inheritance with one base class
194
14ca93a0
VZ
195#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
196 wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL)
0b9ab0bd
RL
197
198 // Multiple inheritance with two base classes
199
14ca93a0
VZ
200#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
201 wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL)
c801d85f
KB
202
203#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
204#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
205
6d553b5f 206#endif // !wxUSE_EXTENDED_RTTI
a095505c
SC
207
208
0b9ab0bd
RL
209// -----------------------------------
210// for pluggable classes
211// -----------------------------------
212
213 // NOTE: this should probably be the very first statement
214 // in the class declaration so wxPluginSentinel is
215 // the first member initialised and the last destroyed.
216
217// _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
218
219#if wxUSE_NESTED_CLASSES
220
60b73526
RL
221#define _DECLARE_DL_SENTINEL(name, exportdecl) \
222class exportdecl name##PluginSentinel { \
223private: \
224 static const wxString sm_className; \
225public: \
226 name##PluginSentinel(); \
2e0b1b11 227 ~name##PluginSentinel(); \
60b73526 228}; \
0b9ab0bd 229name##PluginSentinel m_pluginsentinel;
0b9ab0bd
RL
230
231#define _IMPLEMENT_DL_SENTINEL(name) \
232 const wxString name::name##PluginSentinel::sm_className(#name); \
233 name::name##PluginSentinel::name##PluginSentinel() { \
4f89dbc4 234 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 235 if( e != 0 ) { e->RefObj(); } \
0b9ab0bd 236 } \
abad5367 237 name::name##PluginSentinel::~name##PluginSentinel() { \
4f89dbc4 238 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 239 if( e != 0 ) { e->UnrefObj(); } \
0b9ab0bd
RL
240 }
241#else
242
243#define _DECLARE_DL_SENTINEL(name)
244#define _IMPLEMENT_DL_SENTINEL(name)
245
246#endif // wxUSE_NESTED_CLASSES
247
248#define DECLARE_PLUGGABLE_CLASS(name) \
60b73526 249 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
0b9ab0bd 250#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
60b73526
RL
251 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
252
253#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
254 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
255#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
256 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
0b9ab0bd
RL
257
258#define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \
259 IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
260#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
261 IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
0b9ab0bd
RL
262#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
263 IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
264#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
265 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
266
60b73526
RL
267#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
268 IMPLEMENT_PLUGGABLE_CLASS(name, basename)
269#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
270 IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
271#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
272 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
273#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
274 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
275
c0db9626 276#define CLASSINFO(name) (&name::ms_classInfo)
c801d85f 277
c0db9626 278#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo)
3013b6f4 279
b2edef6f 280// Just seems a bit nicer-looking (pretend it's not a macro)
c0db9626 281#define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo)
c801d85f 282
73fbb031
VZ
283// this cast does some more checks at compile time as it uses static_cast
284// internally
285//
286// note that it still has different semantics from dynamic_cast<> and so can't
287// be replaced by it as long as there are any compilers not supporting it
34636400 288#define wxDynamicCast(obj, className) \
5232d996
VZ
289 ((className *) wxCheckDynamicCast( \
290 wx_const_cast(wxObject *, wx_static_cast(const wxObject *, \
291 wx_const_cast(className *, wx_static_cast(const className *, obj)))), \
292 &className::ms_classInfo))
0b9ab0bd 293
b2edef6f
VZ
294// The 'this' pointer is always true, so use this version
295// to cast the this pointer and avoid compiler warnings.
f7637829 296#define wxDynamicCastThis(className) \
73fbb031 297 (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0)
33ac7e6f 298
f6bcfd97 299#ifdef __WXDEBUG__
e32d4836 300inline void* wxCheckCast(void *ptr)
0b9ab0bd
RL
301{
302 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
e32d4836 303 return ptr;
0b9ab0bd
RL
304}
305#define wxStaticCast(obj, className) \
e32d4836 306 ((className *)wxCheckCast(wxDynamicCast(obj, className)))
f6bcfd97 307
0b9ab0bd 308#else // !__WXDEBUG__
ef0aea5a
VZ
309#define wxStaticCast(obj, className) \
310 wx_const_cast(className *, wx_static_cast(const className *, obj))
f6bcfd97 311
0b9ab0bd 312#endif // __WXDEBUG__
f6bcfd97 313
b2edef6f
VZ
314// ----------------------------------------------------------------------------
315// set up memory debugging macros
316// ----------------------------------------------------------------------------
317
318/*
319 Which new/delete operator variants do we want?
320
321 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
322 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
323 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
324 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
325 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
326 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
327 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
328*/
329
330#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
331
332// All compilers get this one
333#define _WX_WANT_NEW_SIZET_WXCHAR_INT
334
335// Everyone except Visage gets the next one
336#ifndef __VISAGECPP__
337 #define _WX_WANT_DELETE_VOID
c801d85f 338#endif
b2edef6f
VZ
339
340// Only visage gets this one under the correct circumstances
341#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
342 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
343#endif
344
4e124582
VZ
345// Only VC++ 6 and CodeWarrior get overloaded delete that matches new
346#if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \
347 (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 348 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 349#endif
c801d85f 350
b2edef6f
VZ
351// Now see who (if anyone) gets the array memory operators
352#if wxUSE_ARRAY_MEMORY_OPERATORS
353
354 // Everyone except Visual C++ (cause problems for VC++ - crashes)
355 #if !defined(__VISUALC__)
356 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
357 #endif
358
359 // Everyone except Visual C++ (cause problems for VC++ - crashes)
360 #if !defined(__VISUALC__)
361 #define _WX_WANT_ARRAY_DELETE_VOID
362 #endif
363
364 // Only CodeWarrior 6 or higher
365 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
366 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
367 #endif
368
369#endif // wxUSE_ARRAY_MEMORY_OPERATORS
370
e755eb67 371#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
b2edef6f 372
f8855e47
VZ
373// ----------------------------------------------------------------------------
374// wxObjectRefData: ref counted data meant to be stored in wxObject
375// ----------------------------------------------------------------------------
376
377class WXDLLIMPEXP_BASE wxObjectRefData
378{
379 friend class WXDLLIMPEXP_BASE wxObject;
380
381public:
382 wxObjectRefData() : m_count(1) { }
f8855e47
VZ
383
384 int GetRefCount() const { return m_count; }
385
4a11340a
RR
386 void IncRef() { m_count++; }
387 void DecRef();
388
389protected:
390 // this object should never be destroyed directly but only as a
391 // result of a DecRef() call:
392 virtual ~wxObjectRefData() { }
393
f8855e47 394private:
4a11340a 395 // our refcount:
f8855e47
VZ
396 int m_count;
397};
398
4a11340a
RR
399// ----------------------------------------------------------------------------
400// wxObjectDataPtr: helper class to avoid memleaks because of missing calls
401// to wxObjectRefData::DecRef
402// ----------------------------------------------------------------------------
403
404template <class T>
405class wxObjectDataPtr
406{
407public:
408 typedef T element_type;
409
410 wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {}
411
412 // copy ctor
413 wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy)
414 : m_ptr(tocopy.m_ptr)
415 {
416 if (m_ptr)
417 m_ptr->IncRef();
418 }
419
420 ~wxObjectDataPtr()
421 {
422 if (m_ptr)
423 m_ptr->DecRef();
424 }
425
426 T *get() const { return m_ptr; }
427 T *operator->() const { return get(); }
428
429 void reset(T *ptr)
430 {
431 if (m_ptr)
432 m_ptr->DecRef();
433 m_ptr = ptr;
434 }
435
436 wxObjectDataPtr& operator=(const wxObjectDataPtr &tocopy)
437 {
438 if (m_ptr)
439 m_ptr->DecRef();
440 m_ptr = tocopy.m_ptr;
441 if (m_ptr)
442 m_ptr->IncRef();
443 return *this;
444 }
445
446 wxObjectDataPtr& operator=(T *ptr)
447 {
448 if (m_ptr)
449 m_ptr->DecRef();
450 m_ptr = ptr;
451 if (m_ptr)
452 m_ptr->IncRef();
453 return *this;
454 }
455
456private:
457 T *m_ptr;
458};
459
0b9ab0bd 460// ----------------------------------------------------------------------------
77ffb593 461// wxObject: the root class of wxWidgets object hierarchy
0b9ab0bd
RL
462// ----------------------------------------------------------------------------
463
bddd7a8d 464class WXDLLIMPEXP_BASE wxObject
c801d85f 465{
684242c6 466 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 467
0b9ab0bd 468public:
b2edef6f 469 wxObject() { m_refData = NULL; }
0b9ab0bd 470 virtual ~wxObject() { UnRef(); }
4393b50c 471
a6391d30 472 wxObject(const wxObject& other)
66e9a9f0 473 {
f8855e47
VZ
474 m_refData = other.m_refData;
475 if (m_refData)
476 m_refData->m_count++;
66e9a9f0 477 }
4393b50c 478
a6391d30
GD
479 wxObject& operator=(const wxObject& other)
480 {
481 if ( this != &other )
482 {
f8855e47 483 Ref(other);
a6391d30
GD
484 }
485 return *this;
486 }
487
0b9ab0bd 488 bool IsKindOf(wxClassInfo *info) const;
c801d85f 489
0b9ab0bd 490
b2edef6f
VZ
491 // Turn on the correct set of new and delete operators
492
493#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 494 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 495#endif
27198be4 496
b2edef6f
VZ
497#ifdef _WX_WANT_DELETE_VOID
498 void operator delete ( void * buf );
499#endif
0b9ab0bd 500
b2edef6f
VZ
501#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
502 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 503#endif
76626af2 504
b2edef6f 505#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 506 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 507#endif
8cfc5426 508
b2edef6f 509#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 510 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
511#endif
512
b2edef6f
VZ
513#ifdef _WX_WANT_ARRAY_DELETE_VOID
514 void operator delete[] ( void *buf );
0b9ab0bd 515#endif
27198be4 516
b2edef6f 517#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 518 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 519#endif
c801d85f 520
807d8487
VZ
521 // ref counted data handling methods
522
523 // get/set
524 wxObjectRefData *GetRefData() const { return m_refData; }
525 void SetRefData(wxObjectRefData *data) { m_refData = data; }
526
527 // make a 'clone' of the object
0b9ab0bd 528 void Ref(const wxObject& clone);
c801d85f 529
807d8487 530 // destroy a reference
0b9ab0bd 531 void UnRef();
c801d85f 532
93c5f755
PC
533 // Make sure this object has only one reference
534 void UnShare() { AllocExclusive(); }
535
a3ab1c18
VZ
536 // check if this object references the same data as the other one
537 bool IsSameAs(const wxObject& o) const { return m_refData == o.m_refData; }
55ccdb93 538
c801d85f 539protected:
807d8487
VZ
540 // ensure that our data is not shared with anybody else: if we have no
541 // data, it is created using CreateRefData() below, if we have shared data
542 // it is copied using CloneRefData(), otherwise nothing is done
543 void AllocExclusive();
544
4e124582
VZ
545 // both methods must be implemented if AllocExclusive() is used, not pure
546 // virtual only because of the backwards compatibility reasons
807d8487
VZ
547
548 // create a new m_refData
549 virtual wxObjectRefData *CreateRefData() const;
550
551 // create a new m_refData initialized with the given one
b8027888 552 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 553
0b9ab0bd 554 wxObjectRefData *m_refData;
c801d85f
KB
555};
556
ea1e6c4b
RL
557inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
558{
b2edef6f 559 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
560}
561
2d51f067
SC
562#if wxUSE_EXTENDED_RTTI
563class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
564{
8f2b1cfd 565 friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
2d51f067
SC
566public:
567 // instantiates this object with an instance of its superclass
568 wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
d3c7fc99 569 virtual ~wxDynamicObject();
2d51f067 570
8f2b1cfd
SC
571 void SetProperty (const wxChar *propertyName, const wxxVariant &value);
572 wxxVariant GetProperty (const wxChar *propertyName) const ;
2d51f067
SC
573
574 // get the runtime identity of this object
575 wxClassInfo *GetClassInfo() const
576 {
f525dc35
JS
577#ifdef _MSC_VER
578 return (wxClassInfo*) m_classInfo;
579#else
4a11340a
RR
580 wxDynamicClassInfo *nonconst = wx_const_cast(wxDynamicClassInfo *, m_classInfo);
581 return wx_static_cast(wxClassInfo *, nonconst);
f525dc35 582#endif
2d51f067
SC
583 }
584
585 wxObject* GetSuperClassInstance() const
586 {
587 return m_superClassInstance ;
588 }
589private :
8f2b1cfd
SC
590 // removes an existing runtime-property
591 void RemoveProperty( const wxChar *propertyName ) ;
592
593 // renames an existing runtime-property
594 void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
595
2d51f067
SC
596 wxObject *m_superClassInstance ;
597 const wxDynamicClassInfo *m_classInfo;
598 struct wxDynamicObjectInternal;
599 wxDynamicObjectInternal *m_data;
600};
601#endif
602
b2edef6f
VZ
603// ----------------------------------------------------------------------------
604// more debugging macros
605// ----------------------------------------------------------------------------
606
b2edef6f
VZ
607// Redefine new to be the debugging version. This doesn't work with all
608// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
609// to use the debugging version.
7fe7d506 610
70bf6180
VZ
611#ifdef __WXDEBUG__
612 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
613
614 #if wxUSE_DEBUG_NEW_ALWAYS
615 #if wxUSE_GLOBAL_MEMORY_OPERATORS
616 #define new WXDEBUG_NEW
617 #elif defined(__VISUALC__)
618 // Including this file redefines new and allows leak reports to
619 // contain line numbers
620 #include "wx/msw/msvcrt.h"
621 #endif
622 #endif // wxUSE_DEBUG_NEW_ALWAYS
623#else // !__WXDEBUG__
624 #define WXDEBUG_NEW new
625#endif // __WXDEBUG__/!__WXDEBUG__
c801d85f 626
c0089c96 627#endif // _WX_OBJECTH__