object.h 26 KB

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