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;
}
64 bool operator == ( const MyCar& car ) const;
65 bool operator != (const MyCar& car) const
{ return !
(*this == car); }
67 void SetPrice( int price );
70 wxObjectRefPtr<MyCarRefData> m_data;
79 MyCar::MyCar( int price )
81 m_data = new MyCarRefData;
82 m_data.get()->SetPrice( price );
85 bool MyCar::operator == ( const MyCar& car ) const
87 if (m_data.get() == car.m_data.get()) return true;
89 return (*m_data.get() == *car.m_data.get());
92 void MyCar::SetPrice( int price )
96 m_data.get()->SetPrice( price );
99 int MyCar::GetPrice() const
101 return m_data.get()->GetPrice();
104 void MyCar::UnShare()
106 if (m_data.get()->GetCount() == 1)
109 m_data.reset( new MyCarRefData( *m_data.get() ) );
115 \latexignore{\rtfignore{\wxheading{Members}}}
117 \membersection{wxObjectDataPtr<T>::wxObjectDataPtr<T>}\label{wxobjectdataptrwxobjectdataptr}
119 \func{wxEXPLICIT}{wxObjectDataPtr<T>}{\param{T* }{ptr = NULL}}
121 Constructor. {\it ptr} is a pointer to the reference
122 counted object to which this class points.
124 \func{}{wxObjectDataPtr<T>}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
126 This copy constructor increases the count of the reference
127 counted object to which {\it tocopy} points and then this
128 class will point to, as well.
130 \membersection{wxObjectDataPtr<T>::\destruct{wxObjectDataPtr<T>}}\label{wxobjectdataptrdtor}
132 \func{}{\destruct{wxObjectDataPtr<T>}}{\void}
134 Calls \helpref{DecRef}{wxobjectrefdatadecref} on the reference
135 counted object to which this class points.
137 \membersection{wxObjectDataPtr<T>::operator->}\label{wxobjectdataptroperatorpointer}
139 \constfunc{T*}{operator->}{\void}
141 Gets a pointer to the reference counted object to which
142 this class points. Same as \helpref{get}{wxobjectdataptrget}.
144 \membersection{wxObjectDataPtr<T>::operator=}\label{wxobjectdataptroperatorassign}
146 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{const wxObjectDataPtr<T>\& }{tocopy}}
148 \func{wxObjectDataPtr<T>\& operator}{operator=}{\param{T* }{ptr}}
150 Assignment operators.
152 \membersection{wxObjectDataPtr<T>::get}\label{wxobjectdataptrget}
154 \constfunc{T*}{get}{\void}
156 Gets a pointer to the reference counted object to which
159 \membersection{wxObjectDataPtr<T>::reset}\label{wxobjectdataptrreset}
161 \func{void}{reset}{\param{T* }{ptr}}
163 Reset this class to {\it ptr} which points to a reference