Panda3D
weakPointerTo.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file weakPointerTo.I
10  * @author drose
11  * @date 2004-09-27
12  */
13 
14 /**
15  *
16  */
17 template<class T>
18 INLINE WeakPointerTo<T>::
19 WeakPointerTo(To *ptr) : WeakPointerToBase<T>(ptr) {
20 }
21 
22 /**
23  *
24  */
25 template<class T>
26 INLINE WeakPointerTo<T>::
27 WeakPointerTo(const PointerTo<T> &copy) :
28  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
29 {
30 }
31 
32 /**
33  *
34  */
35 template<class T>
36 INLINE WeakPointerTo<T>::
37 WeakPointerTo(const WeakPointerTo<T> &copy) :
38  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
39 {
40 }
41 
42 /**
43  *
44  */
45 template<class T>
46 INLINE WeakPointerTo<T>::
47 WeakPointerTo(WeakPointerTo<T> &&from) noexcept :
48  WeakPointerToBase<T>(std::move(from))
49 {
50 }
51 
52 /**
53  *
54  */
55 template<class T>
56 template<class Y>
57 ALWAYS_INLINE WeakPointerTo<T>::
58 WeakPointerTo(const WeakPointerTo<Y> &r) noexcept :
60 {
61 }
62 
63 /**
64  *
65  */
66 template<class T>
67 template<class Y>
68 ALWAYS_INLINE WeakPointerTo<T>::
69 WeakPointerTo(const PointerTo<Y> &r) noexcept :
71 {
72 }
73 
74 /**
75  *
76  */
77 template<class T>
78 template<class Y>
79 ALWAYS_INLINE WeakPointerTo<T>::
80 WeakPointerTo(WeakPointerTo<Y> &&r) noexcept :
81  WeakPointerToBase<T>(std::move(r))
82 {
83 }
84 
85 /**
86  *
87  */
88 template<class T>
89 INLINE typename WeakPointerTo<T>::To &WeakPointerTo<T>::
90 operator *() const {
91  assert(!this->was_deleted());
92  return *((To *)WeakPointerToBase<T>::_void_ptr);
93 }
94 
95 /**
96  *
97  */
98 template<class T>
99 INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
100 operator -> () const {
101  assert(!this->was_deleted());
102  return (To *)WeakPointerToBase<T>::_void_ptr;
103 }
104 
105 /**
106  * We also have the typecast operator to automatically convert WeakPointerTo's
107  * to the required kind of actual pointer. This introduces ambiguities which
108  * the compiler will resolve one way or the other, but we don't care which way
109  * it goes because either will be correct.
110  */
111 template<class T>
112 INLINE WeakPointerTo<T>::
113 operator T * () const {
114  assert(!this->was_deleted());
115  return (To *)WeakPointerToBase<T>::_void_ptr;
116 }
117 
118 /**
119  * A thread-safe way to access the underlying pointer; will silently return
120  * null if the underlying pointer was deleted or null.
121  * Note that this may return null even if was_deleted() still returns true,
122  * which can occur if the object has reached reference count 0 and is about to
123  * be destroyed.
124  */
125 template<class T>
127 lock() const {
128  PointerTo<T> ptr;
129  this->lock_into(ptr);
130  return ptr;
131 }
132 
133 /**
134  * Returns an ordinary pointer instead of a WeakPointerTo. Useful to work
135  * around compiler problems, particularly for implicit upcasts.
136  */
137 template<class T>
138 INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
139 p() const {
140  assert(!this->was_deleted());
141  return (To *)WeakPointerToBase<T>::_void_ptr;
142 }
143 
144 /**
145  * Returns the original pointer value, even if the object has since been
146  * deleted.
147  */
148 template<class T>
149 INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
150 get_orig() const {
151  return (To *)WeakPointerToBase<T>::_void_ptr;
152 }
153 
154 /**
155  *
156  */
157 template<class T>
159 operator = (To *ptr) {
160  ((WeakPointerTo<T> *)this)->reassign(ptr);
161  return *this;
162 }
163 
164 /**
165  *
166  */
167 template<class T>
169 operator = (const PointerTo<T> &copy) {
170  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
171  return *this;
172 }
173 
174 /**
175  *
176  */
177 template<class T>
179 operator = (const WeakPointerTo<T> &copy) {
180  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
181  return *this;
182 }
183 
184 /**
185  *
186  */
187 template<class T>
189 operator = (WeakPointerTo<T> &&from) noexcept {
190  this->reassign(std::move(from));
191  return *this;
192 }
193 
194 /**
195  *
196  */
197 template<class T>
198 template<class Y>
200 operator = (const WeakPointerTo<Y> &r) noexcept {
201  this->reassign(r);
202  return *this;
203 }
204 
205 /**
206  *
207  */
208 template<class T>
209 template<class Y>
211 operator = (const PointerTo<Y> &r) noexcept {
212  this->reassign(r);
213  return *this;
214 }
215 
216 /**
217  *
218  */
219 template<class T>
220 template<class Y>
222 operator = (WeakPointerTo<Y> &&r) noexcept {
223  this->reassign(std::move(r));
224  return *this;
225 }
226 
227 /**
228  *
229  */
230 template<class T>
232 WeakConstPointerTo(const To *ptr) :
233  WeakPointerToBase<T>((typename WeakConstPointerTo<T>::To *)ptr)
234 {
235 }
236 
237 /**
238  *
239  */
240 template<class T>
242 WeakConstPointerTo(const PointerTo<T> &copy) :
243  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
244 {
245 }
246 
247 /**
248  *
249  */
250 template<class T>
253  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
254 {
255 }
256 
257 /**
258  *
259  */
260 template<class T>
263  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
264 {
265 }
266 
267 /**
268  *
269  */
270 template<class T>
273  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
274 {
275 }
276 
277 /**
278  *
279  */
280 template<class T>
282 WeakConstPointerTo(WeakPointerTo<T> &&from) noexcept :
283  WeakPointerToBase<T>(std::move(from))
284 {
285 }
286 
287 /**
288  *
289  */
290 template<class T>
292 WeakConstPointerTo(WeakConstPointerTo<T> &&from) noexcept :
293  WeakPointerToBase<T>(std::move(from))
294 {
295 }
296 
297 /**
298  *
299  */
300 template<class T>
301 template<class Y>
302 ALWAYS_INLINE WeakConstPointerTo<T>::
303 WeakConstPointerTo(const WeakPointerTo<Y> &r) noexcept :
305 {
306 }
307 
308 /**
309  *
310  */
311 template<class T>
312 template<class Y>
313 ALWAYS_INLINE WeakConstPointerTo<T>::
314 WeakConstPointerTo(const WeakConstPointerTo<Y> &r) noexcept :
316 {
317 }
318 
319 /**
320  *
321  */
322 template<class T>
323 template<class Y>
324 ALWAYS_INLINE WeakConstPointerTo<T>::
325 WeakConstPointerTo(const PointerTo<Y> &r) noexcept :
327 {
328 }
329 
330 /**
331  *
332  */
333 template<class T>
334 template<class Y>
335 ALWAYS_INLINE WeakConstPointerTo<T>::
336 WeakConstPointerTo(const ConstPointerTo<Y> &r) noexcept :
338 {
339 }
340 
341 /**
342  *
343  */
344 template<class T>
345 template<class Y>
346 ALWAYS_INLINE WeakConstPointerTo<T>::
347 WeakConstPointerTo(WeakPointerTo<Y> &&r) noexcept :
348  WeakPointerToBase<T>(std::move(r))
349 {
350 }
351 
352 /**
353  *
354  */
355 template<class T>
356 template<class Y>
357 ALWAYS_INLINE WeakConstPointerTo<T>::
359  WeakPointerToBase<T>(std::move(r))
360 {
361 }
362 
363 /**
364  *
365  */
366 template<class T>
367 INLINE const typename WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
368 operator *() const {
369  assert(!this->was_deleted());
370  return *((To *)WeakPointerToBase<T>::_void_ptr);
371 }
372 
373 /**
374  *
375  */
376 template<class T>
377 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
378 operator -> () const {
379  assert(!this->was_deleted());
380  return (To *)WeakPointerToBase<T>::_void_ptr;
381 }
382 
383 /**
384  * We also have the typecast operator to automatically convert
385  * WeakConstPointerTo's to the required kind of actual pointer. This
386  * introduces ambiguities which the compiler will resolve one way or the
387  * other, but we don't care which way it goes because either will be correct.
388  */
389 
390 template<class T>
391 INLINE WeakConstPointerTo<T>::
392 operator const T * () const {
393  assert(!this->was_deleted());
394  return (To *)WeakPointerToBase<T>::_void_ptr;
395 }
396 
397 /**
398  * A thread-safe way to access the underlying pointer; will silently return
399  * null if the underlying pointer was deleted or null.
400  */
401 template<class T>
403 lock() const {
404  ConstPointerTo<T> ptr;
405  this->lock_into(ptr);
406  return ptr;
407 }
408 
409 /**
410  * Returns an ordinary pointer instead of a WeakConstPointerTo. Useful to
411  * work around compiler problems, particularly for implicit upcasts.
412  */
413 template<class T>
414 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
415 p() const {
416  assert(!this->was_deleted());
417  return (To *)WeakPointerToBase<T>::_void_ptr;
418 }
419 
420 /**
421  * Returns the original pointer value, even if the object has since been
422  * deleted.
423  */
424 template<class T>
425 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
426 get_orig() const {
427  return (To *)WeakPointerToBase<T>::_void_ptr;
428 }
429 
430 /**
431  *
432  */
433 template<class T>
435 operator = (const To *ptr) {
436  ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
437  return *this;
438 }
439 
440 /**
441  *
442  */
443 template<class T>
445 operator = (const PointerTo<T> &copy) {
446  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
447  return *this;
448 }
449 
450 /**
451  *
452  */
453 template<class T>
455 operator = (const ConstPointerTo<T> &copy) {
456  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
457  return *this;
458 }
459 
460 /**
461  *
462  */
463 template<class T>
465 operator = (const WeakPointerTo<T> &copy) {
466  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
467  return *this;
468 }
469 
470 /**
471  *
472  */
473 template<class T>
475 operator = (const WeakConstPointerTo<T> &copy) {
476  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
477  return *this;
478 }
479 
480 /**
481  *
482  */
483 template<class T>
485 operator = (WeakPointerTo<T> &&from) noexcept {
486  this->reassign(std::move(from));
487  return *this;
488 }
489 
490 /**
491  *
492  */
493 template<class T>
495 operator = (WeakConstPointerTo<T> &&from) noexcept {
496  this->reassign(std::move(from));
497  return *this;
498 }
499 
500 /**
501  *
502  */
503 template<class T>
504 template<class Y>
506 operator = (const WeakPointerTo<Y> &r) noexcept {
507  this->reassign(r);
508  return *this;
509 }
510 
511 /**
512  *
513  */
514 template<class T>
515 template<class Y>
517 operator = (const WeakConstPointerTo<Y> &r) noexcept {
518  this->reassign(r);
519  return *this;
520 }
521 
522 /**
523  *
524  */
525 template<class T>
526 template<class Y>
528 operator = (const PointerTo<Y> &r) noexcept {
529  this->reassign(r);
530  return *this;
531 }
532 
533 /**
534  *
535  */
536 template<class T>
537 template<class Y>
539 operator = (const ConstPointerTo<Y> &r) noexcept {
540  this->reassign(r);
541  return *this;
542 }
543 
544 /**
545  *
546  */
547 template<class T>
548 template<class Y>
550 operator = (WeakPointerTo<Y> &&r) noexcept {
551  this->reassign(std::move(r));
552  return *this;
553 }
554 
555 /**
556  *
557  */
558 template<class T>
559 template<class Y>
561 operator = (WeakConstPointerTo<Y> &&r) noexcept {
562  this->reassign(std::move(r));
563  return *this;
564 }
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:29
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:29
To * p() const
Returns an ordinary pointer instead of a WeakPointerTo.
const To * p() const
Returns an ordinary pointer instead of a WeakConstPointerTo.
PointerTo< T > lock() const
A thread-safe way to access the underlying pointer; will silently return null if the underlying point...
A WeakConstPointerTo is similar to a WeakPointerTo, except it keeps a const pointer to the thing...
Definition: weakPointerTo.h:86
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations, PT and CPT).
Definition: pointerTo.h:69
This is the base class for PointerTo and ConstPointerTo.
ConstPointerTo< T > lock() const
A thread-safe way to access the underlying pointer; will silently return null if the underlying point...