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