]>
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 | */ |
b64d83f5 | 128 | ~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 FM |
204 | |
205 | /** | |
206 | A virtual function that may be redefined by derived classes to allow dumping of | |
207 | memory states. | |
cfa9866b | 208 | |
b64d83f5 FM |
209 | This function is only defined in debug build and exists only if @c __WXDEBUG__ |
210 | is defined. | |
3c4f71cc | 211 | |
7c913512 | 212 | @param stream |
4cc4bfaf | 213 | Stream on which to output dump information. |
3c4f71cc | 214 | |
b64d83f5 FM |
215 | @remarks Currently wxWidgets does not define Dump() for derived classes, |
216 | but programmers may wish to use it for their own applications. | |
217 | Be sure to call the Dump member of the class's base class to allow all | |
218 | information to be dumped. | |
cfa9866b FM |
219 | The implementation of this function in wxObject just writes |
220 | the class name of the object. | |
23324ae1 FM |
221 | */ |
222 | void Dump(ostream& stream); | |
223 | ||
224 | /** | |
225 | This virtual function is redefined for every class that requires run-time | |
b64d83f5 | 226 | type information, when using the ::DECLARE_CLASS macro (or similar). |
23324ae1 | 227 | */ |
adaaa686 | 228 | virtual wxClassInfo* GetClassInfo() const; |
23324ae1 FM |
229 | |
230 | /** | |
b64d83f5 | 231 | Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. |
3c4f71cc | 232 | |
b64d83f5 | 233 | @see Ref(), UnRef(), wxObject::m_refData, SetRefData(), wxObjectRefData |
23324ae1 | 234 | */ |
328f5751 | 235 | wxObjectRefData* GetRefData() const; |
23324ae1 FM |
236 | |
237 | /** | |
238 | Determines whether this class is a subclass of (or the same class as) | |
239 | the given class. | |
3c4f71cc | 240 | |
b64d83f5 FM |
241 | Example: |
242 | ||
243 | @code | |
244 | bool tmp = obj->IsKindOf(CLASSINFO(wxFrame)); | |
245 | @endcode | |
246 | ||
7c913512 | 247 | @param info |
4cc4bfaf | 248 | A pointer to a class information object, which may be obtained |
b64d83f5 | 249 | by using the ::CLASSINFO macro. |
3c4f71cc | 250 | |
d29a9a8a | 251 | @return @true if the class represented by info is the same class as this |
4cc4bfaf | 252 | one or is derived from it. |
23324ae1 | 253 | */ |
b7e94bd7 | 254 | bool IsKindOf(const wxClassInfo* info) const; |
23324ae1 FM |
255 | |
256 | /** | |
b64d83f5 FM |
257 | Returns @true if this object has the same data pointer as @a obj. |
258 | ||
259 | Notice that @true is returned if the data pointers are @NULL in both objects. | |
cfa9866b | 260 | |
b64d83f5 | 261 | This function only does a @e shallow comparison, i.e. it doesn't compare |
23324ae1 | 262 | the objects pointed to by the data pointers of these objects. |
b64d83f5 FM |
263 | |
264 | @see @ref overview_refcount | |
23324ae1 | 265 | */ |
b7e94bd7 | 266 | bool IsSameAs(const wxObject& obj) const; |
23324ae1 FM |
267 | |
268 | /** | |
b64d83f5 | 269 | Makes this object refer to the data in @a clone. |
3c4f71cc | 270 | |
7c913512 | 271 | @param clone |
4cc4bfaf | 272 | The object to 'clone'. |
3c4f71cc | 273 | |
23324ae1 | 274 | @remarks First this function calls UnRef() on itself to decrement |
b64d83f5 FM |
275 | (and perhaps free) the data it is currently referring to. |
276 | It then sets its own wxObject::m_refData to point to that of @a clone, | |
cfa9866b FM |
277 | and increments the reference count inside the data. |
278 | ||
b64d83f5 | 279 | @see UnRef(), SetRefData(), GetRefData(), wxObjectRefData |
23324ae1 | 280 | */ |
4cc4bfaf | 281 | void Ref(const wxObject& clone); |
23324ae1 FM |
282 | |
283 | /** | |
b64d83f5 | 284 | Sets the wxObject::m_refData pointer. |
3c4f71cc | 285 | |
b64d83f5 | 286 | @see Ref(), UnRef(), GetRefData(), wxObjectRefData |
23324ae1 FM |
287 | */ |
288 | void SetRefData(wxObjectRefData* data); | |
289 | ||
290 | /** | |
291 | Decrements the reference count in the associated data, and if it is zero, | |
292 | deletes the data. | |
3c4f71cc | 293 | |
b64d83f5 FM |
294 | The wxObject::m_refData member is set to @NULL. |
295 | ||
296 | @see Ref(), SetRefData(), GetRefData(), wxObjectRefData | |
23324ae1 FM |
297 | */ |
298 | void UnRef(); | |
299 | ||
300 | /** | |
301 | Ensure that this object's data is not shared with any other object. | |
3c4f71cc | 302 | |
cfa9866b FM |
303 | If we have no data, it is created using CreateRefData() below, |
304 | if we have shared data, it is copied using CloneRefData(), | |
305 | otherwise nothing is done. | |
23324ae1 | 306 | */ |
cfa9866b | 307 | void UnShare(); |
23324ae1 FM |
308 | |
309 | /** | |
310 | The @e delete operator is defined for debugging versions of the library only, | |
cfa9866b | 311 | when the identifier @c __WXDEBUG__ is defined. |
b64d83f5 | 312 | |
cfa9866b | 313 | It takes over memory deallocation, allowing wxDebugContext operations. |
23324ae1 | 314 | */ |
cfa9866b | 315 | void operator delete(void *buf); |
23324ae1 FM |
316 | |
317 | /** | |
318 | The @e new operator is defined for debugging versions of the library only, when | |
b64d83f5 FM |
319 | the identifier @c __WXDEBUG__ is defined. |
320 | ||
321 | It takes over memory allocation, allowing wxDebugContext operations. | |
23324ae1 | 322 | */ |
b64d83f5 | 323 | void* operator new(size_t size, const wxString& filename = NULL, int lineNum = 0); |
cfa9866b | 324 | |
b64d83f5 | 325 | protected: |
cfa9866b FM |
326 | |
327 | /** | |
328 | Pointer to an object which is the object's reference-counted data. | |
329 | ||
b64d83f5 | 330 | @see Ref(), UnRef(), SetRefData(), GetRefData(), wxObjectRefData |
cfa9866b FM |
331 | */ |
332 | wxObjectRefData* m_refData; | |
23324ae1 FM |
333 | }; |
334 | ||
335 | ||
e54c96f1 | 336 | |
23324ae1 FM |
337 | /** |
338 | @class wxClassInfo | |
7c913512 | 339 | |
b64d83f5 FM |
340 | This class stores meta-information about classes. |
341 | ||
342 | Instances of this class are not generally defined directly by an application, | |
343 | but indirectly through use of macros such as ::DECLARE_DYNAMIC_CLASS and | |
344 | ::IMPLEMENT_DYNAMIC_CLASS. | |
7c913512 | 345 | |
23324ae1 FM |
346 | @library{wxbase} |
347 | @category{rtti} | |
7c913512 | 348 | |
b64d83f5 | 349 | @see @ref overview_rtti_classinfo, wxObject |
23324ae1 | 350 | */ |
7c913512 | 351 | class wxClassInfo |
23324ae1 FM |
352 | { |
353 | public: | |
354 | /** | |
b64d83f5 FM |
355 | Constructs a wxClassInfo object. |
356 | ||
357 | The supplied macros implicitly construct objects of this class, so there is no | |
358 | need to create such objects explicitly in an application. | |
23324ae1 | 359 | */ |
4cc4bfaf FM |
360 | wxClassInfo(const wxChar* className, |
361 | const wxClassInfo* baseClass1, | |
362 | const wxClassInfo* baseClass2, | |
23324ae1 FM |
363 | int size, wxObjectConstructorFn fn); |
364 | ||
365 | /** | |
b64d83f5 FM |
366 | Creates an object of the appropriate kind. |
367 | ||
d29a9a8a | 368 | @return @NULL if the class has not been declared dynamically creatable |
b64d83f5 | 369 | (typically, this happens for abstract classes). |
23324ae1 | 370 | */ |
328f5751 | 371 | wxObject* CreateObject() const; |
23324ae1 FM |
372 | |
373 | /** | |
b64d83f5 | 374 | Finds the wxClassInfo object for a class with the given @a name. |
23324ae1 | 375 | */ |
4cc4bfaf | 376 | static wxClassInfo* FindClass(wxChar* name); |
23324ae1 FM |
377 | |
378 | /** | |
379 | Returns the name of the first base class (@NULL if none). | |
380 | */ | |
328f5751 | 381 | wxChar* GetBaseClassName1() const; |
23324ae1 FM |
382 | |
383 | /** | |
384 | Returns the name of the second base class (@NULL if none). | |
385 | */ | |
328f5751 | 386 | wxChar* GetBaseClassName2() const; |
23324ae1 FM |
387 | |
388 | /** | |
389 | Returns the string form of the class name. | |
390 | */ | |
328f5751 | 391 | wxChar* GetClassName() const; |
23324ae1 FM |
392 | |
393 | /** | |
394 | Returns the size of the class. | |
395 | */ | |
328f5751 | 396 | int GetSize() const; |
23324ae1 FM |
397 | |
398 | /** | |
b64d83f5 FM |
399 | Initializes pointers in the wxClassInfo objects for fast execution of IsKindOf(). |
400 | Called in base wxWidgets library initialization. | |
23324ae1 FM |
401 | */ |
402 | static void InitializeClasses(); | |
403 | ||
404 | /** | |
405 | Returns @true if this class info can create objects of the associated class. | |
406 | */ | |
328f5751 | 407 | bool IsDynamic() const; |
23324ae1 FM |
408 | |
409 | /** | |
410 | Returns @true if this class is a kind of (inherits from) the given class. | |
411 | */ | |
412 | bool IsKindOf(wxClassInfo* info); | |
413 | }; | |
414 | ||
415 | ||
e54c96f1 | 416 | |
23324ae1 | 417 | /** |
7c913512 | 418 | |
b64d83f5 FM |
419 | This is helper template class primarily written to avoid memory leaks because of |
420 | missing calls to wxObjectRefData::DecRef(). | |
7c913512 | 421 | |
b64d83f5 FM |
422 | Despite the name this template can actually be used as a smart pointer for any |
423 | class implementing the reference counting interface which only consists of the two | |
424 | methods @b T::IncRef() and @b T::DecRef(). | |
7c913512 | 425 | |
b64d83f5 FM |
426 | The difference to wxSharedPtr<T> is that wxObjectDataPtr<T> relies on the reference |
427 | counting to be in the class pointed to where instead wxSharedPtr<T> implements the | |
23324ae1 | 428 | reference counting itself. |
7c913512 | 429 | |
cfa9866b FM |
430 | |
431 | @b Example: | |
432 | ||
433 | @code | |
434 | class MyCarRefData: public wxObjectRefData | |
435 | { | |
436 | public: | |
437 | MyCarRefData() { m_price = 0; } | |
438 | ||
439 | MyCarRefData( const MyCarRefData& data ) | |
440 | : wxObjectRefData() | |
441 | { | |
442 | m_price = data.m_price; | |
443 | } | |
444 | ||
445 | void SetPrice( int price ) { m_price = price; } | |
446 | int GetPrice() { return m_price; } | |
447 | ||
448 | protected: | |
449 | int m_price; | |
450 | }; | |
451 | ||
452 | class MyCar | |
453 | { | |
454 | public: | |
455 | MyCar( int price ) : m_data( new MyCarRefData ) | |
456 | { | |
457 | m_data->SetPrice( price ); | |
458 | } | |
459 | ||
460 | MyCar& operator =( const MyCar& tocopy ) | |
461 | { | |
462 | m_data = tocopy.m_data; | |
463 | return *this; | |
464 | } | |
465 | ||
466 | bool operator == ( const MyCar& other ) const | |
467 | { | |
468 | if (m_data.get() == other.m_data.get()) return true; | |
469 | return (m_data->GetPrice() == other.m_data->GetPrice()); | |
470 | } | |
471 | ||
472 | void SetPrice( int price ) | |
473 | { | |
474 | UnShare(); | |
475 | m_data->SetPrice( price ); | |
476 | } | |
477 | ||
478 | int GetPrice() const | |
479 | { | |
480 | return m_data->GetPrice(); | |
481 | } | |
482 | ||
483 | wxObjectDataPtr<MyCarRefData> m_data; | |
484 | ||
485 | protected: | |
486 | void UnShare() | |
487 | { | |
488 | if (m_data->GetRefCount() == 1) | |
489 | return; | |
490 | ||
491 | m_data.reset( new MyCarRefData( *m_data ) ); | |
492 | } | |
493 | }; | |
cfa9866b | 494 | @endcode |
7c913512 | 495 | |
b64d83f5 FM |
496 | |
497 | @library{wxbase} | |
498 | @category{rtti,smartpointers} | |
499 | ||
500 | @see wxObject, wxObjectRefData, @ref overview_refcount, wxSharedPtr<T>, | |
501 | wxScopedPtr<T>, wxWeakRef<T> | |
23324ae1 | 502 | */ |
7c913512 | 503 | class wxObjectDataPtr<T> |
23324ae1 FM |
504 | { |
505 | public: | |
cfa9866b | 506 | /** |
b64d83f5 FM |
507 | Constructor. |
508 | ||
509 | @a ptr is a pointer to the reference counted object to which this class points. | |
cfa9866b FM |
510 | If @a ptr is not NULL @b T::IncRef() will be called on the object. |
511 | */ | |
512 | wxObjectDataPtr<T>(T* ptr = NULL); | |
513 | ||
23324ae1 | 514 | /** |
b64d83f5 FM |
515 | This copy constructor increases the count of the reference counted object to |
516 | which @a tocopy points and then this class will point to, as well. | |
23324ae1 | 517 | */ |
cfa9866b FM |
518 | wxObjectDataPtr<T>(const wxObjectDataPtr<T>& tocopy); |
519 | ||
23324ae1 FM |
520 | |
521 | /** | |
b64d83f5 | 522 | Decreases the reference count of the object to which this class points. |
23324ae1 | 523 | */ |
b64d83f5 | 524 | ~wxObjectDataPtr<T>(); |
23324ae1 FM |
525 | |
526 | /** | |
b64d83f5 | 527 | Gets a pointer to the reference counted object to which this class points. |
23324ae1 | 528 | */ |
328f5751 | 529 | T* get() const; |
23324ae1 | 530 | |
b64d83f5 FM |
531 | /** |
532 | Reset this class to ptr which points to a reference counted object and | |
533 | calls T::DecRef() on the previously owned object. | |
534 | */ | |
d3338a5a | 535 | void reset(T *ptr); |
b64d83f5 | 536 | |
23324ae1 | 537 | /** |
7c913512 | 538 | Conversion to a boolean expression (in a variant which is not |
b64d83f5 FM |
539 | convertable to anything but a boolean expression). |
540 | ||
541 | If this class contains a valid pointer it will return @true, if it contains | |
542 | a @NULL pointer it will return @false. | |
23324ae1 | 543 | */ |
328f5751 | 544 | operator unspecified_bool_type() const; |
23324ae1 FM |
545 | |
546 | /** | |
b64d83f5 FM |
547 | Returns a reference to the object. |
548 | ||
549 | If the internal pointer is @NULL this method will cause an assert in debug mode. | |
23324ae1 | 550 | */ |
cfa9866b | 551 | T& operator*() const; |
23324ae1 FM |
552 | |
553 | /** | |
b64d83f5 FM |
554 | Returns a pointer to the reference counted object to which this class points. |
555 | ||
556 | If this the internal pointer is @NULL, this method will assert in debug mode. | |
23324ae1 | 557 | */ |
b64d83f5 | 558 | T* operator->() const; |
23324ae1 FM |
559 | |
560 | //@{ | |
561 | /** | |
b64d83f5 | 562 | Assignment operator. |
23324ae1 | 563 | */ |
cfa9866b FM |
564 | wxObjectDataPtr<T>& operator=(const wxObjectDataPtr<T>& tocopy); |
565 | wxObjectDataPtr<T>& operator=(T* ptr); | |
23324ae1 FM |
566 | //@} |
567 | }; | |
568 | ||
569 | ||
e54c96f1 | 570 | |
23324ae1 FM |
571 | // ============================================================================ |
572 | // Global functions/macros | |
573 | // ============================================================================ | |
574 | ||
8af7f7c1 BP |
575 | /** @ingroup group_funcmacro_rtti */ |
576 | //@{ | |
577 | ||
23324ae1 | 578 | /** |
8af7f7c1 BP |
579 | Returns a pointer to the wxClassInfo object associated with this class. |
580 | ||
581 | @header{wx/object.h} | |
582 | */ | |
583 | #define CLASSINFO( className ) | |
584 | ||
585 | /** | |
586 | Used inside a class declaration to declare that the class should be made | |
587 | known to the class hierarchy, but objects of this class cannot be created | |
588 | dynamically. The same as DECLARE_ABSTRACT_CLASS(). | |
589 | ||
590 | @header{wx/object.h} | |
23324ae1 | 591 | */ |
8af7f7c1 | 592 | #define DECLARE_CLASS( className ) |
23324ae1 FM |
593 | |
594 | /** | |
595 | Used inside a class declaration to declare that the class should be | |
596 | made known to the class hierarchy, but objects of this class cannot be created | |
8af7f7c1 BP |
597 | dynamically. The same as DECLARE_CLASS(). |
598 | ||
599 | @header{wx/object.h} | |
600 | ||
23324ae1 | 601 | Example: |
4cc4bfaf | 602 | |
23324ae1 FM |
603 | @code |
604 | class wxCommand: public wxObject | |
605 | { | |
8af7f7c1 | 606 | DECLARE_ABSTRACT_CLASS(wxCommand) |
7c913512 | 607 | |
8af7f7c1 BP |
608 | private: |
609 | ... | |
610 | public: | |
611 | ... | |
23324ae1 FM |
612 | }; |
613 | @endcode | |
614 | */ | |
8af7f7c1 | 615 | #define DECLARE_ABSTRACT_CLASS( className ) |
23324ae1 FM |
616 | |
617 | /** | |
8af7f7c1 BP |
618 | Used inside a class declaration to make the class known to wxWidgets RTTI |
619 | system and also declare that the objects of this class should be | |
620 | dynamically creatable from run-time type information. Notice that this | |
621 | implies that the class should have a default constructor, if this is not | |
622 | the case consider using DECLARE_CLASS(). | |
23324ae1 | 623 | |
8af7f7c1 | 624 | @header{wx/object.h} |
7c913512 | 625 | |
8af7f7c1 BP |
626 | Example: |
627 | ||
628 | @code | |
629 | class wxFrame: public wxWindow | |
630 | { | |
631 | DECLARE_DYNAMIC_CLASS(wxFrame) | |
632 | ||
633 | private: | |
634 | const wxString& frameTitle; | |
635 | public: | |
636 | ... | |
637 | }; | |
638 | @endcode | |
23324ae1 | 639 | */ |
7baebf86 | 640 | #define DECLARE_DYNAMIC_CLASS( className ) |
23324ae1 FM |
641 | |
642 | /** | |
8af7f7c1 BP |
643 | Used in a C++ implementation file to complete the declaration of a class |
644 | that has run-time type information. The same as IMPLEMENT_ABSTRACT_CLASS(). | |
645 | ||
646 | @header{wx/object.h} | |
23324ae1 | 647 | */ |
8af7f7c1 | 648 | #define IMPLEMENT_CLASS( className, baseClassName ) |
23324ae1 FM |
649 | |
650 | /** | |
8af7f7c1 BP |
651 | Used in a C++ implementation file to complete the declaration of a class |
652 | that has run-time type information and two base classes. The same as | |
653 | IMPLEMENT_ABSTRACT_CLASS2(). | |
7c913512 | 654 | |
8af7f7c1 | 655 | @header{wx/object.h} |
23324ae1 | 656 | */ |
8af7f7c1 | 657 | #define IMPLEMENT_CLASS2( className, baseClassName1, baseClassName2 ) |
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. The same as IMPLEMENT_CLASS(). | |
662 | ||
663 | @header{wx/object.h} | |
664 | ||
23324ae1 | 665 | Example: |
4cc4bfaf | 666 | |
23324ae1 FM |
667 | @code |
668 | IMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject) | |
7c913512 | 669 | |
23324ae1 FM |
670 | wxCommand::wxCommand(void) |
671 | { | |
8af7f7c1 | 672 | ... |
23324ae1 FM |
673 | } |
674 | @endcode | |
675 | */ | |
8af7f7c1 | 676 | #define IMPLEMENT_ABSTRACT_CLASS( className, baseClassName ) |
23324ae1 FM |
677 | |
678 | /** | |
8af7f7c1 BP |
679 | Used in a C++ implementation file to complete the declaration of a class |
680 | that has run-time type information and two base classes. The same as | |
681 | IMPLEMENT_CLASS2(). | |
682 | ||
683 | @header{wx/object.h} | |
23324ae1 | 684 | */ |
8af7f7c1 | 685 | #define IMPLEMENT_ABSTRACT_CLASS2( className, baseClassName1, baseClassName2 ) |
23324ae1 FM |
686 | |
687 | /** | |
8af7f7c1 BP |
688 | Used in a C++ implementation file to complete the declaration of a class |
689 | that has run-time type information, and whose instances can be created | |
690 | dynamically. | |
7c913512 | 691 | |
8af7f7c1 BP |
692 | @header{wx/object.h} |
693 | ||
694 | Example: | |
695 | ||
696 | @code | |
697 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
698 | ||
699 | wxFrame::wxFrame(void) | |
700 | { | |
701 | ... | |
702 | } | |
703 | @endcode | |
23324ae1 | 704 | */ |
8af7f7c1 | 705 | #define IMPLEMENT_DYNAMIC_CLASS( className, baseClassName ) |
23324ae1 FM |
706 | |
707 | /** | |
8af7f7c1 BP |
708 | Used in a C++ implementation file to complete the declaration of a class |
709 | that has run-time type information, and whose instances can be created | |
710 | dynamically. Use this for classes derived from two base classes. | |
711 | ||
712 | @header{wx/object.h} | |
23324ae1 | 713 | */ |
8af7f7c1 | 714 | #define IMPLEMENT_DYNAMIC_CLASS2( className, baseClassName1, baseClassName2 ) |
23324ae1 FM |
715 | |
716 | /** | |
cfa9866b FM |
717 | Same as @c const_cast<T>(x) if the compiler supports const cast or @c (T)x for |
718 | old compilers. Unlike wxConstCast(), the cast it to the type @c T and not to | |
719 | <tt>T *</tt> and also the order of arguments is the same as for the standard cast. | |
8af7f7c1 BP |
720 | |
721 | @header{wx/defs.h} | |
722 | ||
723 | @see wx_reinterpret_cast(), wx_static_cast() | |
23324ae1 | 724 | */ |
8af7f7c1 | 725 | #define wx_const_cast(T, x) |
23324ae1 FM |
726 | |
727 | /** | |
cfa9866b FM |
728 | Same as @c reinterpret_cast<T>(x) if the compiler supports reinterpret cast or |
729 | @c (T)x for old compilers. | |
4cc4bfaf | 730 | |
8af7f7c1 | 731 | @header{wx/defs.h} |
7c913512 | 732 | |
8af7f7c1 | 733 | @see wx_const_cast(), wx_static_cast() |
23324ae1 | 734 | */ |
8af7f7c1 | 735 | #define wx_reinterpret_cast(T, x) |
23324ae1 FM |
736 | |
737 | /** | |
cfa9866b | 738 | Same as @c static_cast<T>(x) if the compiler supports static cast or @c (T)x for |
8af7f7c1 BP |
739 | old compilers. Unlike wxStaticCast(), there are no checks being done and |
740 | the meaning of the macro arguments is exactly the same as for the standard | |
cfa9866b | 741 | static cast, i.e. @a T is the full type name and star is not appended to it. |
7c913512 | 742 | |
8af7f7c1 BP |
743 | @header{wx/defs.h} |
744 | ||
745 | @see wx_const_cast(), wx_reinterpret_cast(), wx_truncate_cast() | |
23324ae1 | 746 | */ |
8af7f7c1 | 747 | #define wx_static_cast(T, x) |
23324ae1 FM |
748 | |
749 | /** | |
8af7f7c1 BP |
750 | This case doesn’t correspond to any standard cast but exists solely to make |
751 | casts which possibly result in a truncation of an integer value more | |
752 | readable. | |
753 | ||
754 | @header{wx/defs.h} | |
23324ae1 | 755 | */ |
8af7f7c1 | 756 | #define wx_truncate_cast(T, x) |
23324ae1 FM |
757 | |
758 | /** | |
cfa9866b | 759 | This macro expands into <tt>const_cast<classname *>(ptr)</tt> if the compiler |
8af7f7c1 | 760 | supports const_cast or into an old, C-style cast, otherwise. |
4cc4bfaf | 761 | |
8af7f7c1 | 762 | @header{wx/defs.h} |
7c913512 | 763 | |
8af7f7c1 | 764 | @see wx_const_cast(), wxDynamicCast(), wxStaticCast() |
23324ae1 | 765 | */ |
7baebf86 | 766 | #define wxConstCast( ptr, classname ) |
23324ae1 | 767 | |
23324ae1 | 768 | /** |
8af7f7c1 BP |
769 | This macro returns the pointer @e ptr cast to the type @e classname * if |
770 | the pointer is of this type (the check is done during the run-time) or | |
771 | @NULL otherwise. Usage of this macro is preferred over obsoleted | |
772 | wxObject::IsKindOf() function. | |
7c913512 | 773 | |
8af7f7c1 BP |
774 | The @e ptr argument may be @NULL, in which case @NULL will be returned. |
775 | ||
776 | @header{wx/object.h} | |
777 | ||
778 | Example: | |
779 | ||
780 | @code | |
781 | wxWindow *win = wxWindow::FindFocus(); | |
782 | wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl); | |
783 | if ( text ) | |
784 | { | |
785 | // a text control has the focus... | |
786 | } | |
787 | else | |
788 | { | |
789 | // no window has the focus or it is not a text control | |
790 | } | |
791 | @endcode | |
792 | ||
b64d83f5 | 793 | @see @ref overview_rtti, wxDynamicCastThis(), wxConstCast(), wxStaticCast() |
23324ae1 | 794 | */ |
7baebf86 | 795 | #define wxDynamicCast( ptr, classname ) |
23324ae1 FM |
796 | |
797 | /** | |
cfa9866b | 798 | This macro is equivalent to <tt>wxDynamicCast(this, classname)</tt> but the latter provokes |
8af7f7c1 BP |
799 | spurious compilation warnings from some compilers (because it tests whether |
800 | @c this pointer is non-@NULL which is always true), so this macro should be | |
801 | used to avoid them. | |
7c913512 | 802 | |
8af7f7c1 BP |
803 | @header{wx/object.h} |
804 | ||
805 | @see wxDynamicCast() | |
23324ae1 | 806 | */ |
7baebf86 | 807 | #define wxDynamicCastThis( classname ) |
23324ae1 FM |
808 | |
809 | /** | |
8af7f7c1 BP |
810 | This macro checks that the cast is valid in debug mode (an assert failure |
811 | will result if wxDynamicCast(ptr, classname) == @NULL) and then returns the | |
cfa9866b | 812 | result of executing an equivalent of <tt>static_cast<classname *>(ptr)</tt>. |
4cc4bfaf | 813 | |
8af7f7c1 | 814 | @header{wx/object.h} |
7c913512 | 815 | |
8af7f7c1 | 816 | @see wx_static_cast(), wxDynamicCast(), wxConstCast() |
23324ae1 | 817 | */ |
7baebf86 | 818 | #define wxStaticCast( ptr, classname ) |
8af7f7c1 BP |
819 | |
820 | /** | |
821 | Creates and returns an object of the given class, if the class has been | |
822 | registered with the dynamic class system using DECLARE... and IMPLEMENT... | |
823 | macros. | |
824 | ||
825 | @header{wx/object.h} | |
826 | */ | |
7baebf86 | 827 | wxObject *wxCreateDynamicObject(const wxString& className); |
8af7f7c1 BP |
828 | |
829 | //@} | |
23324ae1 | 830 | |
29f86fc1 BP |
831 | /** @ingroup group_funcmacro_debug */ |
832 | //@{ | |
833 | ||
834 | /** | |
835 | This is defined in debug mode to be call the redefined new operator | |
836 | with filename and line number arguments. The definition is: | |
837 | ||
838 | @code | |
839 | #define WXDEBUG_NEW new(__FILE__,__LINE__) | |
840 | @endcode | |
841 | ||
842 | In non-debug mode, this is defined as the normal new operator. | |
843 | ||
844 | @header{wx/object.h} | |
845 | */ | |
846 | #define WXDEBUG_NEW( arg ) | |
847 | ||
848 | //@} | |
849 |