\section{\class{wxObjectDataPtr}}\label{wxobjectdataptr} This is helper template class to avoid memleaks because of missing calls to \helpref{wxObjectRefData::DecRef}{wxobjectrefdatadecref}. Despite the name this template can actually be used for any class implementing the reference counting interface and it does not use or depend on wxObject. \wxheading{See also} \helpref{wxObject}{wxobject}, \helpref{wxObjectRefData}{wxobjectrefdata}, \helpref{Reference counting}{trefcount} \wxheading{Derived from} No base class \wxheading{Include files} \wxheading{Data structures} {\small% \begin{verbatim} typedef T element_type \end{verbatim} }% \wxheading{Example} \begin{verbatim} // include file class MyCarRefData: public wxObjectRefData { public: MyCarRefData() { m_price = 0; } MyCarRefData( const MyCarRefData& data ) : wxObjectRefData() { m_price = data.m_price; } bool operator == (const MyCarRefData& data) const { return m_price == data.m_price; } void SetPrice( int price ) { m_price = price; } int GetPrice() { return m_price; } protected: int m_price; }; class MyCar { public: MyCar( int price ); MyCar( const MyCar& data ); bool operator == ( const MyCar& car ) const; bool operator != (const MyCar& car) const { return !(*this == car); } void SetPrice( int price ); int GetPrice() const; wxObjectRefPtr m_data; protected: void UnShare(); }; // implementation MyCar::MyCar( int price ) { m_data = new MyCarRefData; m_data.get()->SetPrice( price ); } MyCar::MyCar( const MyCar& car ) { m_data.reset( car.m_data.get() ); } bool MyCar::operator == ( const MyCar& car ) const { if (m_data.get() == car.m_data.get()) return true; return (*m_data.get() == *car.m_data.get()); } void MyCar::SetPrice( int price ) { UnShare(); m_data.get()->SetPrice( price ); } int MyCar::GetPrice() const { return m_data.get()->GetPrice(); } void MyCar::UnShare() { if (m_data.get()->GetCount() == 1) return; m_data.reset( new MyCarRefData( *m_data.get() ) ); } \end{verbatim} \latexignore{\rtfignore{\wxheading{Members}}} \membersection{wxObjectDataPtr::wxObjectDataPtr}\label{wxobjectdataptrwxobjectdataptr} \func{wxEXPLICIT}{wxObjectDataPtr}{\param{T* }{ptr = NULL}} Constructor. {\it ptr} is a pointer to the reference counted object to which this class points. \func{}{wxObjectDataPtr}{\param{const wxObjectDataPtr\& }{tocopy}} This copy constructor increases the count of the reference counted object to which {\it tocopy} points and then this class will point to, as well. \membersection{wxObjectDataPtr::\destruct{wxObjectDataPtr}}\label{wxobjectdataptrdtor} \func{}{\destruct{wxObjectDataPtr}}{\void} Calls \helpref{DecRef}{wxobjectrefdatadecref} on the reference counted object to which this class points. \membersection{wxObjectDataPtr::operator->}\label{wxobjectdataptroperatorpointer} \constfunc{T*}{operator->}{\void} Gets a pointer to the reference counted object to which this class points. Same as \helpref{get}{wxobjectdataptrget}. \membersection{wxObjectDataPtr::operator=}\label{wxobjectdataptroperatorassign} \func{wxObjectDataPtr\& operator}{operator=}{\param{const wxObjectDataPtr\& }{tocopy}} \func{wxObjectDataPtr\& operator}{operator=}{\param{T* }{ptr}} Assignment operators. \membersection{wxObjectDataPtr::get}\label{wxobjectdataptrget} \constfunc{T*}{get}{\void} Gets a pointer to the reference counted object to which this class points. \membersection{wxObjectDataPtr::reset}\label{wxobjectdataptrreset} \func{void}{reset}{\param{T* }{ptr}} Reset this class to {\it ptr} which points to a reference counted object.