]>
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 | #ifdef 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 | #ifdef 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 sm_class##name; \ | |
164 | virtual wxClassInfo *GetClassInfo() const \ | |
165 | { return &name::sm_class##name; } | |
166 | ||
167 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
168 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
169 | DECLARE_DYNAMIC_CLASS(name) | |
170 | ||
171 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ | |
172 | DECLARE_NO_COPY_CLASS(name) \ | |
173 | DECLARE_DYNAMIC_CLASS(name) | |
174 | ||
175 | #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
176 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
177 | ||
178 | // ----------------------------------- | |
179 | // for concrete classes | |
180 | // ----------------------------------- | |
181 | ||
182 | // Single inheritance with one base class | |
183 | ||
184 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ | |
185 | wxObject* wxConstructorFor##name() \ | |
186 | { return new name; } \ | |
187 | wxClassInfo name::sm_class##name(wxT(#name), \ | |
188 | &basename::sm_class##basename, NULL, \ | |
189 | (int) sizeof(name), \ | |
190 | (wxObjectConstructorFn) wxConstructorFor##name); | |
191 | ||
192 | // Multiple inheritance with two base classes | |
193 | ||
194 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \ | |
195 | wxObject* wxConstructorFor##name() \ | |
196 | { return new name; } \ | |
197 | wxClassInfo name::sm_class##name(wxT(#name), \ | |
198 | &basename1::sm_class##basename1, \ | |
199 | &basename2::sm_class##basename2, \ | |
200 | wxT(#basename2), (int) sizeof(name), \ | |
201 | (wxObjectConstructorFn) wxConstructorFor##name); | |
202 | ||
203 | // ----------------------------------- | |
204 | // for abstract classes | |
205 | // ----------------------------------- | |
206 | ||
207 | // Single inheritance with one base class | |
208 | ||
209 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
210 | wxClassInfo name::sm_class##name(wxT(#name), \ | |
211 | &basename::sm_class##basename, NULL, \ | |
212 | (int) sizeof(name), (wxObjectConstructorFn) 0); | |
213 | ||
214 | // Multiple inheritance with two base classes | |
215 | ||
216 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
217 | wxClassInfo name::sm_class##name(wxT(#name), \ | |
218 | &basename1::sm_class##basename1, \ | |
219 | &basename2::sm_class##basename2, \ | |
220 | (int) sizeof(name), \ | |
221 | (wxObjectConstructorFn) 0); | |
222 | ||
223 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
224 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
225 | ||
226 | #endif // !wxUSE_EXTENDED_RTTI | |
227 | ||
228 | ||
229 | // ----------------------------------- | |
230 | // for pluggable classes | |
231 | // ----------------------------------- | |
232 | ||
233 | // NOTE: this should probably be the very first statement | |
234 | // in the class declaration so wxPluginSentinel is | |
235 | // the first member initialised and the last destroyed. | |
236 | ||
237 | // _DECLARE_DL_SENTINEL(name) wxPluginSentinel m_pluginsentinel; | |
238 | ||
239 | #if wxUSE_NESTED_CLASSES | |
240 | ||
241 | #define _DECLARE_DL_SENTINEL(name, exportdecl) \ | |
242 | class exportdecl name##PluginSentinel { \ | |
243 | private: \ | |
244 | static const wxString sm_className; \ | |
245 | public: \ | |
246 | name##PluginSentinel(); \ | |
247 | ~name##PluginSentinel(); \ | |
248 | }; \ | |
249 | name##PluginSentinel m_pluginsentinel; | |
250 | ||
251 | #define _IMPLEMENT_DL_SENTINEL(name) \ | |
252 | const wxString name::name##PluginSentinel::sm_className(#name); \ | |
253 | name::name##PluginSentinel::name##PluginSentinel() { \ | |
254 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ | |
255 | if( e != 0 ) { e->RefObj(); } \ | |
256 | } \ | |
257 | name::name##PluginSentinel::~name##PluginSentinel() { \ | |
258 | wxPluginLibrary *e = (wxPluginLibrary*) wxPluginLibrary::ms_classes.Get(#name); \ | |
259 | if( e != 0 ) { e->UnrefObj(); } \ | |
260 | } | |
261 | #else | |
262 | ||
263 | #define _DECLARE_DL_SENTINEL(name) | |
264 | #define _IMPLEMENT_DL_SENTINEL(name) | |
265 | ||
266 | #endif // wxUSE_NESTED_CLASSES | |
267 | ||
268 | #define DECLARE_PLUGGABLE_CLASS(name) \ | |
269 | DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT) | |
270 | #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) \ | |
271 | DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, WXDLLEXPORT) | |
272 | ||
273 | #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) \ | |
274 | DECLARE_DYNAMIC_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo) | |
275 | #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) \ | |
276 | DECLARE_ABSTRACT_CLASS(name) _DECLARE_DL_SENTINEL(name, usergoo) | |
277 | ||
278 | #define IMPLEMENT_PLUGGABLE_CLASS(name, basename) \ | |
279 | IMPLEMENT_DYNAMIC_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
280 | #define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
281 | IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
282 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
283 | IMPLEMENT_ABSTRACT_CLASS(name, basename) _IMPLEMENT_DL_SENTINEL(name) | |
284 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
285 | IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) _IMPLEMENT_DL_SENTINEL(name) | |
286 | ||
287 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) \ | |
288 | IMPLEMENT_PLUGGABLE_CLASS(name, basename) | |
289 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
290 | IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
291 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) \ | |
292 | IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
293 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) \ | |
294 | IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
295 | ||
296 | #define CLASSINFO(name) (&name::sm_class##name) | |
297 | ||
298 | #else // !wxUSE_DYNAMIC_CLASSES | |
299 | ||
300 | // No dynamic class system: so stub out the macros | |
301 | ||
302 | #define DECLARE_DYNAMIC_CLASS(name) | |
303 | #define DECLARE_ABSTRACT_CLASS(name) | |
304 | #define DECLARE_CLASS(name) | |
305 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) | |
306 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) | |
307 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) | |
308 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) | |
309 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
310 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
311 | ||
312 | #define DECLARE_PLUGGABLE_CLASS(name) | |
313 | #define DECLARE_ABSTRACT_PLUGGABLE_CLASS(name) | |
314 | #define IMPLEMENT_PLUGGABLE_CLASS(name, basename) | |
315 | #define IMPLEMENT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
316 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
317 | #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
318 | ||
319 | #define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(name, usergoo) | |
320 | #define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, usergoo) | |
321 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS(name, basename) | |
322 | #define IMPLEMENT_USER_EXPORTED_PLUGGABLE_CLASS2(name, basename1, basename2) | |
323 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(name, basename) | |
324 | #define IMPLEMENT_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS2(name, basename1, basename2) | |
325 | ||
326 | #endif // wxUSE_DYNAMIC_CLASSES | |
327 | ||
328 | #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className) | |
329 | ||
330 | // Just seems a bit nicer-looking (pretend it's not a macro) | |
331 | #define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className) | |
332 | ||
333 | // to be replaced by dynamic_cast<> in the future | |
334 | #define wxDynamicCast(obj, className) \ | |
335 | ((className *) wxCheckDynamicCast((wxObject*)(obj), &className::sm_class##className)) | |
336 | ||
337 | // The 'this' pointer is always true, so use this version | |
338 | // to cast the this pointer and avoid compiler warnings. | |
339 | #define wxDynamicCastThis(className) \ | |
340 | (IsKindOf(&className::sm_class##className) ? (className *)(this) : (className *)0) | |
341 | ||
342 | #ifdef HAVE_CONST_CAST | |
343 | #define wxConstCast(obj, className) const_cast<className *>(obj) | |
344 | #else | |
345 | #define wxConstCast(obj, className) ((className *)(obj)) | |
346 | #endif | |
347 | ||
348 | ||
349 | #ifdef __WXDEBUG__ | |
350 | inline void wxCheckCast(void *ptr) | |
351 | { | |
352 | wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") ); | |
353 | } | |
354 | #define wxStaticCast(obj, className) \ | |
355 | (wxCheckCast(wxDynamicCast(obj, className)), ((className *)(obj))) | |
356 | ||
357 | #else // !__WXDEBUG__ | |
358 | #define wxStaticCast(obj, className) ((className *)(obj)) | |
359 | ||
360 | #endif // __WXDEBUG__ | |
361 | ||
362 | // ---------------------------------------------------------------------------- | |
363 | // set up memory debugging macros | |
364 | // ---------------------------------------------------------------------------- | |
365 | ||
366 | /* | |
367 | Which new/delete operator variants do we want? | |
368 | ||
369 | _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0) | |
370 | _WX_WANT_DELETE_VOID = void operator delete (void * buf) | |
371 | _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line) | |
372 | _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int) | |
373 | _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0) | |
374 | _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf) | |
375 | _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int ) | |
376 | */ | |
377 | ||
378 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING | |
379 | ||
380 | // All compilers get this one | |
381 | #define _WX_WANT_NEW_SIZET_WXCHAR_INT | |
382 | ||
383 | // Everyone except Visage gets the next one | |
384 | #ifndef __VISAGECPP__ | |
385 | #define _WX_WANT_DELETE_VOID | |
386 | #endif | |
387 | ||
388 | // Only visage gets this one under the correct circumstances | |
389 | #if defined(__VISAGECPP__) && __DEBUG_ALLOC__ | |
390 | #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET | |
391 | #endif | |
392 | ||
393 | // Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new | |
394 | #if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) | |
395 | #define _WX_WANT_DELETE_VOID_WXCHAR_INT | |
396 | #endif | |
397 | ||
398 | // Now see who (if anyone) gets the array memory operators | |
399 | #if wxUSE_ARRAY_MEMORY_OPERATORS | |
400 | ||
401 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
402 | #if !defined(__VISUALC__) | |
403 | #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT | |
404 | #endif | |
405 | ||
406 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
407 | #if !defined(__VISUALC__) | |
408 | #define _WX_WANT_ARRAY_DELETE_VOID | |
409 | #endif | |
410 | ||
411 | // Only CodeWarrior 6 or higher | |
412 | #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
413 | #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT | |
414 | #endif | |
415 | ||
416 | #endif // wxUSE_ARRAY_MEMORY_OPERATORS | |
417 | ||
418 | #endif // WXDEBUG && wxUSE_MEMORY_TRACING | |
419 | ||
420 | // ---------------------------------------------------------------------------- | |
421 | // wxObject: the root class of wxWindows object hierarchy | |
422 | // ---------------------------------------------------------------------------- | |
423 | ||
424 | class WXDLLIMPEXP_BASE wxObject | |
425 | { | |
426 | DECLARE_ABSTRACT_CLASS(wxObject) | |
427 | ||
428 | private: | |
429 | void InitFrom(const wxObject& other); | |
430 | ||
431 | public: | |
432 | wxObject() { m_refData = NULL; } | |
433 | virtual ~wxObject() { UnRef(); } | |
434 | ||
435 | wxObject(const wxObject& other) | |
436 | { | |
437 | InitFrom(other); | |
438 | } | |
439 | ||
440 | wxObject& operator=(const wxObject& other) | |
441 | { | |
442 | if ( this != &other ) | |
443 | { | |
444 | UnRef(); | |
445 | InitFrom(other); | |
446 | } | |
447 | return *this; | |
448 | } | |
449 | ||
450 | bool IsKindOf(wxClassInfo *info) const; | |
451 | ||
452 | ||
453 | // Turn on the correct set of new and delete operators | |
454 | ||
455 | #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT | |
456 | void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); | |
457 | #endif | |
458 | ||
459 | #ifdef _WX_WANT_DELETE_VOID | |
460 | void operator delete ( void * buf ); | |
461 | #endif | |
462 | ||
463 | #ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET | |
464 | void operator delete ( void *buf, const char *_fname, size_t _line ); | |
465 | #endif | |
466 | ||
467 | #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT | |
468 | void operator delete ( void *buf, const wxChar*, int ); | |
469 | #endif | |
470 | ||
471 | #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT | |
472 | void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); | |
473 | #endif | |
474 | ||
475 | #ifdef _WX_WANT_ARRAY_DELETE_VOID | |
476 | void operator delete[] ( void *buf ); | |
477 | #endif | |
478 | ||
479 | #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT | |
480 | void operator delete[] (void* buf, const wxChar*, int ); | |
481 | #endif | |
482 | ||
483 | // ref counted data handling methods | |
484 | ||
485 | // get/set | |
486 | wxObjectRefData *GetRefData() const { return m_refData; } | |
487 | void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
488 | ||
489 | // make a 'clone' of the object | |
490 | void Ref(const wxObject& clone); | |
491 | ||
492 | // destroy a reference | |
493 | void UnRef(); | |
494 | ||
495 | protected: | |
496 | // ensure that our data is not shared with anybody else: if we have no | |
497 | // data, it is created using CreateRefData() below, if we have shared data | |
498 | // it is copied using CloneRefData(), otherwise nothing is done | |
499 | void AllocExclusive(); | |
500 | ||
501 | // both methods must be implemented if Unshare() is used, not pure virtual | |
502 | // only because of the backwards compatibility reasons | |
503 | ||
504 | // create a new m_refData | |
505 | virtual wxObjectRefData *CreateRefData() const; | |
506 | ||
507 | // create a new m_refData initialized with the given one | |
508 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
509 | ||
510 | wxObjectRefData *m_refData; | |
511 | }; | |
512 | ||
513 | // ---------------------------------------------------------------------------- | |
514 | // wxObjectRefData: ref counted data meant to be stored in wxObject | |
515 | // ---------------------------------------------------------------------------- | |
516 | ||
517 | class WXDLLIMPEXP_BASE wxObjectRefData | |
518 | { | |
519 | friend class WXDLLIMPEXP_BASE wxObject; | |
520 | ||
521 | public: | |
522 | wxObjectRefData() : m_count(1) { } | |
523 | virtual ~wxObjectRefData() { } | |
524 | ||
525 | int GetRefCount() const { return m_count; } | |
526 | ||
527 | private: | |
528 | int m_count; | |
529 | }; | |
530 | ||
531 | ||
532 | inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) | |
533 | { | |
534 | return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL; | |
535 | } | |
536 | ||
537 | #if wxUSE_EXTENDED_RTTI | |
538 | class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject | |
539 | { | |
540 | friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ; | |
541 | public: | |
542 | // instantiates this object with an instance of its superclass | |
543 | wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ; | |
544 | ~wxDynamicObject(); | |
545 | ||
546 | void SetProperty (const wxChar *propertyName, const wxxVariant &value); | |
547 | wxxVariant GetProperty (const wxChar *propertyName) const ; | |
548 | ||
549 | // get the runtime identity of this object | |
550 | wxClassInfo *GetClassInfo() const | |
551 | { | |
552 | return const_cast<wxClassInfo*>((const wxClassInfo*)m_classInfo); | |
553 | } | |
554 | ||
555 | wxObject* GetSuperClassInstance() const | |
556 | { | |
557 | return m_superClassInstance ; | |
558 | } | |
559 | private : | |
560 | // removes an existing runtime-property | |
561 | void RemoveProperty( const wxChar *propertyName ) ; | |
562 | ||
563 | // renames an existing runtime-property | |
564 | void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; | |
565 | ||
566 | wxObject *m_superClassInstance ; | |
567 | const wxDynamicClassInfo *m_classInfo; | |
568 | struct wxDynamicObjectInternal; | |
569 | wxDynamicObjectInternal *m_data; | |
570 | }; | |
571 | #endif | |
572 | ||
573 | // ---------------------------------------------------------------------------- | |
574 | // more debugging macros | |
575 | // ---------------------------------------------------------------------------- | |
576 | ||
577 | #ifdef __WXDEBUG__ | |
578 | #ifndef WXDEBUG_NEW | |
579 | #define WXDEBUG_NEW new(__TFILE__,__LINE__) | |
580 | #endif | |
581 | #else // !__WXDEBUG__ | |
582 | #define WXDEBUG_NEW new | |
583 | #endif | |
584 | ||
585 | // Redefine new to be the debugging version. This doesn't work with all | |
586 | // compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish | |
587 | // to use the debugging version. | |
588 | ||
589 | #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS | |
590 | #define new new(__TFILE__,__LINE__) | |
591 | #endif | |
592 | ||
593 | #endif // _WX_OBJECTH__ | |
594 |