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