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