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