]>
Commit | Line | Data |
---|---|---|
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 | |
f06d6937 SC |
22 | #define wxDECLARE_CLASS_INFO_ITERATORS() \ |
23 | class WXDLLIMPEXP_BASE const_iterator \ | |
24 | { \ | |
25 | typedef wxHashTable_Node Node; \ | |
26 | public: \ | |
27 | typedef const wxClassInfo* value_type; \ | |
28 | typedef const value_type& const_reference; \ | |
29 | typedef const_iterator itor; \ | |
30 | typedef value_type* ptr_type; \ | |
31 | \ | |
32 | Node* m_node; \ | |
33 | wxHashTable* m_table; \ | |
34 | public: \ | |
35 | typedef const_reference reference_type; \ | |
36 | typedef ptr_type pointer_type; \ | |
37 | \ | |
38 | const_iterator(Node* node, wxHashTable* table) \ | |
39 | : m_node(node), m_table(table) { } \ | |
40 | const_iterator() : m_node(NULL), m_table(NULL) { } \ | |
41 | value_type operator*() const; \ | |
42 | itor& operator++(); \ | |
43 | const itor operator++(int); \ | |
44 | bool operator!=(const itor& it) const \ | |
45 | { return it.m_node != m_node; } \ | |
46 | bool operator==(const itor& it) const \ | |
47 | { return it.m_node == m_node; } \ | |
48 | }; \ | |
49 | \ | |
50 | static const_iterator begin_classinfo(); \ | |
51 | static const_iterator end_classinfo() | |
52 | ||
28953245 SC |
53 | // based on the value of wxUSE_EXTENDED_RTTI symbol, |
54 | // only one of the RTTI system will be compiled: | |
55 | // - the "old" one (defined by rtti.h) or | |
56 | // - the "new" one (defined by xti.h) | |
a095505c | 57 | #include "wx/xti.h" |
28953245 | 58 | #include "wx/rtti.h" |
a095505c | 59 | |
cbca59a8 SC |
60 | #define wxIMPLEMENT_CLASS(name, basename) \ |
61 | wxIMPLEMENT_ABSTRACT_CLASS(name, basename) | |
62 | ||
63 | #define wxIMPLEMENT_CLASS2(name, basename1, basename2) \ | |
64 | wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) | |
65 | ||
0b9ab0bd RL |
66 | // ----------------------------------- |
67 | // for pluggable classes | |
68 | // ----------------------------------- | |
69 | ||
70 | // NOTE: this should probably be the very first statement | |
71 | // in the class declaration so wxPluginSentinel is | |
72 | // the first member initialised and the last destroyed. | |
73 | ||
74 | // _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel; | |
75 | ||
76 | #if wxUSE_NESTED_CLASSES | |
77 | ||
60b73526 RL |
78 | #define _DECLARE_DL_SENTINEL(name, exportdecl) \ |
79 | class exportdecl name##PluginSentinel { \ | |
80 | private: \ | |
81 | static const wxString sm_className; \ | |
82 | public: \ | |
83 | name##PluginSentinel(); \ | |
2e0b1b11 | 84 | ~name##PluginSentinel(); \ |
60b73526 | 85 | }; \ |
b19b28c8 | 86 | name##PluginSentinel m_pluginsentinel |
0b9ab0bd RL |
87 | |
88 | #define _IMPLEMENT_DL_SENTINEL(name) \ | |
89 | const wxString name::name##PluginSentinel::sm_className(#name); \ | |
90 | name::name##PluginSentinel::name##PluginSentinel() { \ | |
4f89dbc4 | 91 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ |
7c1e2b44 | 92 | if( e != 0 ) { e->RefObj(); } \ |
0b9ab0bd | 93 | } \ |
abad5367 | 94 | name::name##PluginSentinel::~name##PluginSentinel() { \ |
4f89dbc4 | 95 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ |
7c1e2b44 | 96 | if( e != 0 ) { e->UnrefObj(); } \ |
0b9ab0bd RL |
97 | } |
98 | #else | |
99 | ||
100 | #define _DECLARE_DL_SENTINEL(name) | |
101 | #define _IMPLEMENT_DL_SENTINEL(name) | |
102 | ||
103 | #endif // wxUSE_NESTED_CLASSES | |
104 | ||
b19b28c8 FM |
105 | #define wxDECLARE_PLUGGABLE_CLASS(name) \ |
106 | wxDECLARE_DYNAMIC_CLASS(name); _DECLARE_DL_SENTINEL(name, WXDLLIMPEXP_CORE) | |
107 | #define wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \ | |
108 | wxDECLARE_ABSTRACT_CLASS(name); _DECLARE_DL_SENTINEL(name, WXDLLIMPEXP_CORE) | |
109 | ||
110 | #define wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \ | |
111 | wxDECLARE_DYNAMIC_CLASS(name); _DECLARE_DL_SENTINEL(name, usergoo) | |
112 | #define wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \ | |
113 | wxDECLARE_ABSTRACT_CLASS(name); _DECLARE_DL_SENTINEL(name, usergoo) | |
114 | ||
115 | #define wxIMPLEMENT_PLUGGABLE_CLASS(name, basename) \ | |
116 | wxIMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
117 | #define wxIMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
118 | wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
119 | #define wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
120 | wxIMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
121 | #define wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
122 | wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
123 | ||
124 | #define wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \ | |
125 | wxIMPLEMENT_PLUGGABLE_CLASS(name, basename) | |
126 | #define wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
127 | wxIMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
128 | #define wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
129 | wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
130 | #define wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
131 | wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
132 | ||
133 | #define wxCLASSINFO(name) (&name::ms_classInfo) | |
c801d85f | 134 | |
c0db9626 | 135 | #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo) |
3013b6f4 | 136 | |
b2edef6f | 137 | // Just seems a bit nicer-looking (pretend it's not a macro) |
c0db9626 | 138 | #define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo) |
c801d85f | 139 | |
73fbb031 VZ |
140 | // this cast does some more checks at compile time as it uses static_cast |
141 | // internally | |
142 | // | |
143 | // note that it still has different semantics from dynamic_cast<> and so can't | |
144 | // be replaced by it as long as there are any compilers not supporting it | |
34636400 | 145 | #define wxDynamicCast(obj, className) \ |
5232d996 | 146 | ((className *) wxCheckDynamicCast( \ |
5c33522f VZ |
147 | const_cast<wxObject *>(static_cast<const wxObject *>(\ |
148 | const_cast<className *>(static_cast<const className *>(obj)))), \ | |
5232d996 | 149 | &className::ms_classInfo)) |
0b9ab0bd | 150 | |
b2edef6f VZ |
151 | // The 'this' pointer is always true, so use this version |
152 | // to cast the this pointer and avoid compiler warnings. | |
f7637829 | 153 | #define wxDynamicCastThis(className) \ |
73fbb031 | 154 | (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0) |
33ac7e6f | 155 | |
657a8a35 VZ |
156 | // FIXME-VC6: dummy argument needed because VC6 doesn't support explicitly |
157 | // choosing the template function to call | |
158 | template <class T> | |
159 | inline T *wxCheckCast(const void *ptr, T * = NULL) | |
0b9ab0bd | 160 | { |
657a8a35 VZ |
161 | wxASSERT_MSG( wxDynamicCast(ptr, T), "wxStaticCast() used incorrectly" ); |
162 | return const_cast<T *>(static_cast<const T *>(ptr)); | |
0b9ab0bd | 163 | } |
f6bcfd97 | 164 | |
657a8a35 | 165 | #define wxStaticCast(obj, className) wxCheckCast((obj), (className *)NULL) |
f6bcfd97 | 166 | |
b2edef6f VZ |
167 | // ---------------------------------------------------------------------------- |
168 | // set up memory debugging macros | |
169 | // ---------------------------------------------------------------------------- | |
170 | ||
171 | /* | |
172 | Which new/delete operator variants do we want? | |
173 | ||
174 | _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0) | |
175 | _WX_WANT_DELETE_VOID = void operator delete (void * buf) | |
176 | _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line) | |
177 | _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int) | |
178 | _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0) | |
179 | _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf) | |
180 | _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int ) | |
181 | */ | |
182 | ||
657a8a35 | 183 | #if wxUSE_MEMORY_TRACING |
b2edef6f VZ |
184 | |
185 | // All compilers get this one | |
186 | #define _WX_WANT_NEW_SIZET_WXCHAR_INT | |
187 | ||
188 | // Everyone except Visage gets the next one | |
189 | #ifndef __VISAGECPP__ | |
190 | #define _WX_WANT_DELETE_VOID | |
c801d85f | 191 | #endif |
b2edef6f VZ |
192 | |
193 | // Only visage gets this one under the correct circumstances | |
194 | #if defined(__VISAGECPP__) && __DEBUG_ALLOC__ | |
195 | #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET | |
196 | #endif | |
197 | ||
4e124582 VZ |
198 | // Only VC++ 6 and CodeWarrior get overloaded delete that matches new |
199 | #if (defined(__VISUALC__) && (__VISUALC__ >= 1200)) || \ | |
200 | (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) | |
b2edef6f | 201 | #define _WX_WANT_DELETE_VOID_WXCHAR_INT |
fd85b064 | 202 | #endif |
c801d85f | 203 | |
b2edef6f VZ |
204 | // Now see who (if anyone) gets the array memory operators |
205 | #if wxUSE_ARRAY_MEMORY_OPERATORS | |
206 | ||
207 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
208 | #if !defined(__VISUALC__) | |
209 | #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT | |
210 | #endif | |
211 | ||
212 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
213 | #if !defined(__VISUALC__) | |
214 | #define _WX_WANT_ARRAY_DELETE_VOID | |
215 | #endif | |
216 | ||
217 | // Only CodeWarrior 6 or higher | |
218 | #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
219 | #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT | |
220 | #endif | |
221 | ||
222 | #endif // wxUSE_ARRAY_MEMORY_OPERATORS | |
223 | ||
657a8a35 | 224 | #endif // wxUSE_MEMORY_TRACING |
b2edef6f | 225 | |
cbca59a8 SC |
226 | // ---------------------------------------------------------------------------- |
227 | // Compatibility macro aliases DECLARE group | |
228 | // ---------------------------------------------------------------------------- | |
229 | // deprecated variants _not_ requiring a semicolon after them and without wx prefix. | |
230 | // (note that also some wx-prefixed macro do _not_ require a semicolon because | |
231 | // it's not always possible to force the compire to require it) | |
232 | ||
233 | #define DECLARE_CLASS_INFO_ITERATORS() wxDECLARE_CLASS_INFO_ITERATORS(); | |
234 | #define DECLARE_ABSTRACT_CLASS(n) wxDECLARE_ABSTRACT_CLASS(n); | |
235 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(n) wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(n); | |
236 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(n) wxDECLARE_DYNAMIC_CLASS_NO_COPY(n); | |
237 | #define DECLARE_DYNAMIC_CLASS(n) wxDECLARE_DYNAMIC_CLASS(n); | |
238 | #define DECLARE_CLASS(n) wxDECLARE_CLASS(n); | |
239 | ||
240 | #define DECLARE_PLUGGABLE_CLASS(n) wxDECLARE_PLUGGABLE_CLASS(n); | |
241 | #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(n) wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(n); | |
242 | #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u); | |
243 | #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u); | |
244 | ||
f8855e47 | 245 | // ---------------------------------------------------------------------------- |
6d37c1b7 | 246 | // wxRefCounter: ref counted data "manager" |
f8855e47 VZ |
247 | // ---------------------------------------------------------------------------- |
248 | ||
6d37c1b7 | 249 | class WXDLLIMPEXP_BASE wxRefCounter |
f8855e47 | 250 | { |
f8855e47 | 251 | public: |
6d37c1b7 | 252 | wxRefCounter() { m_count = 1; } |
f8855e47 VZ |
253 | |
254 | int GetRefCount() const { return m_count; } | |
255 | ||
4a11340a RR |
256 | void IncRef() { m_count++; } |
257 | void DecRef(); | |
258 | ||
259 | protected: | |
260 | // this object should never be destroyed directly but only as a | |
261 | // result of a DecRef() call: | |
6d37c1b7 | 262 | virtual ~wxRefCounter() { } |
4a11340a | 263 | |
f8855e47 | 264 | private: |
4a11340a | 265 | // our refcount: |
f8855e47 | 266 | int m_count; |
fd08ccd2 VZ |
267 | |
268 | // It doesn't make sense to copy the reference counted objects, a new ref | |
269 | // counter should be created for a new object instead and compilation | |
270 | // errors in the code using wxRefCounter due to the lack of copy ctor often | |
271 | // indicate a problem, e.g. a forgotten copy ctor implementation somewhere. | |
272 | wxDECLARE_NO_COPY_CLASS(wxRefCounter); | |
f8855e47 VZ |
273 | }; |
274 | ||
6d37c1b7 RR |
275 | // ---------------------------------------------------------------------------- |
276 | // wxObjectRefData: ref counted data meant to be stored in wxObject | |
277 | // ---------------------------------------------------------------------------- | |
278 | ||
279 | typedef wxRefCounter wxObjectRefData; | |
280 | ||
4a11340a RR |
281 | // ---------------------------------------------------------------------------- |
282 | // wxObjectDataPtr: helper class to avoid memleaks because of missing calls | |
283 | // to wxObjectRefData::DecRef | |
284 | // ---------------------------------------------------------------------------- | |
285 | ||
286 | template <class T> | |
287 | class wxObjectDataPtr | |
288 | { | |
289 | public: | |
290 | typedef T element_type; | |
291 | ||
292 | wxEXPLICIT wxObjectDataPtr(T *ptr = NULL) : m_ptr(ptr) {} | |
293 | ||
294 | // copy ctor | |
53a2db12 | 295 | wxObjectDataPtr(const wxObjectDataPtr<T> &tocopy) |
4a11340a | 296 | : m_ptr(tocopy.m_ptr) |
53a2db12 | 297 | { |
4a11340a | 298 | if (m_ptr) |
53a2db12 | 299 | m_ptr->IncRef(); |
4a11340a RR |
300 | } |
301 | ||
53a2db12 FM |
302 | ~wxObjectDataPtr() |
303 | { | |
304 | if (m_ptr) | |
305 | m_ptr->DecRef(); | |
4a11340a RR |
306 | } |
307 | ||
308 | T *get() const { return m_ptr; } | |
53a2db12 | 309 | |
a60b0ddc RR |
310 | // test for pointer validity: defining conversion to unspecified_bool_type |
311 | // and not more obvious bool to avoid implicit conversions to integer types | |
312 | typedef T *(wxObjectDataPtr<T>::*unspecified_bool_type)() const; | |
313 | operator unspecified_bool_type() const | |
314 | { | |
315 | return m_ptr ? &wxObjectDataPtr<T>::get : NULL; | |
316 | } | |
317 | ||
318 | T& operator*() const | |
53a2db12 FM |
319 | { |
320 | wxASSERT(m_ptr != NULL); | |
a60b0ddc RR |
321 | return *(m_ptr); |
322 | } | |
53a2db12 | 323 | |
e39d30c0 | 324 | T *operator->() const |
53a2db12 FM |
325 | { |
326 | wxASSERT(m_ptr != NULL); | |
327 | return get(); | |
e39d30c0 | 328 | } |
4a11340a RR |
329 | |
330 | void reset(T *ptr) | |
331 | { | |
332 | if (m_ptr) | |
333 | m_ptr->DecRef(); | |
334 | m_ptr = ptr; | |
335 | } | |
336 | ||
337 | wxObjectDataPtr& operator=(const wxObjectDataPtr &tocopy) | |
53a2db12 FM |
338 | { |
339 | if (m_ptr) | |
340 | m_ptr->DecRef(); | |
341 | m_ptr = tocopy.m_ptr; | |
4a11340a | 342 | if (m_ptr) |
53a2db12 | 343 | m_ptr->IncRef(); |
4a11340a RR |
344 | return *this; |
345 | } | |
346 | ||
347 | wxObjectDataPtr& operator=(T *ptr) | |
53a2db12 FM |
348 | { |
349 | if (m_ptr) | |
350 | m_ptr->DecRef(); | |
351 | m_ptr = ptr; | |
4a11340a RR |
352 | return *this; |
353 | } | |
354 | ||
355 | private: | |
356 | T *m_ptr; | |
357 | }; | |
358 | ||
0b9ab0bd | 359 | // ---------------------------------------------------------------------------- |
77ffb593 | 360 | // wxObject: the root class of wxWidgets object hierarchy |
0b9ab0bd RL |
361 | // ---------------------------------------------------------------------------- |
362 | ||
bddd7a8d | 363 | class WXDLLIMPEXP_BASE wxObject |
c801d85f | 364 | { |
b19b28c8 | 365 | wxDECLARE_ABSTRACT_CLASS(wxObject); |
c801d85f | 366 | |
0b9ab0bd | 367 | public: |
b2edef6f | 368 | wxObject() { m_refData = NULL; } |
0b9ab0bd | 369 | virtual ~wxObject() { UnRef(); } |
4393b50c | 370 | |
a6391d30 | 371 | wxObject(const wxObject& other) |
66e9a9f0 | 372 | { |
f8855e47 VZ |
373 | m_refData = other.m_refData; |
374 | if (m_refData) | |
6d37c1b7 | 375 | m_refData->IncRef(); |
66e9a9f0 | 376 | } |
4393b50c | 377 | |
a6391d30 GD |
378 | wxObject& operator=(const wxObject& other) |
379 | { | |
380 | if ( this != &other ) | |
381 | { | |
f8855e47 | 382 | Ref(other); |
a6391d30 GD |
383 | } |
384 | return *this; | |
385 | } | |
386 | ||
303c6f20 | 387 | bool IsKindOf(const wxClassInfo *info) const; |
c801d85f | 388 | |
0b9ab0bd | 389 | |
b2edef6f VZ |
390 | // Turn on the correct set of new and delete operators |
391 | ||
392 | #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT | |
cf760e4c | 393 | void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); |
0b9ab0bd | 394 | #endif |
27198be4 | 395 | |
b2edef6f VZ |
396 | #ifdef _WX_WANT_DELETE_VOID |
397 | void operator delete ( void * buf ); | |
398 | #endif | |
0b9ab0bd | 399 | |
b2edef6f VZ |
400 | #ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET |
401 | void operator delete ( void *buf, const char *_fname, size_t _line ); | |
0b9ab0bd | 402 | #endif |
76626af2 | 403 | |
b2edef6f | 404 | #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT |
cf760e4c | 405 | void operator delete ( void *buf, const wxChar*, int ); |
b2edef6f | 406 | #endif |
8cfc5426 | 407 | |
b2edef6f | 408 | #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT |
cf760e4c | 409 | void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); |
0b9ab0bd RL |
410 | #endif |
411 | ||
b2edef6f VZ |
412 | #ifdef _WX_WANT_ARRAY_DELETE_VOID |
413 | void operator delete[] ( void *buf ); | |
0b9ab0bd | 414 | #endif |
27198be4 | 415 | |
b2edef6f | 416 | #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT |
cf760e4c | 417 | void operator delete[] (void* buf, const wxChar*, int ); |
b2edef6f | 418 | #endif |
c801d85f | 419 | |
807d8487 VZ |
420 | // ref counted data handling methods |
421 | ||
422 | // get/set | |
423 | wxObjectRefData *GetRefData() const { return m_refData; } | |
424 | void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
425 | ||
426 | // make a 'clone' of the object | |
0b9ab0bd | 427 | void Ref(const wxObject& clone); |
c801d85f | 428 | |
807d8487 | 429 | // destroy a reference |
0b9ab0bd | 430 | void UnRef(); |
c801d85f | 431 | |
93c5f755 PC |
432 | // Make sure this object has only one reference |
433 | void UnShare() { AllocExclusive(); } | |
434 | ||
a3ab1c18 VZ |
435 | // check if this object references the same data as the other one |
436 | bool IsSameAs(const wxObject& o) const { return m_refData == o.m_refData; } | |
55ccdb93 | 437 | |
c801d85f | 438 | protected: |
807d8487 VZ |
439 | // ensure that our data is not shared with anybody else: if we have no |
440 | // data, it is created using CreateRefData() below, if we have shared data | |
441 | // it is copied using CloneRefData(), otherwise nothing is done | |
442 | void AllocExclusive(); | |
443 | ||
4e124582 VZ |
444 | // both methods must be implemented if AllocExclusive() is used, not pure |
445 | // virtual only because of the backwards compatibility reasons | |
807d8487 VZ |
446 | |
447 | // create a new m_refData | |
448 | virtual wxObjectRefData *CreateRefData() const; | |
449 | ||
450 | // create a new m_refData initialized with the given one | |
b8027888 | 451 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; |
807d8487 | 452 | |
0b9ab0bd | 453 | wxObjectRefData *m_refData; |
c801d85f KB |
454 | }; |
455 | ||
ea1e6c4b RL |
456 | inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) |
457 | { | |
b2edef6f | 458 | return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL; |
ea1e6c4b RL |
459 | } |
460 | ||
cbca59a8 | 461 | #include "wx/xti2.h" |
2d51f067 | 462 | |
b2edef6f VZ |
463 | // ---------------------------------------------------------------------------- |
464 | // more debugging macros | |
465 | // ---------------------------------------------------------------------------- | |
466 | ||
657a8a35 | 467 | #if wxUSE_DEBUG_NEW_ALWAYS |
70bf6180 VZ |
468 | #define WXDEBUG_NEW new(__TFILE__,__LINE__) |
469 | ||
657a8a35 VZ |
470 | #if wxUSE_GLOBAL_MEMORY_OPERATORS |
471 | #define new WXDEBUG_NEW | |
472 | #elif defined(__VISUALC__) | |
473 | // Including this file redefines new and allows leak reports to | |
474 | // contain line numbers | |
475 | #include "wx/msw/msvcrt.h" | |
476 | #endif | |
477 | #endif // wxUSE_DEBUG_NEW_ALWAYS | |
c801d85f | 478 | |
b19b28c8 | 479 | // ---------------------------------------------------------------------------- |
cbca59a8 | 480 | // Compatibility macro aliases IMPLEMENT group |
b19b28c8 FM |
481 | // ---------------------------------------------------------------------------- |
482 | ||
483 | // deprecated variants _not_ requiring a semicolon after them and without wx prefix. | |
484 | // (note that also some wx-prefixed macro do _not_ require a semicolon because | |
485 | // it's not always possible to force the compire to require it) | |
486 | ||
b19b28c8 FM |
487 | #define IMPLEMENT_DYNAMIC_CLASS(n,b) wxIMPLEMENT_DYNAMIC_CLASS(n,b) |
488 | #define IMPLEMENT_DYNAMIC_CLASS2(n,b1,b2) wxIMPLEMENT_DYNAMIC_CLASS2(n,b1,b2) | |
489 | #define IMPLEMENT_ABSTRACT_CLASS(n,b) wxIMPLEMENT_ABSTRACT_CLASS(n,b) | |
490 | #define IMPLEMENT_ABSTRACT_CLASS2(n,b1,b2) wxIMPLEMENT_ABSTRACT_CLASS2(n,b1,b2) | |
491 | #define IMPLEMENT_CLASS(n,b) wxIMPLEMENT_CLASS(n,b) | |
492 | #define IMPLEMENT_CLASS2(n,b1,b2) wxIMPLEMENT_CLASS2(n,b1,b2) | |
493 | ||
b19b28c8 FM |
494 | #define IMPLEMENT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_PLUGGABLE_CLASS(n,b) |
495 | #define IMPLEMENT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_PLUGGABLE_CLASS2(n,b,b2) | |
496 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b) | |
497 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) | |
498 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(n,b) | |
499 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(n,b,b2) | |
500 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,b) | |
501 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(n,b,b2) | |
502 | ||
503 | #define CLASSINFO(n) wxCLASSINFO(n) | |
504 | ||
c0089c96 | 505 | #endif // _WX_OBJECTH__ |