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
}
28 typedef T element_type
38 class MyCarRefData: public wxObjectRefData
41 MyCarRefData()
{ m_price =
0;
}
43 MyCarRefData( const MyCarRefData& data )
46 m_price = data.m_price;
49 bool operator == (const MyCarRefData& data) const
51 return m_price == data.m_price;
54 void SetPrice( int price )
{ m_price = price;
}
55 int GetPrice()
{ return m_price;
}
65 MyCar( const MyCar& data );
67 bool operator == ( const MyCar& car ) const;
68 bool operator != (const MyCar& car) const
{ return !
(*this == car); }
70 void SetPrice( int price );
73 wxObjectRefPtr<MyCarRefData> m_data;
82 MyCar::MyCar( int price )
84 m_data = new MyCarRefData;
85 m_data.get()->SetPrice( price );
88 MyCar::MyCar( const MyCar& car )
90 m_data.reset( car.m_data.get() );
93 bool MyCar::operator == ( const MyCar& car ) const
95 if (m_data.get() == car.m_data.get()) return true;
97 return (*m_data.get() == *car.m_data.get());
100 void MyCar::SetPrice( int price )
104 m_data.get()->SetPrice( price );
107 int MyCar::GetPrice() const
109 return m_data.get()->GetPrice();
112 void MyCar::UnShare()
114 if (m_data.get()->GetCount() == 1)
117 m_data.reset( new MyCarRefData( *m_data.get() ) );
123 \latexignore{\rtfignore{\wxheading{Members}}}
125 \membersection{wxObjectDataPtr<T>::wxObjectDataPtr<T>}\label{wxobjectdataptrwxobjectdataptr}
127 \func{wxEXPLICIT}{wxObjectDataPtr<T>}{\param{T* }{ptr = NULL}}
129 Constructor. {\it ptr} is a pointer to the reference
130 counted object to which this class points.
132 \func{}{wxObjectDataPtr<T>}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
134 This copy constructor increases the count of the reference
135 counted object to which {\it tocopy} points and then this
136 class will point to, as well.
138 \membersection{wxObjectDataPtr<T>::\destruct{wxObjectDataPtr<T>}}\label{wxobjectdataptrdtor}
140 \func{}{\destruct{wxObjectDataPtr<T>}}{\void}
142 Calls \helpref{DecRef}{wxobjectrefdatadecref} on the reference
143 counted object to which this class points.
145 \membersection{wxObjectDataPtr<T>::operator->}\label{wxobjectdataptroperatorpointer}
147 \constfunc{T*}{operator->}{\void}
149 Gets a pointer to the reference counted object to which
150 this class points. Same as \helpref{get}{wxobjectdataptrget}.
152 \membersection{wxObjectDataPtr<T>::operator=}\label{wxobjectdataptroperatorassign}
154 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
156 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{T* }{ptr}}
158 Assignment operators.
160 \membersection{wxObjectDataPtr<T>::get}\label{wxobjectdataptrget}
162 \constfunc{T*}{get}{\void}
164 Gets a pointer to the reference counted object to which
167 \membersection{wxObjectDataPtr<T>::reset}\label{wxobjectdataptrreset}
169 \func{void}{reset}{\param{T* }{ptr}}
171 Reset this class to {\it ptr} which points to a reference