]>
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> |
65571936 | 10 | // Licence: wxWindows licence |
c801d85f KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
34138703 JS |
13 | #ifndef _WX_OBJECTH__ |
14 | #define _WX_OBJECTH__ | |
c801d85f | 15 | |
0b9ab0bd RL |
16 | // ---------------------------------------------------------------------------- |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #include "wx/defs.h" |
e55ad60e | 21 | #include "wx/memory.h" |
c801d85f | 22 | |
bddd7a8d | 23 | class WXDLLIMPEXP_BASE wxObject; |
c801d85f | 24 | |
4393b50c | 25 | #ifndef wxUSE_EXTENDED_RTTI |
6d553b5f | 26 | #define wxUSE_EXTENDED_RTTI 0 |
a095505c SC |
27 | #endif |
28 | ||
6d553b5f | 29 | #if wxUSE_EXTENDED_RTTI |
a095505c | 30 | #include "wx/xti.h" |
a095505c SC |
31 | #else |
32 | ||
0b9ab0bd RL |
33 | // ---------------------------------------------------------------------------- |
34 | // conditional compilation | |
35 | // ---------------------------------------------------------------------------- | |
36 | ||
bddd7a8d VZ |
37 | class WXDLLIMPEXP_BASE wxClassInfo; |
38 | class WXDLLIMPEXP_BASE wxHashTable; | |
39 | class WXDLLIMPEXP_BASE wxObjectRefData; | |
c801d85f | 40 | |
0b9ab0bd RL |
41 | // ---------------------------------------------------------------------------- |
42 | // wxClassInfo | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | typedef wxObject *(*wxObjectConstructorFn)(void); | |
c801d85f | 46 | |
bddd7a8d | 47 | class WXDLLIMPEXP_BASE wxClassInfo |
c801d85f | 48 | { |
aac65598 | 49 | public: |
38befbee | 50 | wxClassInfo( const wxChar *className, |
d1d738f1 VS |
51 | const wxClassInfo *baseInfo1, |
52 | const wxClassInfo *baseInfo2, | |
38befbee RL |
53 | int size, |
54 | wxObjectConstructorFn ctor ) | |
0b9ab0bd | 55 | : m_className(className) |
0b9ab0bd RL |
56 | , m_objectSize(size) |
57 | , m_objectConstructor(ctor) | |
d1d738f1 VS |
58 | , m_baseInfo1(baseInfo1) |
59 | , m_baseInfo2(baseInfo2) | |
0b9ab0bd | 60 | , m_next(sm_first) |
7e548f6b | 61 | { |
d1d738f1 VS |
62 | sm_first = this; |
63 | Register(); | |
64 | } | |
0b9ab0bd | 65 | |
aa4b7ef9 | 66 | ~wxClassInfo(); |
1d2eddff | 67 | |
0b9ab0bd RL |
68 | wxObject *CreateObject() { return m_objectConstructor ? (*m_objectConstructor)() : 0; } |
69 | ||
70 | const wxChar *GetClassName() const { return m_className; } | |
469349b5 MB |
71 | const wxChar *GetBaseClassName1() const |
72 | { return m_baseInfo1 ? m_baseInfo1->GetClassName() : NULL; } | |
73 | const wxChar *GetBaseClassName2() const | |
74 | { return m_baseInfo2 ? m_baseInfo2->GetClassName() : NULL; } | |
0b9ab0bd RL |
75 | const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; } |
76 | const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; } | |
77 | int GetSize() const { return m_objectSize; } | |
78 | ||
79 | wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
80 | static const wxClassInfo *GetFirst() { return sm_first; } | |
81 | const wxClassInfo *GetNext() const { return m_next; } | |
82 | static wxClassInfo *FindClass(const wxChar *className); | |
807d8487 | 83 | |
0b9ab0bd RL |
84 | // Climb upwards through inheritance hierarchy. |
85 | // Dual inheritance is catered for. | |
86 | ||
87 | bool IsKindOf(const wxClassInfo *info) const | |
88 | { | |
89 | return info != 0 && | |
90 | ( info == this || | |
91 | ( m_baseInfo1 && m_baseInfo1->IsKindOf(info) ) || | |
92 | ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) ); | |
93 | } | |
3f4a0c5b | 94 | |
45bbbc54 | 95 | #if WXWIN_COMPATIBILITY_2_4 |
d1d738f1 | 96 | // Initializes parent pointers and hash table for fast searching. |
45bbbc54 | 97 | wxDEPRECATED( static void InitializeClasses() ); |
d1d738f1 | 98 | // Cleans up hash table used for fast searching. |
45bbbc54 | 99 | wxDEPRECATED( static void CleanUpClasses() ); |
cafc76a4 VS |
100 | #endif |
101 | static void CleanUp(); | |
7e548f6b | 102 | |
0c32066b | 103 | public: |
0b9ab0bd | 104 | const wxChar *m_className; |
0b9ab0bd RL |
105 | int m_objectSize; |
106 | wxObjectConstructorFn m_objectConstructor; | |
107 | ||
108 | // Pointers to base wxClassInfos: set in InitializeClasses | |
109 | ||
110 | const wxClassInfo *m_baseInfo1; | |
111 | const wxClassInfo *m_baseInfo2; | |
112 | ||
113 | // class info object live in a linked list: | |
114 | // pointers to its head and the next element in it | |
115 | ||
116 | static wxClassInfo *sm_first; | |
117 | wxClassInfo *m_next; | |
118 | ||
1f428942 VZ |
119 | // FIXME: this should be private (currently used directly by way too |
120 | // many clients) | |
0b9ab0bd | 121 | static wxHashTable *sm_classTable; |
1f428942 VZ |
122 | |
123 | private: | |
124 | // InitializeClasses() helper | |
125 | static wxClassInfo *GetBaseByName(const wxChar *name); | |
684242c6 GD |
126 | |
127 | DECLARE_NO_COPY_CLASS(wxClassInfo) | |
7e548f6b WS |
128 | |
129 | protected: | |
d1d738f1 VS |
130 | // registers the class |
131 | void Register(); | |
132 | void Unregister(); | |
c801d85f KB |
133 | }; |
134 | ||
bddd7a8d | 135 | WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); |
c801d85f | 136 | |
45bbbc54 | 137 | #if WXWIN_COMPATIBILITY_2_4 |
cafc76a4 VS |
138 | inline void wxClassInfo::InitializeClasses() {} |
139 | inline void wxClassInfo::CleanUpClasses() {} | |
140 | #endif | |
141 | ||
0b9ab0bd RL |
142 | // ---------------------------------------------------------------------------- |
143 | // Dynamic class macros | |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
14ca93a0 VZ |
146 | #define DECLARE_ABSTRACT_CLASS(name) \ |
147 | public: \ | |
148 | static wxClassInfo ms_classInfo; \ | |
149 | virtual wxClassInfo *GetClassInfo() const; | |
150 | ||
151 | #define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ | |
152 | DECLARE_NO_ASSIGN_CLASS(name) \ | |
fc7a2a60 VZ |
153 | DECLARE_DYNAMIC_CLASS(name) |
154 | ||
14ca93a0 VZ |
155 | #define DECLARE_DYNAMIC_CLASS_NO_COPY(name) \ |
156 | DECLARE_NO_COPY_CLASS(name) \ | |
fc7a2a60 VZ |
157 | DECLARE_DYNAMIC_CLASS(name) |
158 | ||
14ca93a0 VZ |
159 | #define DECLARE_DYNAMIC_CLASS(name) \ |
160 | DECLARE_ABSTRACT_CLASS(name) \ | |
161 | static wxObject* wxCreateObject(); | |
162 | ||
c801d85f KB |
163 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) |
164 | ||
14ca93a0 VZ |
165 | |
166 | // common part of the macros below | |
167 | #define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func) \ | |
168 | wxClassInfo name::ms_classInfo(wxT(#name), \ | |
169 | &basename::ms_classInfo, \ | |
170 | baseclsinfo2, \ | |
171 | (int) sizeof(name), \ | |
172 | (wxObjectConstructorFn) func); \ | |
173 | \ | |
174 | wxClassInfo *name::GetClassInfo() const \ | |
175 | { return &name::ms_classInfo; } | |
176 | ||
177 | #define wxIMPLEMENT_CLASS_COMMON1(name, basename, func) \ | |
178 | wxIMPLEMENT_CLASS_COMMON(name, basename, NULL, func) | |
179 | ||
180 | #define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func) \ | |
2b199a38 | 181 | wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func) |
14ca93a0 | 182 | |
0b9ab0bd RL |
183 | // ----------------------------------- |
184 | // for concrete classes | |
185 | // ----------------------------------- | |
186 | ||
187 | // Single inheritance with one base class | |
14ca93a0 VZ |
188 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ |
189 | wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject) \ | |
190 | wxObject* name::wxCreateObject() \ | |
191 | { return new name; } | |
c801d85f | 192 | |
0b9ab0bd | 193 | // Multiple inheritance with two base classes |
14ca93a0 VZ |
194 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \ |
195 | wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, \ | |
196 | name::wxCreateObject) \ | |
197 | wxObject* name::wxCreateObject() \ | |
198 | { return new name; } | |
c801d85f | 199 | |
0b9ab0bd RL |
200 | // ----------------------------------- |
201 | // for abstract classes | |
202 | // ----------------------------------- | |
c801d85f | 203 | |
0b9ab0bd RL |
204 | // Single inheritance with one base class |
205 | ||
14ca93a0 VZ |
206 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \ |
207 | wxIMPLEMENT_CLASS_COMMON1(name, basename, NULL) | |
0b9ab0bd RL |
208 | |
209 | // Multiple inheritance with two base classes | |
210 | ||
14ca93a0 VZ |
211 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ |
212 | wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, NULL) | |
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 | ||
c0db9626 | 287 | #define CLASSINFO(name) (&name::ms_classInfo) |
c801d85f | 288 | |
c0db9626 | 289 | #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::ms_classInfo) |
3013b6f4 | 290 | |
b2edef6f | 291 | // Just seems a bit nicer-looking (pretend it's not a macro) |
c0db9626 | 292 | #define wxIsKindOf(obj, className) obj->IsKindOf(&className::ms_classInfo) |
c801d85f | 293 | |
73fbb031 VZ |
294 | // this cast does some more checks at compile time as it uses static_cast |
295 | // internally | |
296 | // | |
297 | // note that it still has different semantics from dynamic_cast<> and so can't | |
298 | // be replaced by it as long as there are any compilers not supporting it | |
34636400 | 299 | #define wxDynamicCast(obj, className) \ |
5232d996 VZ |
300 | ((className *) wxCheckDynamicCast( \ |
301 | wx_const_cast(wxObject *, wx_static_cast(const wxObject *, \ | |
302 | wx_const_cast(className *, wx_static_cast(const className *, obj)))), \ | |
303 | &className::ms_classInfo)) | |
0b9ab0bd | 304 | |
b2edef6f VZ |
305 | // The 'this' pointer is always true, so use this version |
306 | // to cast the this pointer and avoid compiler warnings. | |
f7637829 | 307 | #define wxDynamicCastThis(className) \ |
73fbb031 | 308 | (IsKindOf(&className::ms_classInfo) ? (className *)(this) : (className *)0) |
33ac7e6f | 309 | |
f6bcfd97 | 310 | #ifdef __WXDEBUG__ |
e32d4836 | 311 | inline void* wxCheckCast(void *ptr) |
0b9ab0bd RL |
312 | { |
313 | wxASSERT_MSG( ptr, _T("wxStaticCast() used incorrectly") ); | |
e32d4836 | 314 | return ptr; |
0b9ab0bd RL |
315 | } |
316 | #define wxStaticCast(obj, className) \ | |
e32d4836 | 317 | ((className *)wxCheckCast(wxDynamicCast(obj, className))) |
f6bcfd97 | 318 | |
0b9ab0bd | 319 | #else // !__WXDEBUG__ |
ef0aea5a VZ |
320 | #define wxStaticCast(obj, className) \ |
321 | wx_const_cast(className *, wx_static_cast(const className *, obj)) | |
f6bcfd97 | 322 | |
0b9ab0bd | 323 | #endif // __WXDEBUG__ |
f6bcfd97 | 324 | |
b2edef6f VZ |
325 | // ---------------------------------------------------------------------------- |
326 | // set up memory debugging macros | |
327 | // ---------------------------------------------------------------------------- | |
328 | ||
329 | /* | |
330 | Which new/delete operator variants do we want? | |
331 | ||
332 | _WX_WANT_NEW_SIZET_WXCHAR_INT = void *operator new (size_t size, wxChar *fileName = 0, int lineNum = 0) | |
333 | _WX_WANT_DELETE_VOID = void operator delete (void * buf) | |
334 | _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET = void operator delete (void *buf, const char *_fname, size_t _line) | |
335 | _WX_WANT_DELETE_VOID_WXCHAR_INT = void operator delete(void *buf, wxChar*, int) | |
336 | _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT = void *operator new[] (size_t size, wxChar *fileName , int lineNum = 0) | |
337 | _WX_WANT_ARRAY_DELETE_VOID = void operator delete[] (void *buf) | |
338 | _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT = void operator delete[] (void* buf, wxChar*, int ) | |
339 | */ | |
340 | ||
341 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING | |
342 | ||
343 | // All compilers get this one | |
344 | #define _WX_WANT_NEW_SIZET_WXCHAR_INT | |
345 | ||
346 | // Everyone except Visage gets the next one | |
347 | #ifndef __VISAGECPP__ | |
348 | #define _WX_WANT_DELETE_VOID | |
c801d85f | 349 | #endif |
b2edef6f VZ |
350 | |
351 | // Only visage gets this one under the correct circumstances | |
352 | #if defined(__VISAGECPP__) && __DEBUG_ALLOC__ | |
353 | #define _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET | |
354 | #endif | |
355 | ||
356 | // Only VC++ 6.0 and CodeWarrior compilers get overloaded delete that matches new | |
684242c6 | 357 | #if ( defined(__VISUALC__) && (__VISUALC__ >= 1200) ) || (defined(__MWERKS__) && (__MWERKS__ >= 0x2400)) |
b2edef6f | 358 | #define _WX_WANT_DELETE_VOID_WXCHAR_INT |
fd85b064 | 359 | #endif |
c801d85f | 360 | |
b2edef6f VZ |
361 | // Now see who (if anyone) gets the array memory operators |
362 | #if wxUSE_ARRAY_MEMORY_OPERATORS | |
363 | ||
364 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
365 | #if !defined(__VISUALC__) | |
366 | #define _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT | |
367 | #endif | |
368 | ||
369 | // Everyone except Visual C++ (cause problems for VC++ - crashes) | |
370 | #if !defined(__VISUALC__) | |
371 | #define _WX_WANT_ARRAY_DELETE_VOID | |
372 | #endif | |
373 | ||
374 | // Only CodeWarrior 6 or higher | |
375 | #if defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
376 | #define _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT | |
377 | #endif | |
378 | ||
379 | #endif // wxUSE_ARRAY_MEMORY_OPERATORS | |
380 | ||
e755eb67 | 381 | #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING |
b2edef6f | 382 | |
0b9ab0bd | 383 | // ---------------------------------------------------------------------------- |
77ffb593 | 384 | // wxObject: the root class of wxWidgets object hierarchy |
0b9ab0bd RL |
385 | // ---------------------------------------------------------------------------- |
386 | ||
bddd7a8d | 387 | class WXDLLIMPEXP_BASE wxObject |
c801d85f | 388 | { |
684242c6 | 389 | DECLARE_ABSTRACT_CLASS(wxObject) |
c801d85f | 390 | |
a6391d30 GD |
391 | private: |
392 | void InitFrom(const wxObject& other); | |
4393b50c | 393 | |
0b9ab0bd | 394 | public: |
b2edef6f | 395 | wxObject() { m_refData = NULL; } |
0b9ab0bd | 396 | virtual ~wxObject() { UnRef(); } |
4393b50c | 397 | |
a6391d30 | 398 | wxObject(const wxObject& other) |
66e9a9f0 WS |
399 | { |
400 | InitFrom(other); | |
401 | } | |
4393b50c | 402 | |
a6391d30 GD |
403 | wxObject& operator=(const wxObject& other) |
404 | { | |
405 | if ( this != &other ) | |
406 | { | |
407 | UnRef(); | |
408 | InitFrom(other); | |
409 | } | |
410 | return *this; | |
411 | } | |
412 | ||
0b9ab0bd | 413 | bool IsKindOf(wxClassInfo *info) const; |
c801d85f | 414 | |
0b9ab0bd | 415 | |
b2edef6f VZ |
416 | // Turn on the correct set of new and delete operators |
417 | ||
418 | #ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT | |
cf760e4c | 419 | void *operator new ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); |
0b9ab0bd | 420 | #endif |
27198be4 | 421 | |
b2edef6f VZ |
422 | #ifdef _WX_WANT_DELETE_VOID |
423 | void operator delete ( void * buf ); | |
424 | #endif | |
0b9ab0bd | 425 | |
b2edef6f VZ |
426 | #ifdef _WX_WANT_DELETE_VOID_CONSTCHAR_SIZET |
427 | void operator delete ( void *buf, const char *_fname, size_t _line ); | |
0b9ab0bd | 428 | #endif |
76626af2 | 429 | |
b2edef6f | 430 | #ifdef _WX_WANT_DELETE_VOID_WXCHAR_INT |
cf760e4c | 431 | void operator delete ( void *buf, const wxChar*, int ); |
b2edef6f | 432 | #endif |
8cfc5426 | 433 | |
b2edef6f | 434 | #ifdef _WX_WANT_ARRAY_NEW_SIZET_WXCHAR_INT |
cf760e4c | 435 | void *operator new[] ( size_t size, const wxChar *fileName = NULL, int lineNum = 0 ); |
0b9ab0bd RL |
436 | #endif |
437 | ||
b2edef6f VZ |
438 | #ifdef _WX_WANT_ARRAY_DELETE_VOID |
439 | void operator delete[] ( void *buf ); | |
0b9ab0bd | 440 | #endif |
27198be4 | 441 | |
b2edef6f | 442 | #ifdef _WX_WANT_ARRAY_DELETE_VOID_WXCHAR_INT |
cf760e4c | 443 | void operator delete[] (void* buf, const wxChar*, int ); |
b2edef6f | 444 | #endif |
c801d85f | 445 | |
807d8487 VZ |
446 | // ref counted data handling methods |
447 | ||
448 | // get/set | |
449 | wxObjectRefData *GetRefData() const { return m_refData; } | |
450 | void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
451 | ||
452 | // make a 'clone' of the object | |
0b9ab0bd | 453 | void Ref(const wxObject& clone); |
c801d85f | 454 | |
807d8487 | 455 | // destroy a reference |
0b9ab0bd | 456 | void UnRef(); |
c801d85f | 457 | |
48710795 RR |
458 | |
459 | // Reserved for future use | |
460 | virtual void ReservedObjectFunc1() {} | |
461 | virtual void ReservedObjectFunc2() {} | |
462 | virtual void ReservedObjectFunc3() {} | |
463 | virtual void ReservedObjectFunc4() {} | |
464 | virtual void ReservedObjectFunc5() {} | |
465 | virtual void ReservedObjectFunc6() {} | |
466 | virtual void ReservedObjectFunc7() {} | |
467 | virtual void ReservedObjectFunc8() {} | |
468 | virtual void ReservedObjectFunc9() {} | |
469 | ||
c801d85f | 470 | protected: |
807d8487 VZ |
471 | // ensure that our data is not shared with anybody else: if we have no |
472 | // data, it is created using CreateRefData() below, if we have shared data | |
473 | // it is copied using CloneRefData(), otherwise nothing is done | |
474 | void AllocExclusive(); | |
475 | ||
476 | // both methods must be implemented if Unshare() is used, not pure virtual | |
477 | // only because of the backwards compatibility reasons | |
478 | ||
479 | // create a new m_refData | |
480 | virtual wxObjectRefData *CreateRefData() const; | |
481 | ||
482 | // create a new m_refData initialized with the given one | |
b8027888 | 483 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; |
807d8487 | 484 | |
0b9ab0bd | 485 | wxObjectRefData *m_refData; |
c801d85f KB |
486 | }; |
487 | ||
b2edef6f VZ |
488 | // ---------------------------------------------------------------------------- |
489 | // wxObjectRefData: ref counted data meant to be stored in wxObject | |
490 | // ---------------------------------------------------------------------------- | |
c801d85f | 491 | |
bddd7a8d | 492 | class WXDLLIMPEXP_BASE wxObjectRefData |
0b9ab0bd | 493 | { |
bddd7a8d | 494 | friend class WXDLLIMPEXP_BASE wxObject; |
c801d85f KB |
495 | |
496 | public: | |
b2edef6f VZ |
497 | wxObjectRefData() : m_count(1) { } |
498 | virtual ~wxObjectRefData() { } | |
499 | ||
500 | int GetRefCount() const { return m_count; } | |
c801d85f | 501 | |
c801d85f KB |
502 | private: |
503 | int m_count; | |
504 | }; | |
505 | ||
0b9ab0bd | 506 | |
ea1e6c4b RL |
507 | inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) |
508 | { | |
b2edef6f | 509 | return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL; |
ea1e6c4b RL |
510 | } |
511 | ||
2d51f067 SC |
512 | #if wxUSE_EXTENDED_RTTI |
513 | class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject | |
514 | { | |
8f2b1cfd | 515 | friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ; |
2d51f067 SC |
516 | public: |
517 | // instantiates this object with an instance of its superclass | |
518 | wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ; | |
519 | ~wxDynamicObject(); | |
520 | ||
8f2b1cfd SC |
521 | void SetProperty (const wxChar *propertyName, const wxxVariant &value); |
522 | wxxVariant GetProperty (const wxChar *propertyName) const ; | |
2d51f067 SC |
523 | |
524 | // get the runtime identity of this object | |
525 | wxClassInfo *GetClassInfo() const | |
526 | { | |
f525dc35 JS |
527 | #ifdef _MSC_VER |
528 | return (wxClassInfo*) m_classInfo; | |
529 | #else | |
7e548f6b | 530 | return wx_const_cast(wxClassInfo *, m_classInfo); |
f525dc35 | 531 | #endif |
2d51f067 SC |
532 | } |
533 | ||
534 | wxObject* GetSuperClassInstance() const | |
535 | { | |
536 | return m_superClassInstance ; | |
537 | } | |
538 | private : | |
8f2b1cfd SC |
539 | // removes an existing runtime-property |
540 | void RemoveProperty( const wxChar *propertyName ) ; | |
541 | ||
542 | // renames an existing runtime-property | |
543 | void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; | |
544 | ||
2d51f067 SC |
545 | wxObject *m_superClassInstance ; |
546 | const wxDynamicClassInfo *m_classInfo; | |
547 | struct wxDynamicObjectInternal; | |
548 | wxDynamicObjectInternal *m_data; | |
549 | }; | |
550 | #endif | |
551 | ||
b2edef6f VZ |
552 | // ---------------------------------------------------------------------------- |
553 | // more debugging macros | |
554 | // ---------------------------------------------------------------------------- | |
555 | ||
7fe7d506 | 556 | #ifdef __WXDEBUG__ |
b2edef6f VZ |
557 | #ifndef WXDEBUG_NEW |
558 | #define WXDEBUG_NEW new(__TFILE__,__LINE__) | |
559 | #endif | |
560 | #else // !__WXDEBUG__ | |
561 | #define WXDEBUG_NEW new | |
7fe7d506 JS |
562 | #endif |
563 | ||
b2edef6f VZ |
564 | // Redefine new to be the debugging version. This doesn't work with all |
565 | // compilers, in which case you need to use WXDEBUG_NEW explicitly if you wish | |
566 | // to use the debugging version. | |
7fe7d506 JS |
567 | |
568 | #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS | |
b2edef6f | 569 | #define new new(__TFILE__,__LINE__) |
70dfc4ed | 570 | #elif (defined(__WXDEBUG__) && defined(__VISUALC__) && !wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS) |
c86abb56 JS |
571 | // Including this file redefines new and allows leak reports to contain line numbers |
572 | #include "wx/msw/msvcrt.h" | |
c801d85f KB |
573 | #endif |
574 | ||
c0089c96 | 575 | #endif // _WX_OBJECTH__ |