1 \section{\class{wxObjectDataPtr<T>
}}\label{wxobjectdataptr
}
3 This is helper template class to avoid memleaks because of missing calls
4 to
\helpref{wxObjectRefData::DecRef
}{wxobjectrefdatadecref
}.
6 Despite the name this template can actually be used for any
7 class implementing the reference counting interface and it
8 does not use or depend on wxObject.
12 \helpref{wxObject
}{wxobject
},
13 \helpref{wxObjectRefData
}{wxobjectrefdata
},
14 \helpref{Reference counting
}{trefcount
}
16 \wxheading{Derived from
}
20 \wxheading{Include files
}
24 \wxheading{Data structures
}
26 {\small \begin{verbatim
}
27 typedef T element
\_type
36 class MyCarRefData: public wxObjectRefData
39 MyCarRefData()
{ m_price =
0;
}
41 MyCarRefData( const MyCarRefData& data )
44 m_price = data.m_price;
47 bool operator == (const MyCarRefData& data) const
49 return m_price == data.m_price;
52 void SetPrice( int price )
{ m_price = price;
}
53 int GetPrice()
{ return m_price;
}
63 MyCar( const MyCar& data );
65 bool operator == ( const MyCar& car ) const;
66 bool operator != (const MyCar& car) const
{ return !
(*this == car); }
68 void SetPrice( int price );
71 wxObjectRefPtr<MyCarRefData> m_data;
80 MyCar::MyCar( int price )
82 m_data = new MyCarRefData;
83 m_data.get()->SetPrice( price );
86 MyCar::MyCar( const MyCar& car )
88 m_data.reset( car.m_data.get() );
91 bool MyCar::operator == ( const MyCar& car ) const
93 if (m_data.get() == car.m_data.get()) return true;
95 return (*m_data.get() == *car.m_data.get());
98 void MyCar::SetPrice( int price )
102 m_data.get()->SetPrice( price );
105 int MyCar::GetPrice() const
107 return m_data.get()->GetPrice();
110 void MyCar::UnShare()
112 if (m_data.get()->GetCount() == 1)
115 m_data.reset( new MyCarRefData( *m_data.get() ) );
121 \latexignore{\rtfignore{\wxheading{Members}}}
123 \membersection{wxObjectDataPtr<T>::wxObjectDataPtr<T>}\label{wxobjectdataptrwxobjectdataptr}
125 \func{wxEXPLICIT}{wxObjectDataPtr<T>}{\param{T* }{ptr = NULL}}
127 Constructor. {\it ptr} is a pointer to the reference
128 counted object to which this class points.
130 \func{}{wxObjectDataPtr<T>}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
132 This copy constructor increases the count of the reference
133 counted object to which {\it tocopy} points and then this
134 class will point to, as well.
136 \membersection{wxObjectDataPtr<T>::\destruct{wxObjectDataPtr<T>}}\label{wxobjectdataptrdtor}
138 \func{}{\destruct{wxObjectDataPtr<T>}}{\void}
140 Calls \helpref{DecRef}{wxobjectrefdatadecref} on the reference
141 counted object to which this class points.
143 \membersection{wxObjectDataPtr<T>::operator->}\label{wxobjectdataptroperatorpointer}
145 \constfunc{T*}{operator->}{\void}
147 Gets a pointer to the reference counted object to which
148 this class points. Same as \helpref{get}{wxobjectdataptrget}.
150 \membersection{wxObjectDataPtr<T>::operator=}\label{wxobjectdataptroperatorassign}
152 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
154 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{T* }{ptr}}
156 Assignment operators.
158 \membersection{wxObjectDataPtr<T>::get}\label{wxobjectdataptrget}
160 \constfunc{T*}{get}{\void}
162 Gets a pointer to the reference counted object to which
165 \membersection{wxObjectDataPtr<T>::reset}\label{wxobjectdataptrreset}
167 \func{void}{reset}{\param{T* }{ptr}}
169 Reset this class to {\it ptr} which points to a reference