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>
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 false,
122  * which can occur if the object has reached reference count 0 and is about to
123  * be destroyed.
124  *
125  * @since 1.10.0
126  */
127 template<class T>
129 lock() const {
130  PointerTo<T> ptr;
131  this->lock_into(ptr);
132  return ptr;
133 }
134 
135 /**
136  * Returns an ordinary pointer instead of a WeakPointerTo. Useful to work
137  * around compiler problems, particularly for implicit upcasts.
138  */
139 template<class T>
140 INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
141 p() const {
142  assert(!this->was_deleted());
143  return (To *)WeakPointerToBase<T>::_void_ptr;
144 }
145 
146 /**
147  * Returns the original pointer value, even if the object has since been
148  * deleted.
149  */
150 template<class T>
151 INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
152 get_orig() const {
153  return (To *)WeakPointerToBase<T>::_void_ptr;
154 }
155 
156 /**
157  *
158  */
159 template<class T>
161 operator = (To *ptr) {
162  ((WeakPointerTo<T> *)this)->reassign(ptr);
163  return *this;
164 }
165 
166 /**
167  *
168  */
169 template<class T>
171 operator = (const PointerTo<T> &copy) {
172  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
173  return *this;
174 }
175 
176 /**
177  *
178  */
179 template<class T>
181 operator = (const WeakPointerTo<T> &copy) {
182  ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
183  return *this;
184 }
185 
186 /**
187  *
188  */
189 template<class T>
191 operator = (WeakPointerTo<T> &&from) noexcept {
192  this->reassign(std::move(from));
193  return *this;
194 }
195 
196 /**
197  *
198  */
199 template<class T>
200 template<class Y>
202 operator = (const WeakPointerTo<Y> &r) noexcept {
203  this->reassign(r);
204  return *this;
205 }
206 
207 /**
208  *
209  */
210 template<class T>
211 template<class Y>
213 operator = (const PointerTo<Y> &r) noexcept {
214  this->reassign(r);
215  return *this;
216 }
217 
218 /**
219  *
220  */
221 template<class T>
222 template<class Y>
224 operator = (WeakPointerTo<Y> &&r) noexcept {
225  this->reassign(std::move(r));
226  return *this;
227 }
228 
229 /**
230  *
231  */
232 template<class T>
234 WeakConstPointerTo(const To *ptr) :
235  WeakPointerToBase<T>((typename WeakConstPointerTo<T>::To *)ptr)
236 {
237 }
238 
239 /**
240  *
241  */
242 template<class T>
244 WeakConstPointerTo(const PointerTo<T> &copy) :
245  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
246 {
247 }
248 
249 /**
250  *
251  */
252 template<class T>
255  WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
256 {
257 }
258 
259 /**
260  *
261  */
262 template<class T>
265  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
266 {
267 }
268 
269 /**
270  *
271  */
272 template<class T>
275  WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
276 {
277 }
278 
279 /**
280  *
281  */
282 template<class T>
284 WeakConstPointerTo(WeakPointerTo<T> &&from) noexcept :
285  WeakPointerToBase<T>(std::move(from))
286 {
287 }
288 
289 /**
290  *
291  */
292 template<class T>
294 WeakConstPointerTo(WeakConstPointerTo<T> &&from) noexcept :
295  WeakPointerToBase<T>(std::move(from))
296 {
297 }
298 
299 /**
300  *
301  */
302 template<class T>
303 template<class Y>
304 ALWAYS_INLINE WeakConstPointerTo<T>::
305 WeakConstPointerTo(const WeakPointerTo<Y> &r) noexcept :
307 {
308 }
309 
310 /**
311  *
312  */
313 template<class T>
314 template<class Y>
315 ALWAYS_INLINE WeakConstPointerTo<T>::
316 WeakConstPointerTo(const WeakConstPointerTo<Y> &r) noexcept :
318 {
319 }
320 
321 /**
322  *
323  */
324 template<class T>
325 template<class Y>
326 ALWAYS_INLINE WeakConstPointerTo<T>::
327 WeakConstPointerTo(const PointerTo<Y> &r) noexcept :
329 {
330 }
331 
332 /**
333  *
334  */
335 template<class T>
336 template<class Y>
337 ALWAYS_INLINE WeakConstPointerTo<T>::
338 WeakConstPointerTo(const ConstPointerTo<Y> &r) noexcept :
340 {
341 }
342 
343 /**
344  *
345  */
346 template<class T>
347 template<class Y>
348 ALWAYS_INLINE WeakConstPointerTo<T>::
349 WeakConstPointerTo(WeakPointerTo<Y> &&r) noexcept :
350  WeakPointerToBase<T>(std::move(r))
351 {
352 }
353 
354 /**
355  *
356  */
357 template<class T>
358 template<class Y>
359 ALWAYS_INLINE WeakConstPointerTo<T>::
361  WeakPointerToBase<T>(std::move(r))
362 {
363 }
364 
365 /**
366  *
367  */
368 template<class T>
369 INLINE const typename WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
370 operator *() const {
371  assert(!this->was_deleted());
372  return *((To *)WeakPointerToBase<T>::_void_ptr);
373 }
374 
375 /**
376  *
377  */
378 template<class T>
379 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
380 operator -> () const {
381  assert(!this->was_deleted());
382  return (To *)WeakPointerToBase<T>::_void_ptr;
383 }
384 
385 /**
386  * We also have the typecast operator to automatically convert
387  * WeakConstPointerTo's to the required kind of actual pointer. This
388  * introduces ambiguities which the compiler will resolve one way or the
389  * other, but we don't care which way it goes because either will be correct.
390  */
391 
392 template<class T>
394 operator const T * () const {
395  assert(!this->was_deleted());
396  return (To *)WeakPointerToBase<T>::_void_ptr;
397 }
398 
399 /**
400  * A thread-safe way to access the underlying pointer; will silently return
401  * null if the underlying pointer was deleted or null.
402  * Note that this may return null even if was_deleted() still returns false,
403  * which can occur if the object has reached reference count 0 and is about to
404  * be destroyed.
405  *
406  * @since 1.10.0
407  */
408 template<class T>
410 lock() const {
411  ConstPointerTo<T> ptr;
412  this->lock_into(ptr);
413  return ptr;
414 }
415 
416 /**
417  * Returns an ordinary pointer instead of a WeakConstPointerTo. Useful to
418  * work around compiler problems, particularly for implicit upcasts.
419  */
420 template<class T>
421 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
422 p() const {
423  assert(!this->was_deleted());
424  return (To *)WeakPointerToBase<T>::_void_ptr;
425 }
426 
427 /**
428  * Returns the original pointer value, even if the object has since been
429  * deleted.
430  */
431 template<class T>
432 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
433 get_orig() const {
434  return (To *)WeakPointerToBase<T>::_void_ptr;
435 }
436 
437 /**
438  *
439  */
440 template<class T>
442 operator = (const To *ptr) {
443  ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
444  return *this;
445 }
446 
447 /**
448  *
449  */
450 template<class T>
452 operator = (const PointerTo<T> &copy) {
453  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
454  return *this;
455 }
456 
457 /**
458  *
459  */
460 template<class T>
462 operator = (const ConstPointerTo<T> &copy) {
463  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
464  return *this;
465 }
466 
467 /**
468  *
469  */
470 template<class T>
472 operator = (const WeakPointerTo<T> &copy) {
473  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
474  return *this;
475 }
476 
477 /**
478  *
479  */
480 template<class T>
482 operator = (const WeakConstPointerTo<T> &copy) {
483  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
484  return *this;
485 }
486 
487 /**
488  *
489  */
490 template<class T>
492 operator = (WeakPointerTo<T> &&from) noexcept {
493  this->reassign(std::move(from));
494  return *this;
495 }
496 
497 /**
498  *
499  */
500 template<class T>
502 operator = (WeakConstPointerTo<T> &&from) noexcept {
503  this->reassign(std::move(from));
504  return *this;
505 }
506 
507 /**
508  *
509  */
510 template<class T>
511 template<class Y>
513 operator = (const WeakPointerTo<Y> &r) noexcept {
514  this->reassign(r);
515  return *this;
516 }
517 
518 /**
519  *
520  */
521 template<class T>
522 template<class Y>
524 operator = (const WeakConstPointerTo<Y> &r) noexcept {
525  this->reassign(r);
526  return *this;
527 }
528 
529 /**
530  *
531  */
532 template<class T>
533 template<class Y>
535 operator = (const PointerTo<Y> &r) noexcept {
536  this->reassign(r);
537  return *this;
538 }
539 
540 /**
541  *
542  */
543 template<class T>
544 template<class Y>
546 operator = (const ConstPointerTo<Y> &r) noexcept {
547  this->reassign(r);
548  return *this;
549 }
550 
551 /**
552  *
553  */
554 template<class T>
555 template<class Y>
557 operator = (WeakPointerTo<Y> &&r) noexcept {
558  this->reassign(std::move(r));
559  return *this;
560 }
561 
562 /**
563  *
564  */
565 template<class T>
566 template<class Y>
568 operator = (WeakConstPointerTo<Y> &&r) noexcept {
569  this->reassign(std::move(r));
570  return *this;
571 }
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition: pointerTo.h:144
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:29
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
Definition: pointerTo.h:69
A WeakConstPointerTo is similar to a WeakPointerTo, except it keeps a const pointer to the thing,...
Definition: weakPointerTo.h:86
const To * p() const
Returns an ordinary pointer instead of a WeakConstPointerTo.
ConstPointerTo< T > lock() const
A thread-safe way to access the underlying pointer; will silently return null if the underlying point...
const To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.
This is the base class for PointerTo and ConstPointerTo.
WeakPointerTo is similar to PointerTo, except that it does not actually prevent the referenced pointe...
Definition: weakPointerTo.h:29
To * p() const
Returns an ordinary pointer instead of a WeakPointerTo.
PointerTo< T > lock() const
A thread-safe way to access the underlying pointer; will silently return null if the underlying point...
To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.