Panda3D
weakPointerTo.I
1 // Filename: weakPointerTo.I
2 // Created by: drose (27Sep04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: WeakPointerTo::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 template<class T>
22 INLINE WeakPointerTo<T>::
23 WeakPointerTo(To *ptr) : WeakPointerToBase<T>(ptr) {
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: WeakPointerTo::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 template<class T>
32 INLINE WeakPointerTo<T>::
33 WeakPointerTo(const PointerTo<T> &copy) :
34  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: WeakPointerTo::Copy Constructor
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 template<class T>
44 INLINE WeakPointerTo<T>::
45 WeakPointerTo(const WeakPointerTo<T> &copy) :
46  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
47 {
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: WeakPointerTo::Dereference operator
52 // Access: Public
53 // Description:
54 ////////////////////////////////////////////////////////////////////
55 template<class T>
56 INLINE TYPENAME WeakPointerTo<T>::To &WeakPointerTo<T>::
57 operator *() const {
58  nassertr(!this->was_deleted(), *((To *)NULL));
59  return *((To *)WeakPointerToBase<T>::_void_ptr);
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: WeakPointerTo::Member access operator
64 // Access: Public
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 template<class T>
68 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
69 operator -> () const {
70  nassertr(!this->was_deleted(), (To *)NULL);
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: WeakPointerTo::Typecast operator
76 // Access: Public
77 // Description: We also have the typecast operator to automatically
78 // convert WeakPointerTo's to the required kind of actual
79 // pointer. This introduces ambiguities which the
80 // compiler will resolve one way or the other, but we
81 // don't care which way it goes because either will be
82 // correct.
83 ////////////////////////////////////////////////////////////////////
84 template<class T>
85 INLINE WeakPointerTo<T>::
86 operator T * () const {
87  nassertr(!this->was_deleted(), (To *)NULL);
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: WeakPointerTo::p
93 // Access: Public
94 // Description: Returns an ordinary pointer instead of a WeakPointerTo.
95 // Useful to work around compiler problems, particularly
96 // for implicit upcasts.
97 ////////////////////////////////////////////////////////////////////
98 template<class T>
99 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
100 p() const {
101  nassertr(!this->was_deleted(), (To *)NULL);
102  return (To *)WeakPointerToBase<T>::_void_ptr;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: WeakPointerTo::get_orig
107 // Access: Public
108 // Description: Returns the original pointer value, even if the
109 // object has since been deleted.
110 ////////////////////////////////////////////////////////////////////
111 template<class T>
112 INLINE TYPENAME WeakPointerTo<T>::To *WeakPointerTo<T>::
113 get_orig() const {
114  return (To *)WeakPointerToBase<T>::_void_ptr;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: WeakPointerTo::Assignment operator
119 // Access: Public
120 // Description:
121 ////////////////////////////////////////////////////////////////////
122 template<class T>
124 operator = (To *ptr) {
125  ((WeakPointerTo<T> *)this)->reassign(ptr);
126  return *this;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: WeakPointerTo::Assignment operator
131 // Access: Public
132 // Description:
133 ////////////////////////////////////////////////////////////////////
134 template<class T>
136 operator = (const PointerTo<T> &copy) {
137  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
138  return *this;
139 }
140 
141 ////////////////////////////////////////////////////////////////////
142 // Function: WeakPointerTo::Assignment operator
143 // Access: Public
144 // Description:
145 ////////////////////////////////////////////////////////////////////
146 template<class T>
148 operator = (const WeakPointerTo<T> &copy) {
149  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
150  return *this;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: WeakConstPointerTo::Constructor
155 // Access: Public
156 // Description:
157 ////////////////////////////////////////////////////////////////////
158 template<class T>
160 WeakConstPointerTo(const To *ptr) :
161  WeakPointerToBase<T>((TYPENAME WeakConstPointerTo<T>::To *)ptr)
162 {
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: WeakConstPointerTo::Copy Constructor
167 // Access: Public
168 // Description:
169 ////////////////////////////////////////////////////////////////////
170 template<class T>
172 WeakConstPointerTo(const PointerTo<T> &copy) :
173  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
174 {
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: WeakConstPointerTo::Copy Constructor
179 // Access: Public
180 // Description:
181 ////////////////////////////////////////////////////////////////////
182 template<class T>
185  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
186 {
187 }
188 
189 ////////////////////////////////////////////////////////////////////
190 // Function: WeakConstPointerTo::Copy Constructor
191 // Access: Public
192 // Description:
193 ////////////////////////////////////////////////////////////////////
194 template<class T>
198 {
199 }
200 
201 ////////////////////////////////////////////////////////////////////
202 // Function: WeakConstPointerTo::Copy Constructor
203 // Access: Public
204 // Description:
205 ////////////////////////////////////////////////////////////////////
206 template<class T>
210 {
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: WeakConstPointerTo::Dereference operator
215 // Access: Public
216 // Description:
217 ////////////////////////////////////////////////////////////////////
218 template<class T>
219 INLINE const TYPENAME WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
220 operator *() const {
221  nassertr(!this->was_deleted(), *((To *)NULL));
222  return *((To *)WeakPointerToBase<T>::_void_ptr);
223 }
224 
225 ////////////////////////////////////////////////////////////////////
226 // Function: WeakConstPointerTo::Member access operator
227 // Access: Public
228 // Description:
229 ////////////////////////////////////////////////////////////////////
230 template<class T>
231 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
232 operator -> () const {
233  nassertr(!this->was_deleted(), (To *)NULL);
234  return (To *)WeakPointerToBase<T>::_void_ptr;
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: WeakConstPointerTo::Typecast operator
239 // Access: Public
240 // Description: We also have the typecast operator to automatically
241 // convert WeakConstPointerTo's to the required kind of actual
242 // pointer. This introduces ambiguities which the
243 // compiler will resolve one way or the other, but we
244 // don't care which way it goes because either will be
245 // correct.
246 ////////////////////////////////////////////////////////////////////
247 
248 template<class T>
249 INLINE WeakConstPointerTo<T>::
250 operator const T * () const {
251  nassertr(!this->was_deleted(), (To *)NULL);
252  return (To *)WeakPointerToBase<T>::_void_ptr;
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: WeakConstPointerTo::p
257 // Access: Public
258 // Description: Returns an ordinary pointer instead of a WeakConstPointerTo.
259 // Useful to work around compiler problems, particularly
260 // for implicit upcasts.
261 ////////////////////////////////////////////////////////////////////
262 template<class T>
263 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
264 p() const {
265  nassertr(!this->was_deleted(), (To *)NULL);
266  return (To *)WeakPointerToBase<T>::_void_ptr;
267 }
268 
269 ////////////////////////////////////////////////////////////////////
270 // Function: WeakConstPointerTo::get_orig
271 // Access: Public
272 // Description: Returns the original pointer value, even if the
273 // object has since been deleted.
274 ////////////////////////////////////////////////////////////////////
275 template<class T>
276 INLINE const TYPENAME WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
277 get_orig() const {
278  return (To *)WeakPointerToBase<T>::_void_ptr;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: WeakConstPointerTo::Assignment operator
283 // Access: Public
284 // Description:
285 ////////////////////////////////////////////////////////////////////
286 template<class T>
288 operator = (const To *ptr) {
289  ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
290  return *this;
291 }
292 
293 ////////////////////////////////////////////////////////////////////
294 // Function: WeakConstPointerTo::Assignment operator
295 // Access: Public
296 // Description:
297 ////////////////////////////////////////////////////////////////////
298 template<class T>
300 operator = (const PointerTo<T> &copy) {
301  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
302  return *this;
303 }
304 
305 ////////////////////////////////////////////////////////////////////
306 // Function: WeakConstPointerTo::Assignment operator
307 // Access: Public
308 // Description:
309 ////////////////////////////////////////////////////////////////////
310 template<class T>
312 operator = (const ConstPointerTo<T> &copy) {
313  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
314  return *this;
315 }
316 
317 ////////////////////////////////////////////////////////////////////
318 // Function: WeakConstPointerTo::Assignment operator
319 // Access: Public
320 // Description:
321 ////////////////////////////////////////////////////////////////////
322 template<class T>
324 operator = (const WeakPointerTo<T> &copy) {
325  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
326  return *this;
327 }
328 
329 ////////////////////////////////////////////////////////////////////
330 // Function: WeakConstPointerTo::Assignment operator
331 // Access: Public
332 // Description:
333 ////////////////////////////////////////////////////////////////////
334 template<class T>
336 operator = (const WeakConstPointerTo<T> &copy) {
337  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
338  return *this;
339 }
const To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.
To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.
WeakPointerTo is similar to PointerTo, except that it does not actually prevent the referenced pointe...
Definition: weakPointerTo.h:32
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:32
bool was_deleted() const
Returns true if the object we are pointing to has been deleted, false otherwise.
To * p() const
Returns an ordinary pointer instead of a WeakPointerTo.
const To * p() const
Returns an ordinary pointer instead of a WeakConstPointerTo.
A WeakConstPointerTo is similar to a WeakPointerTo, except it keeps a const pointer to the thing...
Definition: weakPointerTo.h:69
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144
PointerTo is a template class which implements a smart pointer to an object derived from ReferenceCou...
Definition: pointerTo.h:79
This is the base class for PointerTo and ConstPointerTo.