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