]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
fixed GL case in #include (patch 557178)
[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$
0b9ab0bd
RL
8// Copyright: (c) 1997 Julian Smart and Markus Holzem
9// (c) 2001 Ron Lee <ron@debian.org>
3f4a0c5b 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
34138703
JS
13#ifndef _WX_OBJECTH__
14#define _WX_OBJECTH__
c801d85f
KB
15
16#ifdef __GNUG__
0d3820b3 17#pragma interface "object.h"
c801d85f
KB
18#endif
19
0b9ab0bd
RL
20// ----------------------------------------------------------------------------
21// headers
22// ----------------------------------------------------------------------------
23
c801d85f 24#include "wx/defs.h"
e55ad60e 25#include "wx/memory.h"
c801d85f
KB
26
27class WXDLLEXPORT wxObject;
28
47d67540 29#if wxUSE_DYNAMIC_CLASSES
c801d85f 30
0b9ab0bd
RL
31// ----------------------------------------------------------------------------
32// conditional compilation
33// ----------------------------------------------------------------------------
34
b2edef6f
VZ
35// this shouldn't be needed any longer as <wx/msw/private.h> does it but it
36// doesn't hurt neither
c801d85f
KB
37#ifdef GetClassName
38#undef GetClassName
39#endif
3f1af920
JS
40#ifdef GetClassInfo
41#undef GetClassInfo
c801d85f
KB
42#endif
43
44class WXDLLEXPORT wxClassInfo;
f4a8c29f 45class WXDLLEXPORT wxHashTable;
b2edef6f 46class WXDLLEXPORT wxObjectRefData;
c801d85f 47
38830220 48#if wxUSE_STD_IOSTREAM && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT)
b2edef6f 49 #include "wx/ioswrap.h"
fbc535ff
JS
50#endif
51
c801d85f 52
0b9ab0bd
RL
53// ----------------------------------------------------------------------------
54// wxClassInfo
55// ----------------------------------------------------------------------------
56
57typedef wxObject *(*wxObjectConstructorFn)(void);
c801d85f 58
c801d85f
KB
59class WXDLLEXPORT wxClassInfo
60{
aac65598 61public:
38befbee
RL
62 wxClassInfo( const wxChar *className,
63 const wxChar *baseName1,
64 const wxChar *baseName2,
65 int size,
66 wxObjectConstructorFn ctor )
0b9ab0bd
RL
67 : m_className(className)
68 , m_baseClassName1(baseName1)
69 , m_baseClassName2(baseName2)
70 , m_objectSize(size)
71 , m_objectConstructor(ctor)
72 , m_baseInfo1(0)
73 , m_baseInfo2(0)
74 , m_next(sm_first)
6d1b9112 75 { sm_first = this; }
0b9ab0bd
RL
76
77 wxObject *CreateObject() { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
78
79 const wxChar *GetClassName() const { return m_className; }
80 const wxChar *GetBaseClassName1() const { return m_baseClassName1; }
81 const wxChar *GetBaseClassName2() const { return m_baseClassName2; }
82 const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
83 const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
84 int GetSize() const { return m_objectSize; }
85
86 wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
87 static const wxClassInfo *GetFirst() { return sm_first; }
88 const wxClassInfo *GetNext() const { return m_next; }
89 static wxClassInfo *FindClass(const wxChar *className);
807d8487 90
0b9ab0bd
RL
91 // Climb upwards through inheritance hierarchy.
92 // Dual inheritance is catered for.
93
94 bool IsKindOf(const wxClassInfo *info) const
95 {
96 return info != 0 &&
97 ( info == this ||
98 ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) ||
99 ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
100 }
3f4a0c5b 101
0b9ab0bd 102 // Initializes parent pointers and hash table for fast searching.
c801d85f 103
0b9ab0bd 104 static void InitializeClasses();
0c32066b 105
0b9ab0bd 106 // Cleans up hash table used for fast searching.
0c32066b 107
0b9ab0bd 108 static void CleanUpClasses();
0c32066b
JS
109
110public:
0b9ab0bd
RL
111 const wxChar *m_className;
112 const wxChar *m_baseClassName1;
113 const wxChar *m_baseClassName2;
114 int m_objectSize;
115 wxObjectConstructorFn m_objectConstructor;
116
117 // Pointers to base wxClassInfos: set in InitializeClasses
118
119 const wxClassInfo *m_baseInfo1;
120 const wxClassInfo *m_baseInfo2;
121
122 // class info object live in a linked list:
123 // pointers to its head and the next element in it
124
125 static wxClassInfo *sm_first;
126 wxClassInfo *m_next;
127
1f428942
VZ
128 // FIXME: this should be private (currently used directly by way too
129 // many clients)
0b9ab0bd 130 static wxHashTable *sm_classTable;
1f428942
VZ
131
132private:
133 // InitializeClasses() helper
134 static wxClassInfo *GetBaseByName(const wxChar *name);
684242c6
GD
135
136 DECLARE_NO_COPY_CLASS(wxClassInfo)
c801d85f
KB
137};
138
0b9ab0bd 139WXDLLEXPORT wxObject *wxCreateDynamicObject(const wxChar *name);
c801d85f 140
0b9ab0bd
RL
141// ----------------------------------------------------------------------------
142// Dynamic class macros
143// ----------------------------------------------------------------------------
144
145#define DECLARE_DYNAMIC_CLASS(name) \
146 public: \
147 static wxClassInfo sm_class##name; \
148 virtual wxClassInfo *GetClassInfo() const \
0c32066b 149 { return &name::sm_class##name; }
c801d85f
KB
150
151#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
152#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
153
0b9ab0bd
RL
154// -----------------------------------
155// for concrete classes
156// -----------------------------------
157
158 // Single inheritance with one base class
c801d85f 159
0b9ab0bd
RL
160#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
161 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name() \
162 { return new name; } \
163 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
164 0, (int) sizeof(name), \
165 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 166
0b9ab0bd 167 // Multiple inheritance with two base classes
c801d85f 168
0b9ab0bd
RL
169#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
170 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name() \
171 { return new name; } \
172 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
173 wxT(#basename2), (int) sizeof(name), \
174 (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 175
0b9ab0bd
RL
176// -----------------------------------
177// for abstract classes
178// -----------------------------------
c801d85f 179
0b9ab0bd
RL
180 // Single inheritance with one base class
181
182#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
183 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
184 0, (int) sizeof(name), (wxObjectConstructorFn) 0);
185
186 // Multiple inheritance with two base classes
187
188#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
189 wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
190 wxT(#basename2), (int) sizeof(name), \
191 (wxObjectConstructorFn) 0);
c801d85f
KB
192
193#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
194#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
195
0b9ab0bd
RL
196// -----------------------------------
197// for pluggable classes
198// -----------------------------------
199
200 // NOTE: this should probably be the very first statement
201 // in the class declaration so wxPluginSentinel is
202 // the first member initialised and the last destroyed.
203
204// _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel;
205
206#if wxUSE_NESTED_CLASSES
207
60b73526
RL
208#define _DECLARE_DL_SENTINEL(name, exportdecl) \
209class exportdecl name##PluginSentinel { \
210private: \
211 static const wxString sm_className; \
212public: \
213 name##PluginSentinel(); \
2e0b1b11 214 ~name##PluginSentinel(); \
60b73526 215}; \
0b9ab0bd 216name##PluginSentinel m_pluginsentinel;
0b9ab0bd
RL
217
218#define _IMPLEMENT_DL_SENTINEL(name) \
219 const wxString name::name##PluginSentinel::sm_className(#name); \
220 name::name##PluginSentinel::name##PluginSentinel() { \
4f89dbc4 221 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 222 if( e != 0 ) { e->RefObj(); } \
0b9ab0bd 223 } \
abad5367 224 name::name##PluginSentinel::~name##PluginSentinel() { \
4f89dbc4 225 wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \
7c1e2b44 226 if( e != 0 ) { e->UnrefObj(); } \
0b9ab0bd
RL
227 }
228#else
229
230#define _DECLARE_DL_SENTINEL(name)
231#define _IMPLEMENT_DL_SENTINEL(name)
232
233#endif // wxUSE_NESTED_CLASSES
234
235#define DECLARE_PLUGGABLE_CLASS(name) \
60b73526 236 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
0b9ab0bd 237#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \
60b73526
RL
238 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT)
239
240#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \
241 DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
242#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \
243 DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo)
0b9ab0bd
RL
244
245#define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \
246 IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
247#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \
248 IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
0b9ab0bd
RL
249#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
250 IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name)
251#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
252 IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name)
253
60b73526
RL
254#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \
255 IMPLEMENT_PLUGGABLE_CLASS(name, basename)
256#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \
257 IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
258#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \
259 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
260#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \
261 IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
262
0b9ab0bd 263
0c32066b 264#define CLASSINFO(name) (&name::sm_class##name)
c801d85f 265
34636400 266#else // !wxUSE_DYNAMIC_CLASSES
c801d85f 267
0b9ab0bd
RL
268 // No dynamic class system: so stub out the macros
269
c801d85f
KB
270#define DECLARE_DYNAMIC_CLASS(name)
271#define DECLARE_ABSTRACT_CLASS(name)
272#define DECLARE_CLASS(name)
273#define IMPLEMENT_DYNAMIC_CLASS(name, basename)
274#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
275#define IMPLEMENT_ABSTRACT_CLASS(name, basename)
276#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
277#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
278#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
279
0b9ab0bd
RL
280#define DECLARE_PLUGGABLE_CLASS(name)
281#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name)
282#define IMPLEMENT_PLUGGABLE_CLASS(name, basename)
283#define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2)
284#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename)
285#define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
286
60b73526
RL
287#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo)
288#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo)
289#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename)
290#define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2)
291#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename)
292#define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2)
293
0b9ab0bd
RL
294#endif // wxUSE_DYNAMIC_CLASSES
295
c801d85f 296
3013b6f4
JS
297#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
298
b2edef6f 299// Just seems a bit nicer-looking (pretend it's not a macro)
3013b6f4 300#define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className)
c801d85f 301
b2edef6f 302// to be replaced by dynamic_cast<> in the future
34636400 303#define wxDynamicCast(obj, className) \
0b9ab0bd
RL
304 (className *) wxCheckDynamicCast((wxObject*)(obj), &className::sm_class##className)
305
b2edef6f
VZ
306// The 'this' pointer is always true, so use this version
307// to cast the this pointer and avoid compiler warnings.
f7637829 308#define wxDynamicCastThis(className) \
0b9ab0bd 309 (IsKindOf(&className::sm_class##className) ? (className *)(this) : (className *)0)
33ac7e6f 310
f6bcfd97
BP
311#define wxConstCast(obj, className) ((className *)(obj))
312
0b9ab0bd 313
f6bcfd97 314#ifdef __WXDEBUG__
0b9ab0bd
RL
315inline void wxCheckCast(void *ptr)
316{
317 wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") );
318}
319#define wxStaticCast(obj, className) \
320 (wxCheckCast(wxDynamicCast(obj, className)), ((className *)(obj)))
f6bcfd97 321
0b9ab0bd
RL
322#else // !__WXDEBUG__
323#define wxStaticCast(obj, className) ((className *)(obj))
f6bcfd97 324
0b9ab0bd 325#endif // __WXDEBUG__
f6bcfd97 326
0b9ab0bd 327
b2edef6f 328// for some reason Borland seems to need this include.
0b9ab0bd
RL
329#if wxUSE_STD_IOSTREAM \
330 && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT) \
331 && defined(__BORLANDC__)
b2edef6f
VZ
332 #if wxUSE_IOSTREAMH
333 #include <iostream.h>
334 #else
335 #include <iostream>
336 #endif
337#endif // wxUSE_IOSTREAMH
338
339// ----------------------------------------------------------------------------
340// set up memory debugging macros
341// ----------------------------------------------------------------------------
342
343/*
344 Which new/delete operator variants do we want?
345
346 _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0)
347 _WX_WANT_DELETE_VOID = void operator delete (void * buf)
348 _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line)
349 _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int)
350 _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0)
351 _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf)
352 _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int )
353*/
354
355#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
356
357// All compilers get this one
358#define _WX_WANT_NEW_SIZET_WXCHAR_INT
359
360// Everyone except Visage gets the next one
361#ifndef __VISAGECPP__
362 #define _WX_WANT_DELETE_VOID
c801d85f 363#endif
b2edef6f
VZ
364
365// Only visage gets this one under the correct circumstances
366#if defined(__VISAGECPP__) && __DEBUG_ALLOC__
367 #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
368#endif
369
370// Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new
684242c6 371#if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400))
b2edef6f 372 #define _WX_WANT_DELETE_VOID_WXCHAR_INT
fd85b064 373#endif
c801d85f 374
b2edef6f
VZ
375// Now see who (if anyone) gets the array memory operators
376#if wxUSE_ARRAY_MEMORY_OPERATORS
377
378 // Everyone except Visual C++ (cause problems for VC++ - crashes)
379 #if !defined(__VISUALC__)
380 #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
381 #endif
382
383 // Everyone except Visual C++ (cause problems for VC++ - crashes)
384 #if !defined(__VISUALC__)
385 #define _WX_WANT_ARRAY_DELETE_VOID
386 #endif
387
388 // Only CodeWarrior 6 or higher
389 #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
390 #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
391 #endif
392
393#endif // wxUSE_ARRAY_MEMORY_OPERATORS
394
395#endif // WXDEBUG && wxUSE_MEMORY_TRACING
396
0b9ab0bd
RL
397
398// ----------------------------------------------------------------------------
b2edef6f 399// wxObject: the root class of wxWindows object hierarchy
0b9ab0bd
RL
400// ----------------------------------------------------------------------------
401
c801d85f
KB
402class WXDLLEXPORT wxObject
403{
684242c6 404 DECLARE_ABSTRACT_CLASS(wxObject)
c801d85f 405
a6391d30
GD
406private:
407 void InitFrom(const wxObject& other);
408
0b9ab0bd 409public:
b2edef6f 410 wxObject() { m_refData = NULL; }
0b9ab0bd 411 virtual ~wxObject() { UnRef(); }
684242c6 412
a6391d30
GD
413 wxObject(const wxObject& other)
414 {
415 InitFrom(other);
416 }
417
418 wxObject& operator=(const wxObject& other)
419 {
420 if ( this != &other )
421 {
422 UnRef();
423 InitFrom(other);
424 }
425 return *this;
426 }
427
0b9ab0bd 428 bool IsKindOf(wxClassInfo *info) const;
c801d85f 429
0b9ab0bd 430
b2edef6f
VZ
431 // Turn on the correct set of new and delete operators
432
433#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
cf760e4c 434 void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd 435#endif
27198be4 436
b2edef6f
VZ
437#ifdef _WX_WANT_DELETE_VOID
438 void operator delete ( void * buf );
439#endif
0b9ab0bd 440
b2edef6f
VZ
441#ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET
442 void operator delete ( void *buf, const char *_fname, size_t _line );
0b9ab0bd 443#endif
76626af2 444
b2edef6f 445#ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT
cf760e4c 446 void operator delete ( void *buf, const wxChar*, int );
b2edef6f 447#endif
8cfc5426 448
b2edef6f 449#ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT
cf760e4c 450 void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 );
0b9ab0bd
RL
451#endif
452
b2edef6f
VZ
453#ifdef _WX_WANT_ARRAY_DELETE_VOID
454 void operator delete[] ( void *buf );
0b9ab0bd 455#endif
27198be4 456
b2edef6f 457#ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT
cf760e4c 458 void operator delete[] (void* buf, const wxChar*, int );
b2edef6f 459#endif
c801d85f 460
c801d85f 461
0b9ab0bd
RL
462#if wxUSE_STD_IOSTREAM && (defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT)
463 virtual void Dump(wxSTD ostream& str);
c801d85f
KB
464#endif
465
807d8487
VZ
466 // ref counted data handling methods
467
468 // get/set
469 wxObjectRefData *GetRefData() const { return m_refData; }
470 void SetRefData(wxObjectRefData *data) { m_refData = data; }
471
472 // make a 'clone' of the object
0b9ab0bd 473 void Ref(const wxObject& clone);
c801d85f 474
807d8487 475 // destroy a reference
0b9ab0bd 476 void UnRef();
c801d85f 477
c801d85f 478protected:
807d8487
VZ
479 // ensure that our data is not shared with anybody else: if we have no
480 // data, it is created using CreateRefData() below, if we have shared data
481 // it is copied using CloneRefData(), otherwise nothing is done
482 void AllocExclusive();
483
484 // both methods must be implemented if Unshare() is used, not pure virtual
485 // only because of the backwards compatibility reasons
486
487 // create a new m_refData
488 virtual wxObjectRefData *CreateRefData() const;
489
490 // create a new m_refData initialized with the given one
b8027888 491 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
807d8487 492
0b9ab0bd 493 wxObjectRefData *m_refData;
c801d85f
KB
494};
495
b2edef6f
VZ
496// ----------------------------------------------------------------------------
497// wxObjectRefData: ref counted data meant to be stored in wxObject
498// ----------------------------------------------------------------------------
c801d85f 499
0b9ab0bd
RL
500class WXDLLEXPORT wxObjectRefData
501{
c801d85f
KB
502 friend class wxObject;
503
504public:
b2edef6f
VZ
505 wxObjectRefData() : m_count(1) { }
506 virtual ~wxObjectRefData() { }
507
508 int GetRefCount() const { return m_count; }
c801d85f 509
c801d85f
KB
510private:
511 int m_count;
512};
513
0b9ab0bd 514
ea1e6c4b
RL
515inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo)
516{
b2edef6f 517 return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL;
ea1e6c4b
RL
518}
519
b2edef6f
VZ
520// ----------------------------------------------------------------------------
521// more debugging macros
522// ----------------------------------------------------------------------------
523
7fe7d506 524#ifdef __WXDEBUG__
b2edef6f
VZ
525 #ifndef WXDEBUG_NEW
526 #define WXDEBUG_NEW new(__TFILE__,__LINE__)
527 #endif
528#else // !__WXDEBUG__
529 #define WXDEBUG_NEW new
7fe7d506
JS
530#endif
531
b2edef6f
VZ
532// Redefine new to be the debugging version. This doesn't work with all
533// compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish
534// to use the debugging version.
7fe7d506
JS
535
536#if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
b2edef6f 537 #define new new(__TFILE__,__LINE__)
c801d85f
KB
538#endif
539
0b9ab0bd 540#endif // _WX_OBJECTH__
c801d85f 541