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  * @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>
393 INLINE WeakConstPointerTo<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  *
403  * @since 1.10.0
404  */
405 template<class T>
407 lock() const {
408  ConstPointerTo<T> ptr;
409  this->lock_into(ptr);
410  return ptr;
411 }
412 
413 /**
414  * Returns an ordinary pointer instead of a WeakConstPointerTo. Useful to
415  * work around compiler problems, particularly for implicit upcasts.
416  */
417 template<class T>
418 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
419 p() const {
420  assert(!this->was_deleted());
421  return (To *)WeakPointerToBase<T>::_void_ptr;
422 }
423 
424 /**
425  * Returns the original pointer value, even if the object has since been
426  * deleted.
427  */
428 template<class T>
429 INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
430 get_orig() const {
431  return (To *)WeakPointerToBase<T>::_void_ptr;
432 }
433 
434 /**
435  *
436  */
437 template<class T>
439 operator = (const To *ptr) {
440  ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
441  return *this;
442 }
443 
444 /**
445  *
446  */
447 template<class T>
449 operator = (const PointerTo<T> &copy) {
450  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
451  return *this;
452 }
453 
454 /**
455  *
456  */
457 template<class T>
459 operator = (const ConstPointerTo<T> &copy) {
460  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
461  return *this;
462 }
463 
464 /**
465  *
466  */
467 template<class T>
469 operator = (const WeakPointerTo<T> &copy) {
470  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
471  return *this;
472 }
473 
474 /**
475  *
476  */
477 template<class T>
479 operator = (const WeakConstPointerTo<T> &copy) {
480  ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
481  return *this;
482 }
483 
484 /**
485  *
486  */
487 template<class T>
489 operator = (WeakPointerTo<T> &&from) noexcept {
490  this->reassign(std::move(from));
491  return *this;
492 }
493 
494 /**
495  *
496  */
497 template<class T>
499 operator = (WeakConstPointerTo<T> &&from) noexcept {
500  this->reassign(std::move(from));
501  return *this;
502 }
503 
504 /**
505  *
506  */
507 template<class T>
508 template<class Y>
510 operator = (const WeakPointerTo<Y> &r) noexcept {
511  this->reassign(r);
512  return *this;
513 }
514 
515 /**
516  *
517  */
518 template<class T>
519 template<class Y>
521 operator = (const WeakConstPointerTo<Y> &r) noexcept {
522  this->reassign(r);
523  return *this;
524 }
525 
526 /**
527  *
528  */
529 template<class T>
530 template<class Y>
532 operator = (const PointerTo<Y> &r) noexcept {
533  this->reassign(r);
534  return *this;
535 }
536 
537 /**
538  *
539  */
540 template<class T>
541 template<class Y>
543 operator = (const ConstPointerTo<Y> &r) noexcept {
544  this->reassign(r);
545  return *this;
546 }
547 
548 /**
549  *
550  */
551 template<class T>
552 template<class Y>
554 operator = (WeakPointerTo<Y> &&r) noexcept {
555  this->reassign(std::move(r));
556  return *this;
557 }
558 
559 /**
560  *
561  */
562 template<class T>
563 template<class Y>
565 operator = (WeakConstPointerTo<Y> &&r) noexcept {
566  this->reassign(std::move(r));
567  return *this;
568 }
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,...
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...