]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: object.h | |
e54c96f1 | 3 | // Purpose: interface of wxObjectRefData |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxObjectRefData | |
7c913512 | 11 | |
b64d83f5 | 12 | This class is used to store reference-counted data. |
7c913512 | 13 | |
b64d83f5 FM |
14 | Derive classes from this to store your own data. When retrieving information |
15 | from a wxObject's reference data, you will need to cast to your own derived class. | |
cfa9866b FM |
16 | |
17 | @b Example: | |
18 | ||
19 | @code | |
20 | // include file | |
21 | ||
22 | class MyCar: public wxObject | |
23 | { | |
24 | public: | |
25 | MyCar() { } | |
26 | MyCar( int price ); | |
27 | ||
28 | bool IsOk() const { return m_refData != NULL; } | |
29 | ||
30 | bool operator == ( const MyCar& car ) const; | |
31 | bool operator != (const MyCar& car) const { return !(*this == car); } | |
32 | ||
33 | void SetPrice( int price ); | |
34 | int GetPrice() const; | |
35 | ||
36 | protected: | |
37 | virtual wxObjectRefData *CreateRefData() const; | |
38 | virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; | |
39 | ||
40 | DECLARE_DYNAMIC_CLASS(MyCar) | |
41 | }; | |
42 | ||
43 | ||
44 | // implementation | |
45 | ||
46 | class MyCarRefData: public wxObjectRefData | |
47 | { | |
48 | public: | |
49 | MyCarRefData() | |
50 | { | |
51 | m_price = 0; | |
52 | } | |
53 | ||
54 | MyCarRefData( const MyCarRefData& data ) | |
55 | : wxObjectRefData() | |
56 | { | |
57 | m_price = data.m_price; | |
58 | } | |
59 | ||
60 | bool operator == (const MyCarRefData& data) const | |
61 | { | |
62 | return m_price == data.m_price; | |
63 | } | |
64 | ||
65 | int m_price; | |
66 | }; | |
67 | ||
68 | ||
69 | #define M_CARDATA ((MyCarRefData *)m_refData) | |
70 | ||
71 | IMPLEMENT_DYNAMIC_CLASS(MyCar,wxObject) | |
72 | ||
73 | MyCar::MyCar( int price ) | |
74 | { | |
75 | m_refData = new MyCarRefData(); | |
76 | M_CARDATA->m_price = price; | |
77 | } | |
78 | ||
79 | wxObjectRefData *MyCar::CreateRefData() const | |
80 | { | |
81 | return new MyCarRefData; | |
82 | } | |
83 | ||
84 | wxObjectRefData *MyCar::CloneRefData(const wxObjectRefData *data) const | |
85 | { | |
86 | return new MyCarRefData(*(MyCarRefData *)data); | |
87 | } | |
88 | ||
89 | bool MyCar::operator == ( const MyCar& car ) const | |
90 | { | |
91 | if (m_refData == car.m_refData) return true; | |
92 | ||
93 | if (!m_refData || !car.m_refData) return false; | |
94 | ||
95 | return ( *(MyCarRefData*)m_refData == *(MyCarRefData*)car.m_refData ); | |
96 | } | |
97 | ||
98 | void MyCar::SetPrice( int price ) | |
99 | { | |
100 | UnShare(); | |
101 | ||
102 | M_CARDATA->m_price = price; | |
103 | } | |
104 | ||
105 | int MyCar::GetPrice() const | |
106 | { | |
107 | wxCHECK_MSG( IsOk(), -1, "invalid car" ); | |
108 | ||
109 | return (M_CARDATA->m_price); | |
110 | } | |
111 | @endcode | |
7c913512 | 112 | |
b64d83f5 FM |
113 | |
114 | @library{wxbase} | |
115 | @category{rtti} | |
116 | ||
117 | @see wxObject, wxObjectDataPtr<T>, @ref overview_refcount | |
23324ae1 | 118 | */ |
7c913512 | 119 | class wxObjectRefData |
23324ae1 | 120 | { |
b64d83f5 | 121 | protected: |
23324ae1 | 122 | /** |
b64d83f5 FM |
123 | Destructor. |
124 | ||
125 | It's declared @c protected so that wxObjectRefData instances | |
126 | will never be destroyed directly but only as result of a DecRef() call. | |
23324ae1 | 127 | */ |
0004982c | 128 | virtual ~wxObjectRefData(); |
23324ae1 | 129 | |
b64d83f5 | 130 | public: |
23324ae1 | 131 | /** |
b64d83f5 | 132 | Default constructor. Initialises the internal reference count to 1. |
23324ae1 | 133 | */ |
b64d83f5 | 134 | wxObjectRefData(); |
23324ae1 FM |
135 | |
136 | /** | |
cfa9866b FM |
137 | Decrements the reference count associated with this shared data and, if |
138 | it reaches zero, destroys this instance of wxObjectRefData releasing its | |
139 | memory. | |
140 | ||
141 | Please note that after calling this function, the caller should | |
142 | absolutely avoid to use the pointer to this instance since it may not be | |
143 | valid anymore. | |
23324ae1 FM |
144 | */ |
145 | void DecRef(); | |
146 | ||
147 | /** | |
148 | Returns the reference count associated with this shared data. | |
b64d83f5 FM |
149 | |
150 | When this goes to zero during a DecRef() call, the object will auto-free itself. | |
23324ae1 | 151 | */ |
328f5751 | 152 | int GetRefCount() const; |
23324ae1 FM |
153 | |
154 | /** | |
155 | Increments the reference count associated with this shared data. | |
156 | */ | |
157 | void IncRef(); | |
158 | }; | |
159 | ||
160 | ||
e54c96f1 | 161 | |
23324ae1 FM |
162 | /** |
163 | @class wxObject | |
7c913512 | 164 | |
23324ae1 | 165 | This is the root class of many of the wxWidgets classes. |
b64d83f5 | 166 | |
cfa9866b FM |
167 | It declares a virtual destructor which ensures that destructors get called |
168 | for all derived class objects where necessary. | |
7c913512 | 169 | |
cfa9866b FM |
170 | wxObject is the hub of a dynamic object creation scheme, enabling a program |
171 | to create instances of a class only knowing its string class name, and to | |
172 | query the class hierarchy. | |
7c913512 | 173 | |
cfa9866b FM |
174 | The class contains optional debugging versions of @b new and @b delete, which |
175 | can help trace memory allocation and deallocation problems. | |
7c913512 | 176 | |
cfa9866b | 177 | wxObject can be used to implement @ref overview_refcount "reference counted" |
b64d83f5 FM |
178 | objects, such as wxPen, wxBitmap and others |
179 | (see @ref overview_refcount_list "this list"). | |
7c913512 | 180 | |
23324ae1 FM |
181 | @library{wxbase} |
182 | @category{rtti} | |
7c913512 | 183 | |
cfa9866b | 184 | @see wxClassInfo, @ref overview_debugging, wxObjectRefData |
23324ae1 | 185 | */ |
7c913512 | 186 | class wxObject |
23324ae1 FM |
187 | { |
188 | public: | |
cfa9866b FM |
189 | |
190 | wxObject(); | |
b64d83f5 | 191 | |
23324ae1 | 192 | /** |
b64d83f5 | 193 | Copy ctor. |
23324ae1 | 194 | */ |
7c913512 | 195 | wxObject(const wxObject& other); |
cfa9866b | 196 | |
23324ae1 FM |
197 | |
198 | /** | |
b64d83f5 FM |
199 | Destructor. |
200 | ||
201 | Performs dereferencing, for those objects that use reference counting. | |
23324ae1 | 202 | */ |
adaaa686 | 203 | virtual ~wxObject(); |
23324ae1 | 204 | |
23324ae1 FM |
205 | /** |
206 | This virtual function is redefined for every class that requires run-time | |
b64d83f5 | 207 | type information, when using the ::DECLARE_CLASS macro (or similar). |
23324ae1 | 208 | */ |
adaaa686 | 209 | virtual wxClassInfo* GetClassInfo() const; |
23324ae1 FM |
210 | |
211 | /** | |
b64d83f5 | 212 | Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. |
3c4f71cc | 213 | |
b64d83f5 | 214 | @see Ref(), UnRef(), wxObject::m_refData, SetRefData(), wxObjectRefData |
23324ae1 | 215 | */ |
328f5751 | 216 | wxObjectRefData* GetRefData() const; |
23324ae1 FM |
217 | |
218 | /** | |
219 | Determines whether this class is a subclass of (or the same class as) | |
220 | the given class. | |
3c4f71cc | 221 | |
b64d83f5 FM |
222 | Example: |
223 | ||
224 | @code | |
225 | bool tmp = obj->IsKindOf(CLASSINFO(wxFrame)); | |
226 | @endcode | |
227 | ||
7c913512 | 228 | @param info |
4cc4bfaf | 229 | A pointer to a class information object, which may be obtained |
b64d83f5 | 230 | by using the ::CLASSINFO macro. |
3c4f71cc | 231 | |
d29a9a8a | 232 | @return @true if the class represented by info is the same class as this |
4cc4bfaf | 233 | one or is derived from it. |
23324ae1 | 234 | */ |
b7e94bd7 | 235 | bool IsKindOf(const wxClassInfo* info) const; |
23324ae1 FM |
236 | |
237 | /** | |
b64d83f5 FM |
238 | Returns @true if this object has the same data pointer as @a obj. |
239 | ||
240 | Notice that @true is returned if the data pointers are @NULL in both objects. | |
cfa9866b | 241 | |
b64d83f5 | 242 | This function only does a @e shallow comparison, i.e. it doesn't compare |
23324ae1 | 243 | the objects pointed to by the data pointers of these objects. |
b64d83f5 FM |
244 | |
245 | @see @ref overview_refcount | |
23324ae1 | 246 | */ |
b7e94bd7 | 247 | bool IsSameAs(const wxObject& obj) const; |
23324ae1 FM |
248 | |
249 | /** | |
b64d83f5 | 250 | Makes this object refer to the data in @a clone. |
3c4f71cc | 251 | |
7c913512 | 252 | @param clone |
4cc4bfaf | 253 | The object to 'clone'. |
3c4f71cc | 254 | |
23324ae1 | 255 | @remarks First this function calls UnRef() on itself to decrement |
b64d83f5 FM |
256 | (and perhaps free) the data it is currently referring to. |
257 | It then sets its own wxObject::m_refData to point to that of @a clone, | |
cfa9866b FM |
258 | and increments the reference count inside the data. |
259 | ||
b64d83f5 | 260 | @see UnRef(), SetRefData(), GetRefData(), wxObjectRefData |
23324ae1 | 261 | */ |
4cc4bfaf | 262 | void Ref(const wxObject& clone); |
23324ae1 FM |
263 | |
264 | /** | |
b64d83f5 | 265 | Sets the wxObject::m_refData pointer. |
3c4f71cc | 266 | |
b64d83f5 | 267 | @see Ref(), UnRef(), GetRefData(), wxObjectRefData |
23324ae1 FM |
268 | */ |
269 | void SetRefData(wxObjectRefData* data); | |
270 | ||
271 | /** | |
272 | Decrements the reference count in the associated data, and if it is zero, | |
273 | deletes the data. | |
3c4f71cc | 274 | |
b64d83f5 FM |
275 | The wxObject::m_refData member is set to @NULL. |
276 | ||
277 | @see Ref(), SetRefData(), GetRefData(), wxObjectRefData | |
23324ae1 FM |
278 | */ |
279 | void UnRef(); | |
280 | ||
281 | /** | |
282 | Ensure that this object's data is not shared with any other object. | |
3c4f71cc | 283 | |
cfa9866b FM |
284 | If we have no data, it is created using CreateRefData() below, |
285 | if we have shared data, it is copied using CloneRefData(), | |
286 | otherwise nothing is done. | |
23324ae1 | 287 | */ |
cfa9866b | 288 | void UnShare(); |
23324ae1 FM |
289 | |
290 | /** | |
291 | The @e delete operator is defined for debugging versions of the library only, | |
cfa9866b | 292 | when the identifier @c __WXDEBUG__ is defined. |
b64d83f5 | 293 | |
cfa9866b | 294 | It takes over memory deallocation, allowing wxDebugContext operations. |
23324ae1 | 295 | */ |
cfa9866b | 296 | void operator delete(void *buf); |
23324ae1 FM |
297 | |
298 | /** | |
299 | The @e new operator is defined for debugging versions of the library only, when | |
b64d83f5 FM |
300 | the identifier @c __WXDEBUG__ is defined. |
301 | ||
302 | It takes over memory allocation, allowing wxDebugContext operations. | |
23324ae1 | 303 | */ |
b64d83f5 | 304 | void* operator new(size_t size, const wxString& filename = NULL, int lineNum = 0); |
cfa9866b | 305 | |
b64d83f5 | 306 | protected: |
cfa9866b FM |
307 | |
308 | /** | |
309 | Pointer to an object which is the object's reference-counted data. | |
310 | ||
b64d83f5 | 311 | @see Ref(), UnRef(), SetRefData(), GetRefData(), wxObjectRefData |
cfa9866b FM |
312 | */ |
313 | wxObjectRefData* m_refData; | |
23324ae1 FM |
314 | }; |
315 | ||
316 | ||
e54c96f1 | 317 | |
23324ae1 FM |
318 | /** |
319 | @class wxClassInfo | |
7c913512 | 320 | |
b64d83f5 FM |
321 | This class stores meta-information about classes. |
322 | ||
323 | Instances of this class are not generally defined directly by an application, | |
324 | but indirectly through use of macros such as ::DECLARE_DYNAMIC_CLASS and | |
325 | ::IMPLEMENT_DYNAMIC_CLASS. | |
7c913512 | 326 | |
23324ae1 FM |
327 | @library{wxbase} |
328 | @category{rtti} | |
7c913512 | 329 | |
b64d83f5 | 330 | @see @ref overview_rtti_classinfo, wxObject |
23324ae1 | 331 | */ |
7c913512 | 332 | class wxClassInfo |
23324ae1 FM |
333 | { |
334 | public: | |
335 | /** | |
b64d83f5 FM |
336 | Constructs a wxClassInfo object. |
337 | ||
338 | The supplied macros implicitly construct objects of this class, so there is no | |
339 | need to create such objects explicitly in an application. | |
23324ae1 | 340 | */ |
4cc4bfaf FM |
341 | wxClassInfo(const wxChar* className, |
342 | const wxClassInfo* baseClass1, | |
343 | const wxClassInfo* baseClass2, | |
23324ae1 FM |
344 | int size, wxObjectConstructorFn fn); |
345 | ||
346 | /** | |
b64d83f5 FM |
347 | Creates an object of the appropriate kind. |
348 | ||
d29a9a8a | 349 | @return @NULL if the class has not been declared dynamically creatable |
b64d83f5 | 350 | (typically, this happens for abstract classes). |
23324ae1 | 351 | */ |
328f5751 | 352 | wxObject* CreateObject() const; |
23324ae1 FM |
353 | |
354 | /** | |
b64d83f5 | 355 | Finds the wxClassInfo object for a class with the given @a name. |
23324ae1 | 356 | */ |
4cc4bfaf | 357 | static wxClassInfo* FindClass(wxChar* name); |
23324ae1 FM |
358 | |
359 | /** | |
360 | Returns the name of the first base class (@NULL if none). | |
361 | */ | |
7323ff1a | 362 | const wxChar* GetBaseClassName1() const; |
23324ae1 FM |
363 | |
364 | /** | |
365 | Returns the name of the second base class (@NULL if none). | |
366 | */ | |
7323ff1a | 367 | const wxChar* GetBaseClassName2() const; |
23324ae1 FM |
368 | |
369 | /** | |
370 | Returns the string form of the class name. | |
371 | */ | |
7323ff1a | 372 | const wxChar* GetClassName() const; |
23324ae1 FM |
373 | |
374 | /** | |
375 | Returns the size of the class. | |
376 | */ | |
328f5751 | 377 | int GetSize() const; |
23324ae1 FM |
378 | |
379 | /** | |
b64d83f5 FM |
380 | Initializes pointers in the wxClassInfo objects for fast execution of IsKindOf(). |
381 | Called in base wxWidgets library initialization. | |
23324ae1 FM |
382 | */ |
383 | static void InitializeClasses(); | |
384 | ||
385 | /** | |
386 | Returns @true if this class info can create objects of the associated class. | |
387 | */ | |
328f5751 | 388 | bool IsDynamic() const; |
23324ae1 FM |
389 | |
390 | /** | |
391 | Returns @true if this class is a kind of (inherits from) the given class. | |
392 | */ | |
50ec54b6 | 393 | bool IsKindOf(const wxClassInfo* info) const; |
23324ae1 FM |
394 | }; |
395 | ||
396 | ||
e54c96f1 | 397 | |
23324ae1 | 398 | /** |
7c913512 | 399 | |
b64d83f5 FM |
400 | This is helper template class primarily written to avoid memory leaks because of |
401 | missing calls to wxObjectRefData::DecRef(). | |
7c913512 | 402 | |
b64d83f5 FM |
403 | Despite the name this template can actually be used as a smart pointer for any |
404 | class implementing the reference counting interface which only consists of the two | |
405 | methods @b T::IncRef() and @b T::DecRef(). | |
7c913512 | 406 | |
b64d83f5 FM |
407 | The difference to wxSharedPtr<T> is that wxObjectDataPtr<T> relies on the reference |
408 | counting to be in the class pointed to where instead wxSharedPtr<T> implements the | |
23324ae1 | 409 | reference counting itself. |
7c913512 | 410 | |
cfa9866b FM |
411 | |
412 | @b Example: | |
413 | ||
414 | @code | |
415 | class MyCarRefData: public wxObjectRefData | |
416 | { | |
417 | public: | |
418 | MyCarRefData() { m_price = 0; } | |
419 | ||
420 | MyCarRefData( const MyCarRefData& data ) | |
421 | : wxObjectRefData() | |
422 | { | |
423 | m_price = data.m_price; | |
424 | } | |
425 | ||
426 | void SetPrice( int price ) { m_price = price; } | |
427 | int GetPrice() { return m_price; } | |
428 | ||
429 | protected: | |
430 | int m_price; | |
431 | }; | |
432 | ||
433 | class MyCar | |
434 | { | |
435 | public: | |
436 | MyCar( int price ) : m_data( new MyCarRefData ) | |
437 | { | |
438 | m_data->SetPrice( price ); | |
439 | } | |
440 | ||
441 | MyCar& operator =( const MyCar& tocopy ) | |
442 | { | |
443 | m_data = tocopy.m_data; | |
444 | return *this; | |
445 | } | |
446 | ||
447 | bool operator == ( const MyCar& other ) const | |
448 | { | |
449 | if (m_data.get() == other.m_data.get()) return true; | |
450 | return (m_data->GetPrice() == other.m_data->GetPrice()); | |
451 | } | |
452 | ||
453 | void SetPrice( int price ) | |
454 | { | |
455 | UnShare(); | |
456 | m_data->SetPrice( price ); | |
457 | } | |
458 | ||
459 | int GetPrice() const | |
460 | { | |
461 | return m_data->GetPrice(); | |
462 | } | |
463 | ||
464 | wxObjectDataPtr<MyCarRefData> m_data; | |
465 | ||
466 | protected: | |
467 | void UnShare() | |
468 | { | |
469 | if (m_data->GetRefCount() == 1) | |
470 | return; | |
471 | ||
472 | m_data.reset( new MyCarRefData( *m_data ) ); | |
473 | } | |
474 | }; | |
cfa9866b | 475 | @endcode |
7c913512 | 476 | |
b64d83f5 FM |
477 | |
478 | @library{wxbase} | |
479 | @category{rtti,smartpointers} | |
480 | ||
481 | @see wxObject, wxObjectRefData, @ref overview_refcount, wxSharedPtr<T>, | |
482 | wxScopedPtr<T>, wxWeakRef<T> | |
23324ae1 | 483 | */ |
7c913512 | 484 | class wxObjectDataPtr<T> |
23324ae1 FM |
485 | { |
486 | public: | |
cfa9866b | 487 | /** |
b64d83f5 FM |
488 | Constructor. |
489 | ||
490 | @a ptr is a pointer to the reference counted object to which this class points. | |
cfa9866b FM |
491 | If @a ptr is not NULL @b T::IncRef() will be called on the object. |
492 | */ | |
493 | wxObjectDataPtr<T>(T* ptr = NULL); | |
494 | ||
23324ae1 | 495 | /** |
b64d83f5 FM |
496 | This copy constructor increases the count of the reference counted object to |
497 | which @a tocopy points and then this class will point to, as well. | |
23324ae1 | 498 | */ |
cfa9866b FM |
499 | wxObjectDataPtr<T>(const wxObjectDataPtr<T>& tocopy); |
500 | ||
23324ae1 FM |
501 | |
502 | /** | |
b64d83f5 | 503 | Decreases the reference count of the object to which this class points. |
23324ae1 | 504 | */ |
b64d83f5 | 505 | ~wxObjectDataPtr<T>(); |
23324ae1 FM |
506 | |
507 | /** | |
b64d83f5 | 508 | Gets a pointer to the reference counted object to which this class points. |
23324ae1 | 509 | */ |
328f5751 | 510 | T* get() const; |
23324ae1 | 511 | |
b64d83f5 FM |
512 | /** |
513 | Reset this class to ptr which points to a reference counted object and | |
514 | calls T::DecRef() on the previously owned object. | |
515 | */ | |
d3338a5a | 516 | void reset(T *ptr); |
b64d83f5 | 517 | |
23324ae1 | 518 | /** |
7c913512 | 519 | Conversion to a boolean expression (in a variant which is not |
b64d83f5 FM |
520 | convertable to anything but a boolean expression). |
521 | ||
522 | If this class contains a valid pointer it will return @true, if it contains | |
523 | a @NULL pointer it will return @false. | |
23324ae1 | 524 | */ |
328f5751 | 525 | operator unspecified_bool_type() const; |
23324ae1 FM |
526 | |
527 | /** | |
b64d83f5 FM |
528 | Returns a reference to the object. |
529 | ||
530 | If the internal pointer is @NULL this method will cause an assert in debug mode. | |
23324ae1 | 531 | */ |
cfa9866b | 532 | T& operator*() const; |
23324ae1 FM |
533 | |
534 | /** | |
b64d83f5 FM |
535 | Returns a pointer to the reference counted object to which this class points. |
536 | ||
537 | If this the internal pointer is @NULL, this method will assert in debug mode. | |
23324ae1 | 538 | */ |
b64d83f5 | 539 | T* operator->() const; |
23324ae1 FM |
540 | |
541 | //@{ | |
542 | /** | |
b64d83f5 | 543 | Assignment operator. |
23324ae1 | 544 | */ |
cfa9866b FM |
545 | wxObjectDataPtr<T>& operator=(const wxObjectDataPtr<T>& tocopy); |
546 | wxObjectDataPtr<T>& operator=(T* ptr); | |
23324ae1 FM |
547 | //@} |
548 | }; | |
549 | ||
550 | ||
e54c96f1 | 551 | |
23324ae1 FM |
552 | // ============================================================================ |
553 | // Global functions/macros | |
554 | // ============================================================================ | |
555 | ||
8af7f7c1 BP |
556 | /** @ingroup group_funcmacro_rtti */ |
557 | //@{ | |
558 | ||
23324ae1 | 559 | /** |
8af7f7c1 BP |
560 | Returns a pointer to the wxClassInfo object associated with this class. |
561 | ||
562 | @header{wx/object.h} | |
563 | */ | |
564 | #define CLASSINFO( className ) | |
565 | ||
566 | /** | |
567 | Used inside a class declaration to declare that the class should be made | |
568 | known to the class hierarchy, but objects of this class cannot be created | |
569 | dynamically. The same as DECLARE_ABSTRACT_CLASS(). | |
570 | ||
571 | @header{wx/object.h} | |
23324ae1 | 572 | */ |
8af7f7c1 | 573 | #define DECLARE_CLASS( className ) |
23324ae1 FM |
574 | |
575 | /** | |
576 | Used inside a class declaration to declare that the class should be | |
577 | made known to the class hierarchy, but objects of this class cannot be created | |
8af7f7c1 BP |
578 | dynamically. The same as DECLARE_CLASS(). |
579 | ||
580 | @header{wx/object.h} | |
581 | ||
23324ae1 | 582 | Example: |
4cc4bfaf | 583 | |
23324ae1 FM |
584 | @code |
585 | class wxCommand: public wxObject | |
586 | { | |
8af7f7c1 | 587 | DECLARE_ABSTRACT_CLASS(wxCommand) |
7c913512 | 588 | |
8af7f7c1 BP |
589 | private: |
590 | ... | |
591 | public: | |
592 | ... | |
23324ae1 FM |
593 | }; |
594 | @endcode | |
595 | */ | |
8af7f7c1 | 596 | #define DECLARE_ABSTRACT_CLASS( className ) |
23324ae1 FM |
597 | |
598 | /** | |
8af7f7c1 BP |
599 | Used inside a class declaration to make the class known to wxWidgets RTTI |
600 | system and also declare that the objects of this class should be | |
601 | dynamically creatable from run-time type information. Notice that this | |
602 | implies that the class should have a default constructor, if this is not | |
603 | the case consider using DECLARE_CLASS(). | |
23324ae1 | 604 | |
8af7f7c1 | 605 | @header{wx/object.h} |
7c913512 | 606 | |
8af7f7c1 BP |
607 | Example: |
608 | ||
609 | @code | |
610 | class wxFrame: public wxWindow | |
611 | { | |
612 | DECLARE_DYNAMIC_CLASS(wxFrame) | |
613 | ||
614 | private: | |
615 | const wxString& frameTitle; | |
616 | public: | |
617 | ... | |
618 | }; | |
619 | @endcode | |
23324ae1 | 620 | */ |
7baebf86 | 621 | #define DECLARE_DYNAMIC_CLASS( className ) |
23324ae1 FM |
622 | |
623 | /** | |
8af7f7c1 BP |
624 | Used in a C++ implementation file to complete the declaration of a class |
625 | that has run-time type information. The same as IMPLEMENT_ABSTRACT_CLASS(). | |
626 | ||
627 | @header{wx/object.h} | |
23324ae1 | 628 | */ |
8af7f7c1 | 629 | #define IMPLEMENT_CLASS( className, baseClassName ) |
23324ae1 FM |
630 | |
631 | /** | |
8af7f7c1 BP |
632 | Used in a C++ implementation file to complete the declaration of a class |
633 | that has run-time type information and two base classes. The same as | |
634 | IMPLEMENT_ABSTRACT_CLASS2(). | |
7c913512 | 635 | |
8af7f7c1 | 636 | @header{wx/object.h} |
23324ae1 | 637 | */ |
8af7f7c1 | 638 | #define IMPLEMENT_CLASS2( className, baseClassName1, baseClassName2 ) |
23324ae1 FM |
639 | |
640 | /** | |
8af7f7c1 BP |
641 | Used in a C++ implementation file to complete the declaration of a class |
642 | that has run-time type information. The same as IMPLEMENT_CLASS(). | |
643 | ||
644 | @header{wx/object.h} | |
645 | ||
23324ae1 | 646 | Example: |
4cc4bfaf | 647 | |
23324ae1 FM |
648 | @code |
649 | IMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject) | |
7c913512 | 650 | |
23324ae1 FM |
651 | wxCommand::wxCommand(void) |
652 | { | |
8af7f7c1 | 653 | ... |
23324ae1 FM |
654 | } |
655 | @endcode | |
656 | */ | |
8af7f7c1 | 657 | #define IMPLEMENT_ABSTRACT_CLASS( className, baseClassName ) |
23324ae1 FM |
658 | |
659 | /** | |
8af7f7c1 BP |
660 | Used in a C++ implementation file to complete the declaration of a class |
661 | that has run-time type information and two base classes. The same as | |
662 | IMPLEMENT_CLASS2(). | |
663 | ||
664 | @header{wx/object.h} | |
23324ae1 | 665 | */ |
8af7f7c1 | 666 | #define IMPLEMENT_ABSTRACT_CLASS2( className, baseClassName1, baseClassName2 ) |
23324ae1 FM |
667 | |
668 | /** | |
8af7f7c1 BP |
669 | Used in a C++ implementation file to complete the declaration of a class |
670 | that has run-time type information, and whose instances can be created | |
671 | dynamically. | |
7c913512 | 672 | |
8af7f7c1 BP |
673 | @header{wx/object.h} |
674 | ||
675 | Example: | |
676 | ||
677 | @code | |
678 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
679 | ||
680 | wxFrame::wxFrame(void) | |
681 | { | |
682 | ... | |
683 | } | |
684 | @endcode | |
23324ae1 | 685 | */ |
8af7f7c1 | 686 | #define IMPLEMENT_DYNAMIC_CLASS( className, baseClassName ) |
23324ae1 FM |
687 | |
688 | /** | |
8af7f7c1 BP |
689 | Used in a C++ implementation file to complete the declaration of a class |
690 | that has run-time type information, and whose instances can be created | |
691 | dynamically. Use this for classes derived from two base classes. | |
692 | ||
693 | @header{wx/object.h} | |
23324ae1 | 694 | */ |
8af7f7c1 | 695 | #define IMPLEMENT_DYNAMIC_CLASS2( className, baseClassName1, baseClassName2 ) |
23324ae1 FM |
696 | |
697 | /** | |
cfa9866b FM |
698 | Same as @c const_cast<T>(x) if the compiler supports const cast or @c (T)x for |
699 | old compilers. Unlike wxConstCast(), the cast it to the type @c T and not to | |
700 | <tt>T *</tt> and also the order of arguments is the same as for the standard cast. | |
8af7f7c1 BP |
701 | |
702 | @header{wx/defs.h} | |
703 | ||
704 | @see wx_reinterpret_cast(), wx_static_cast() | |
23324ae1 | 705 | */ |
8af7f7c1 | 706 | #define wx_const_cast(T, x) |
23324ae1 FM |
707 | |
708 | /** | |
cfa9866b FM |
709 | Same as @c reinterpret_cast<T>(x) if the compiler supports reinterpret cast or |
710 | @c (T)x for old compilers. | |
4cc4bfaf | 711 | |
8af7f7c1 | 712 | @header{wx/defs.h} |
7c913512 | 713 | |
8af7f7c1 | 714 | @see wx_const_cast(), wx_static_cast() |
23324ae1 | 715 | */ |
8af7f7c1 | 716 | #define wx_reinterpret_cast(T, x) |
23324ae1 FM |
717 | |
718 | /** | |
cfa9866b | 719 | Same as @c static_cast<T>(x) if the compiler supports static cast or @c (T)x for |
8af7f7c1 BP |
720 | old compilers. Unlike wxStaticCast(), there are no checks being done and |
721 | the meaning of the macro arguments is exactly the same as for the standard | |
cfa9866b | 722 | static cast, i.e. @a T is the full type name and star is not appended to it. |
7c913512 | 723 | |
8af7f7c1 BP |
724 | @header{wx/defs.h} |
725 | ||
726 | @see wx_const_cast(), wx_reinterpret_cast(), wx_truncate_cast() | |
23324ae1 | 727 | */ |
8af7f7c1 | 728 | #define wx_static_cast(T, x) |
23324ae1 FM |
729 | |
730 | /** | |
8af7f7c1 BP |
731 | This case doesn’t correspond to any standard cast but exists solely to make |
732 | casts which possibly result in a truncation of an integer value more | |
733 | readable. | |
734 | ||
735 | @header{wx/defs.h} | |
23324ae1 | 736 | */ |
8af7f7c1 | 737 | #define wx_truncate_cast(T, x) |
23324ae1 FM |
738 | |
739 | /** | |
cfa9866b | 740 | This macro expands into <tt>const_cast<classname *>(ptr)</tt> if the compiler |
8af7f7c1 | 741 | supports const_cast or into an old, C-style cast, otherwise. |
4cc4bfaf | 742 | |
8af7f7c1 | 743 | @header{wx/defs.h} |
7c913512 | 744 | |
8af7f7c1 | 745 | @see wx_const_cast(), wxDynamicCast(), wxStaticCast() |
23324ae1 | 746 | */ |
7baebf86 | 747 | #define wxConstCast( ptr, classname ) |
23324ae1 | 748 | |
23324ae1 | 749 | /** |
8af7f7c1 BP |
750 | This macro returns the pointer @e ptr cast to the type @e classname * if |
751 | the pointer is of this type (the check is done during the run-time) or | |
752 | @NULL otherwise. Usage of this macro is preferred over obsoleted | |
753 | wxObject::IsKindOf() function. | |
7c913512 | 754 | |
8af7f7c1 BP |
755 | The @e ptr argument may be @NULL, in which case @NULL will be returned. |
756 | ||
757 | @header{wx/object.h} | |
758 | ||
759 | Example: | |
760 | ||
761 | @code | |
762 | wxWindow *win = wxWindow::FindFocus(); | |
763 | wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl); | |
764 | if ( text ) | |
765 | { | |
766 | // a text control has the focus... | |
767 | } | |
768 | else | |
769 | { | |
770 | // no window has the focus or it is not a text control | |
771 | } | |
772 | @endcode | |
773 | ||
b64d83f5 | 774 | @see @ref overview_rtti, wxDynamicCastThis(), wxConstCast(), wxStaticCast() |
23324ae1 | 775 | */ |
7baebf86 | 776 | #define wxDynamicCast( ptr, classname ) |
23324ae1 FM |
777 | |
778 | /** | |
cfa9866b | 779 | This macro is equivalent to <tt>wxDynamicCast(this, classname)</tt> but the latter provokes |
8af7f7c1 BP |
780 | spurious compilation warnings from some compilers (because it tests whether |
781 | @c this pointer is non-@NULL which is always true), so this macro should be | |
782 | used to avoid them. | |
7c913512 | 783 | |
8af7f7c1 BP |
784 | @header{wx/object.h} |
785 | ||
786 | @see wxDynamicCast() | |
23324ae1 | 787 | */ |
7baebf86 | 788 | #define wxDynamicCastThis( classname ) |
23324ae1 FM |
789 | |
790 | /** | |
8af7f7c1 BP |
791 | This macro checks that the cast is valid in debug mode (an assert failure |
792 | will result if wxDynamicCast(ptr, classname) == @NULL) and then returns the | |
cfa9866b | 793 | result of executing an equivalent of <tt>static_cast<classname *>(ptr)</tt>. |
4cc4bfaf | 794 | |
8af7f7c1 | 795 | @header{wx/object.h} |
7c913512 | 796 | |
8af7f7c1 | 797 | @see wx_static_cast(), wxDynamicCast(), wxConstCast() |
23324ae1 | 798 | */ |
7baebf86 | 799 | #define wxStaticCast( ptr, classname ) |
8af7f7c1 BP |
800 | |
801 | /** | |
802 | Creates and returns an object of the given class, if the class has been | |
803 | registered with the dynamic class system using DECLARE... and IMPLEMENT... | |
804 | macros. | |
805 | ||
806 | @header{wx/object.h} | |
807 | */ | |
7baebf86 | 808 | wxObject *wxCreateDynamicObject(const wxString& className); |
8af7f7c1 BP |
809 | |
810 | //@} | |
23324ae1 | 811 | |
29f86fc1 BP |
812 | /** @ingroup group_funcmacro_debug */ |
813 | //@{ | |
814 | ||
815 | /** | |
816 | This is defined in debug mode to be call the redefined new operator | |
817 | with filename and line number arguments. The definition is: | |
818 | ||
819 | @code | |
820 | #define WXDEBUG_NEW new(__FILE__,__LINE__) | |
821 | @endcode | |
822 | ||
823 | In non-debug mode, this is defined as the normal new operator. | |
824 | ||
825 | @header{wx/object.h} | |
826 | */ | |
827 | #define WXDEBUG_NEW( arg ) | |
828 | ||
829 | //@} | |
830 |