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