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