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