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