1 \section{\class{wxObjectDataPtr<T>
}}\label{wxobjectdataptr
}
3 This is helper template class primarily written to avoid memory
4 leaks because of missing calls to
\helpref{wxObjectRefData::DecRef
}{wxobjectrefdatadecref
}.
6 Despite the name this template can actually be used as a
7 smart pointer for any class implementing the reference
8 counting interface and it does not use or depend on wxObject.
10 The difference to
\helpref{wxSharedPtr
}{wxsharedptr
} is that
11 wxObjectDataPtr relies on the reference counting to be in
12 the class pointed to where as wxSharedPtr implements the
13 reference counting itself.
17 \helpref{wxObject
}{wxobject
},
18 \helpref{wxObjectRefData
}{wxobjectrefdata
},
19 \helpref{Reference counting
}{trefcount
}
21 \helpref{wxSharedPtr
}{wxsharedptr
},
22 \helpref{wxScopedPtr
}{wxscopedptrtemplate
},
23 \helpref{wxWeakRef
}{wxweakref
}
26 \wxheading{Derived from
}
30 \wxheading{Include files
}
34 \wxheading{Data structures
}
38 typedef T element_type
46 class MyCarRefData: public wxObjectRefData
49 MyCarRefData()
{ m_price =
0;
}
51 MyCarRefData( const MyCarRefData& data )
54 m_price = data.m_price;
57 void SetPrice( int price )
{ m_price = price;
}
58 int GetPrice()
{ return m_price;
}
67 MyCar( int price ) : m_data( new MyCarRefData )
69 m_data->SetPrice( price );
72 MyCar& operator =( const MyCar& tocopy )
74 m_data = tocopy.m_data;
78 bool operator == ( const MyCar& other ) const
80 if (m_data.get() == other.m_data.get()) return true;
81 return (m_data->GetPrice() == other.m_data->GetPrice());
84 void SetPrice( int price )
87 m_data->SetPrice( price );
92 return m_data->GetPrice();
95 wxObjectDataPtr<MyCarRefData> m_data;
100 if (m_data->GetRefCount() ==
1)
103 m_data.reset( new MyCarRefData( *m_data ) );
110 \latexignore{\rtfignore{\wxheading{Members
}}}
112 \membersection{wxObjectDataPtr<T>::wxObjectDataPtr<T>
}\label{wxobjectdataptrwxobjectdataptr
}
114 \func{wxEXPLICIT
}{wxObjectDataPtr<T>
}{\param{T*
}{ptr = NULL
}}
116 Constructor.
{\it ptr
} is a pointer to the reference
117 counted object to which this class points.
119 \func{}{wxObjectDataPtr<T>
}{\param{const wxObjectDataPtr<T>\&
}{tocopy
}}
121 This copy constructor increases the count of the reference
122 counted object to which
{\it tocopy
} points and then this
123 class will point to, as well.
125 \membersection{wxObjectDataPtr<T>::
\destruct{wxObjectDataPtr<T>
}}\label{wxobjectdataptrdtor
}
127 \func{}{\destruct{wxObjectDataPtr<T>
}}{\void}
129 Calls
\helpref{DecRef
}{wxobjectrefdatadecref
} on the reference
130 counted object to which this class points.
132 \membersection{wxObjectDataPtr<T>::operator unspecified
\_bool\_type}\label{wxobjectdataptroperatorbool
}
134 \constfunc{}{operator unspecified
\_bool\_type}{\void}
136 Conversion to a boolean expression (in a variant which is not
137 convertable to anything but a boolean expression). If this class
138 contains a valid pointer it will return
{\it true
}, if it contains
139 a NULL pointer it will return
{\it false
}.
141 \membersection{wxObjectDataPtr<T>::operator*
}\label{wxobjectdataptroperatorreft
}
143 \constfunc{T \&
}{operator*
}{\void}
145 Returns a reference to the object. If the internal pointer is NULL
146 this method will cause an assert in debug mode.
148 \membersection{wxObjectDataPtr<T>::operator->
}\label{wxobjectdataptroperatorpointer
}
150 \constfunc{T*
}{operator->
}{\void}
152 Returns a pointer to the reference counted object to which
153 this class points. If this the internal pointer is NULL,
154 this method will assert in debug mode.
156 \membersection{wxObjectDataPtr<T>::operator=
}\label{wxobjectdataptroperatorassign
}
158 \func{wxObjectDataPtr<T>\& operator
}{operator=
}{\param{const wxObjectDataPtr<T>\&
}{tocopy
}}
160 \func{wxObjectDataPtr<T>\& operator
}{operator=
}{\param{T*
}{ptr
}}
162 Assignment operators.
164 \membersection{wxObjectDataPtr<T>::get
}\label{wxobjectdataptrget
}
166 \constfunc{T*
}{get
}{\void}
168 Gets a pointer to the reference counted object to which
171 \membersection{wxObjectDataPtr<T>::reset
}\label{wxobjectdataptrreset
}
173 \func{void
}{reset
}{\param{T*
}{ptr
}}
175 Reset this class to
{\it ptr
} which points to a reference