]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/object.h | |
3 | // Purpose: wxObject class, plus run-time type information macros | |
4 | // Author: Julian Smart | |
5 | // Modified by: Ron Lee | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997 Julian Smart | |
9 | // (c) 2001 Ron Lee <ron@debian.org> | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #ifndef _WX_OBJECTH__ | |
14 | #define _WX_OBJECTH__ | |
15 | ||
16 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
17 | #pragma interface "object.h" | |
18 | #endif | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // headers | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
24 | #include "wx/defs.h" | |
25 | #include "wx/memory.h" | |
26 | ||
27 | class WXDLLIMPEXP_BASE wxObject; | |
28 | ||
29 | #if wxUSE_DYNAMIC_CLASSES | |
30 | ||
31 | #ifndef wxUSE_EXTENDED_RTTI | |
32 | #define wxUSE_EXTENDED_RTTI 0 | |
33 | #endif | |
34 | ||
35 | #if wxUSE_EXTENDED_RTTI | |
36 | #include "wx/xti.h" | |
37 | #else | |
38 | ||
39 | // ---------------------------------------------------------------------------- | |
40 | // conditional compilation | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
43 | // this shouldn't be needed any longer as <wx/msw/private.h> does it but it | |
44 | // doesn't hurt neither | |
45 | #ifdef GetClassName | |
46 | #undef GetClassName | |
47 | #endif | |
48 | #ifdef GetClassInfo | |
49 | #undef GetClassInfo | |
50 | #endif | |
51 | ||
52 | class WXDLLIMPEXP_BASE wxClassInfo; | |
53 | class WXDLLIMPEXP_BASE wxHashTable; | |
54 | class WXDLLIMPEXP_BASE wxObjectRefData; | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // wxClassInfo | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
61 | ||
62 | class WXDLLIMPEXP_BASE wxClassInfo | |
63 | { | |
64 | public: | |
65 | wxClassInfo( const wxChar *className, | |
66 | const wxClassInfo *baseInfo1, | |
67 | const wxClassInfo *baseInfo2, | |
68 | int size, | |
69 | wxObjectConstructorFn ctor ) | |
70 | : m_className(className) | |
71 | , m_objectSize(size) | |
72 | , m_objectConstructor(ctor) | |
73 | , m_baseInfo1(baseInfo1) | |
74 | , m_baseInfo2(baseInfo2) | |
75 | , m_next(sm_first) | |
76 | { | |
77 | sm_first = this; | |
78 | Register(); | |
79 | } | |
80 | ||
81 | ~wxClassInfo(); | |
82 | ||
83 | wxObject *CreateObject() { return m_objectConstructor ? (*m_objectConstructor)() : 0; } | |
84 | ||
85 | const wxChar *GetClassName() const { return m_className; } | |
86 | const wxChar *GetBaseClassName1() const | |
87 | { return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; } | |
88 | const wxChar *GetBaseClassName2() const | |
89 | { return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; } | |
90 | const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; } | |
91 | const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; } | |
92 | int GetSize() const { return m_objectSize; } | |
93 | ||
94 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
95 | static const wxClassInfo *GetFirst() { return sm_first; } | |
96 | const wxClassInfo *GetNext() const { return m_next; } | |
97 | static wxClassInfo *FindClass(const wxChar *className); | |
98 | ||
99 | // Climb upwards through inheritance hierarchy. | |
100 | // Dual inheritance is catered for. | |
101 | ||
102 | bool IsKindOf(const wxClassInfo *info) const | |
103 | { | |
104 | return info != 0 && | |
105 | ( info == this || | |
106 | ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) || | |
107 | ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) ); | |
108 | } | |
109 | ||
110 | #if WXWIN_COMPATIBILITY_2_4 | |
111 | // Initializes parent pointers and hash table for fast searching. | |
112 | wxDEPRECATED( static void InitializeClasses() ); | |
113 | // Cleans up hash table used for fast searching. | |
114 | wxDEPRECATED( static void CleanUpClasses() ); | |
115 | #endif | |
116 | static void CleanUp(); | |
117 | ||
118 | public: | |
119 | const wxChar *m_className; | |
120 | int m_objectSize; | |
121 | wxObjectConstructorFn m_objectConstructor; | |
122 | ||
123 | // Pointers to base wxClassInfos: set in InitializeClasses | |
124 | ||
125 | const wxClassInfo *m_baseInfo1; | |
126 | const wxClassInfo *m_baseInfo2; | |
127 | ||
128 | // class info object live in a linked list: | |
129 | // pointers to its head and the next element in it | |
130 | ||
131 | static wxClassInfo *sm_first; | |
132 | wxClassInfo *m_next; | |
133 | ||
134 | // FIXME: this should be private (currently used directly by way too | |
135 | // many clients) | |
136 | static wxHashTable *sm_classTable; | |
137 | ||
138 | private: | |
139 | // InitializeClasses() helper | |
140 | static wxClassInfo *GetBaseByName(const wxChar *name); | |
141 | ||
142 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
143 | ||
144 | protected: | |
145 | // registers the class | |
146 | void Register(); | |
147 | void Unregister(); | |
148 | }; | |
149 | ||
150 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); | |
151 | ||
152 | #if WXWIN_COMPATIBILITY_2_4 | |
153 | inline void wxClassInfo::InitializeClasses() {} | |
154 | inline void wxClassInfo::CleanUpClasses() {} | |
155 | #endif | |
156 | ||
157 | // ---------------------------------------------------------------------------- | |
158 | // Dynamic class macros | |
159 | // ---------------------------------------------------------------------------- | |
160 | ||
161 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
162 | public: \ | |
163 | static wxClassInfo ms_classInfo; \ | |
164 | static wxObject* wxCreateObject(); \ | |
165 | virtual wxClassInfo *GetClassInfo() const \ | |
166 | { return &name::ms_classInfo; } | |
167 | ||
168 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
169 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
170 | DECLARE_DYNAMIC_CLASS(name) | |
171 | ||
172 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
173 | DECLARE_NO_COPY_CLASS(name) \ | |
174 | DECLARE_DYNAMIC_CLASS(name) | |
175 | ||
176 | #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
177 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
178 | ||
179 | // ----------------------------------- | |
180 | // for concrete classes | |
181 | // ----------------------------------- | |
182 | ||
183 | // Single inheritance with one base class | |
184 | ||
185 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ | |
186 | wxObject* name::wxCreateObject() \ | |
187 | { return new name; } \ | |
188 | wxClassInfo name::ms_classInfo(wxT(#name), \ | |
189 | &basename::ms_classInfo, NULL, \ | |
190 | (int) sizeof(name), \ | |
191 | (wxObjectConstructorFn) name::wxCreateObject); | |
192 | ||
193 | // Multiple inheritance with two base classes | |
194 | ||
195 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \ | |
196 | wxObject* name::wxCreateObject() \ | |
197 | { return new name; } \ | |
198 | wxClassInfo name::ms_classInfo(wxT(#name), \ | |
199 | &basename1::ms_classInfo, \ | |
200 | &basename2::ms_classInfo, \ | |
201 | wxT(#basename2), (int) sizeof(name), \ | |
202 | (wxObjectConstructorFn) name::wxCreateObject); | |
203 | ||
204 | // ----------------------------------- | |
205 | // for abstract classes | |
206 | // ----------------------------------- | |
207 | ||
208 | // Single inheritance with one base class | |
209 | ||
210 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
211 | wxClassInfo name::ms_classInfo(wxT(#name), \ | |
212 | &basename::ms_classInfo, NULL, \ | |
213 | (int) sizeof(name), (wxObjectConstructorFn) 0); | |
214 | ||
215 | // Multiple inheritance with two base classes | |
216 | ||
217 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
218 | wxClassInfo name::ms_classInfo(wxT(#name), \ | |
219 | &basename1::ms_classInfo, \ | |
220 | &basename2::ms_classInfo, \ | |
221 | (int) sizeof(name), \ | |
222 | (wxObjectConstructorFn) 0); | |
223 | ||
224 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
225 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
226 | ||
227 | #endif // !wxUSE_EXTENDED_RTTI | |
228 | ||
229 | ||
230 | // ----------------------------------- | |
231 | // for pluggable classes | |
232 | // ----------------------------------- | |
233 | ||
234 | // NOTE: this should probably be the very first statement | |
235 | // in the class declaration so wxPluginSentinel is | |
236 | // the first member initialised and the last destroyed. | |
237 | ||
238 | // _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel; | |
239 | ||
240 | #if wxUSE_NESTED_CLASSES | |
241 | ||
242 | #define _DECLARE_DL_SENTINEL(name, exportdecl) \ | |
243 | class exportdecl name##PluginSentinel { \ | |
244 | private: \ | |
245 | static const wxString sm_className; \ | |
246 | public: \ | |
247 | name##PluginSentinel(); \ | |
248 | ~name##PluginSentinel(); \ | |
249 | }; \ | |
250 | name##PluginSentinel m_pluginsentinel; | |
251 | ||
252 | #define _IMPLEMENT_DL_SENTINEL(name) \ | |
253 | const wxString name::name##PluginSentinel::sm_className(#name); \ | |
254 | name::name##PluginSentinel::name##PluginSentinel() { \ | |
255 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ | |
256 | if( e != 0 ) { e->RefObj(); } \ | |
257 | } \ | |
258 | name::name##PluginSentinel::~name##PluginSentinel() { \ | |
259 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ | |
260 | if( e != 0 ) { e->UnrefObj(); } \ | |
261 | } | |
262 | #else | |
263 | ||
264 | #define _DECLARE_DL_SENTINEL(name) | |
265 | #define _IMPLEMENT_DL_SENTINEL(name) | |
266 | ||
267 | #endif // wxUSE_NESTED_CLASSES | |
268 | ||
269 | #define DECLARE_PLUGGABLE_CLASS(name) \ | |
270 | DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT) | |
271 | #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \ | |
272 | DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT) | |
273 | ||
274 | #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \ | |
275 | DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo) | |
276 | #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \ | |
277 | DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo) | |
278 | ||
279 | #define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \ | |
280 | IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
281 | #define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
282 | IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
283 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
284 | IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
285 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
286 | IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
287 | ||
288 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \ | |
289 | IMPLEMENT_PLUGGABLE_CLASS(name, basename) | |
290 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
291 | IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
292 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
293 | IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
294 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
295 | IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
296 | ||
297 | #define CLASSINFO(name) (&name::ms_classInfo) | |
298 | ||
299 | #else // !wxUSE_DYNAMIC_CLASSES | |
300 | ||
301 | // No dynamic class system: so stub out the macros | |
302 | ||
303 | #define DECLARE_DYNAMIC_CLASS(name) | |
304 | #define DECLARE_ABSTRACT_CLASS(name) | |
305 | #define DECLARE_CLASS(name) | |
306 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) | |
307 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) | |
308 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) | |
309 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) | |
310 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
311 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
312 | ||
313 | #define DECLARE_PLUGGABLE_CLASS(name) | |
314 | #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) | |
315 | #define IMPLEMENT_PLUGGABLE_CLASS(name, basename) | |
316 | #define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
317 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
318 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
319 | ||
320 | #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) | |
321 | #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) | |
322 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) | |
323 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) | |
324 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
325 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
326 | ||
327 | #endif // wxUSE_DYNAMIC_CLASSES | |
328 | ||
329 | #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo) | |
330 | ||
331 | // Just seems a bit nicer-looking (pretend it's not a macro) | |
332 | #define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo) | |
333 | ||
334 | // to be replaced by dynamic_cast<> in the future | |
335 | #define wxDynamicCast(obj, className) \ | |
336 | ((className *) wxCheckDynamicCast( \ | |
337 | wx_const_cast(wxObject *, wx_static_cast(const wxObject *, \ | |
338 | wx_const_cast(className *, wx_static_cast(const className *, obj)))), \ | |
339 | &className::ms_classInfo)) | |
340 | ||
341 | // The 'this' pointer is always true, so use this version | |
342 | // to cast the this pointer and avoid compiler warnings. | |
343 | #define wxDynamicCastThis(className) \ | |
344 | (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0) | |
345 | ||
346 | #ifdef __WXDEBUG__ | |
347 | inline void* wxCheckCast(void *ptr) | |
348 | { | |
349 | wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") ); | |
350 | return ptr; | |
351 | } | |
352 | #define wxStaticCast(obj, className) \ | |
353 | ((className *)wxCheckCast(wxDynamicCast(obj, className))) | |
354 | ||
355 | #else // !__WXDEBUG__ | |
356 | #define wxStaticCast(obj, className) ((className *)(obj)) | |
357 | ||
358 | #endif // __WXDEBUG__ | |
359 | ||
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 | |
384 | #endif | |
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 | |
392 | #if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) | |
393 | #define _WX_WANT_DELETE_VOID_WXCHAR_INT | |
394 | #endif | |
395 | ||
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 | ||
418 | // ---------------------------------------------------------------------------- | |
419 | // wxObject: the root class of wxWidgets object hierarchy | |
420 | // ---------------------------------------------------------------------------- | |
421 | ||
422 | class WXDLLIMPEXP_BASE wxObject | |
423 | { | |
424 | DECLARE_ABSTRACT_CLASS(wxObject) | |
425 | ||
426 | private: | |
427 | void InitFrom(const wxObject& other); | |
428 | ||
429 | public: | |
430 | wxObject() { m_refData = NULL; } | |
431 | virtual ~wxObject() { UnRef(); } | |
432 | ||
433 | wxObject(const wxObject& other) | |
434 | { | |
435 | InitFrom(other); | |
436 | } | |
437 | ||
438 | wxObject& operator=(const wxObject& other) | |
439 | { | |
440 | if ( this != &other ) | |
441 | { | |
442 | UnRef(); | |
443 | InitFrom(other); | |
444 | } | |
445 | return *this; | |
446 | } | |
447 | ||
448 | bool IsKindOf(wxClassInfo *info) const; | |
449 | ||
450 | ||
451 | // Turn on the correct set of new and delete operators | |
452 | ||
453 | #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT | |
454 | void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); | |
455 | #endif | |
456 | ||
457 | #ifdef _WX_WANT_DELETE_VOID | |
458 | void operator delete ( void * buf ); | |
459 | #endif | |
460 | ||
461 | #ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET | |
462 | void operator delete ( void *buf, const char *_fname, size_t _line ); | |
463 | #endif | |
464 | ||
465 | #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT | |
466 | void operator delete ( void *buf, const wxChar*, int ); | |
467 | #endif | |
468 | ||
469 | #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT | |
470 | void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); | |
471 | #endif | |
472 | ||
473 | #ifdef _WX_WANT_ARRAY_DELETE_VOID | |
474 | void operator delete[] ( void *buf ); | |
475 | #endif | |
476 | ||
477 | #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT | |
478 | void operator delete[] (void* buf, const wxChar*, int ); | |
479 | #endif | |
480 | ||
481 | // ref counted data handling methods | |
482 | ||
483 | // get/set | |
484 | wxObjectRefData *GetRefData() const { return m_refData; } | |
485 | void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
486 | ||
487 | // make a 'clone' of the object | |
488 | void Ref(const wxObject& clone); | |
489 | ||
490 | // destroy a reference | |
491 | void UnRef(); | |
492 | ||
493 | protected: | |
494 | // ensure that our data is not shared with anybody else: if we have no | |
495 | // data, it is created using CreateRefData() below, if we have shared data | |
496 | // it is copied using CloneRefData(), otherwise nothing is done | |
497 | void AllocExclusive(); | |
498 | ||
499 | // both methods must be implemented if Unshare() is used, not pure virtual | |
500 | // only because of the backwards compatibility reasons | |
501 | ||
502 | // create a new m_refData | |
503 | virtual wxObjectRefData *CreateRefData() const; | |
504 | ||
505 | // create a new m_refData initialized with the given one | |
506 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
507 | ||
508 | wxObjectRefData *m_refData; | |
509 | }; | |
510 | ||
511 | // ---------------------------------------------------------------------------- | |
512 | // wxObjectRefData: ref counted data meant to be stored in wxObject | |
513 | // ---------------------------------------------------------------------------- | |
514 | ||
515 | class WXDLLIMPEXP_BASE wxObjectRefData | |
516 | { | |
517 | friend class WXDLLIMPEXP_BASE wxObject; | |
518 | ||
519 | public: | |
520 | wxObjectRefData() : m_count(1) { } | |
521 | virtual ~wxObjectRefData() { } | |
522 | ||
523 | int GetRefCount() const { return m_count; } | |
524 | ||
525 | private: | |
526 | int m_count; | |
527 | }; | |
528 | ||
529 | ||
530 | inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) | |
531 | { | |
532 | return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL; | |
533 | } | |
534 | ||
535 | #if wxUSE_EXTENDED_RTTI | |
536 | class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject | |
537 | { | |
538 | friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ; | |
539 | public: | |
540 | // instantiates this object with an instance of its superclass | |
541 | wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ; | |
542 | ~wxDynamicObject(); | |
543 | ||
544 | void SetProperty (const wxChar *propertyName, const wxxVariant &value); | |
545 | wxxVariant GetProperty (const wxChar *propertyName) const ; | |
546 | ||
547 | // get the runtime identity of this object | |
548 | wxClassInfo *GetClassInfo() const | |
549 | { | |
550 | return wx_const_cast(wxClassInfo *, m_classInfo); | |
551 | } | |
552 | ||
553 | wxObject* GetSuperClassInstance() const | |
554 | { | |
555 | return m_superClassInstance ; | |
556 | } | |
557 | private : | |
558 | // removes an existing runtime-property | |
559 | void RemoveProperty( const wxChar *propertyName ) ; | |
560 | ||
561 | // renames an existing runtime-property | |
562 | void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; | |
563 | ||
564 | wxObject *m_superClassInstance ; | |
565 | const wxDynamicClassInfo *m_classInfo; | |
566 | struct wxDynamicObjectInternal; | |
567 | wxDynamicObjectInternal *m_data; | |
568 | }; | |
569 | #endif | |
570 | ||
571 | // ---------------------------------------------------------------------------- | |
572 | // more debugging macros | |
573 | // ---------------------------------------------------------------------------- | |
574 | ||
575 | #ifdef __WXDEBUG__ | |
576 | #ifndef WXDEBUG_NEW | |
577 | #define WXDEBUG_NEW new(__TFILE__,__LINE__) | |
578 | #endif | |
579 | #else // !__WXDEBUG__ | |
580 | #define WXDEBUG_NEW new | |
581 | #endif | |
582 | ||
583 | // Redefine new to be the debugging version. This doesn't work with all | |
584 | // compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish | |
585 | // to use the debugging version. | |
586 | ||
587 | #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS | |
588 | #define new new(__TFILE__,__LINE__) | |
589 | #endif | |
590 | ||
591 | #endif // _WX_OBJECTH__ | |
592 |