Panda3D
Loading...
Searching...
No Matches
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 */
17template<class T>
19WeakPointerTo(To *ptr) : WeakPointerToBase<T>(ptr) {
20}
21
22/**
23 *
24 */
25template<class T>
27WeakPointerTo(const PointerTo<T> &copy) :
28 WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
29{
30}
31
32/**
33 *
34 */
35template<class T>
38 WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
39{
40}
41
42/**
43 *
44 */
45template<class T>
47WeakPointerTo(WeakPointerTo<T> &&from) noexcept :
48 WeakPointerToBase<T>(std::move(from))
49{
50}
51
52/**
53 *
54 */
55template<class T>
56template<class Y>
57ALWAYS_INLINE WeakPointerTo<T>::
58WeakPointerTo(const WeakPointerTo<Y> &r) noexcept :
60{
61}
62
63/**
64 *
65 */
66template<class T>
67template<class Y>
68ALWAYS_INLINE WeakPointerTo<T>::
69WeakPointerTo(const PointerTo<Y> &r) noexcept :
71{
72}
73
74/**
75 *
76 */
77template<class T>
78template<class Y>
79ALWAYS_INLINE WeakPointerTo<T>::
80WeakPointerTo(WeakPointerTo<Y> &&r) noexcept :
81 WeakPointerToBase<T>(std::move(r))
82{
83}
84
85/**
86 *
87 */
88template<class T>
89INLINE typename WeakPointerTo<T>::To &WeakPointerTo<T>::
90operator *() const {
91 assert(!this->was_deleted());
92 return *((To *)WeakPointerToBase<T>::_void_ptr);
93}
94
95/**
96 *
97 */
98template<class T>
99INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
100operator -> () const {
101 assert(!this->was_deleted());
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 */
111template<class T>
113operator T * () const {
114 assert(!this->was_deleted());
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 */
127template<class T>
129lock() 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 */
139template<class T>
140INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
141p() const {
142 assert(!this->was_deleted());
144}
145
146/**
147 * Returns the original pointer value, even if the object has since been
148 * deleted.
149 */
150template<class T>
151INLINE typename WeakPointerTo<T>::To *WeakPointerTo<T>::
152get_orig() const {
154}
155
156/**
157 *
158 */
159template<class T>
161operator = (To *ptr) {
162 ((WeakPointerTo<T> *)this)->reassign(ptr);
163 return *this;
164}
165
166/**
167 *
168 */
169template<class T>
171operator = (const PointerTo<T> &copy) {
172 ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
173 return *this;
174}
175
176/**
177 *
178 */
179template<class T>
181operator = (const WeakPointerTo<T> &copy) {
182 ((WeakPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
183 return *this;
184}
185
186/**
187 *
188 */
189template<class T>
191operator = (WeakPointerTo<T> &&from) noexcept {
192 this->reassign(std::move(from));
193 return *this;
194}
195
196/**
197 *
198 */
199template<class T>
200template<class Y>
202operator = (const WeakPointerTo<Y> &r) noexcept {
203 this->reassign(r);
204 return *this;
205}
206
207/**
208 *
209 */
210template<class T>
211template<class Y>
213operator = (const PointerTo<Y> &r) noexcept {
214 this->reassign(r);
215 return *this;
216}
217
218/**
219 *
220 */
221template<class T>
222template<class Y>
224operator = (WeakPointerTo<Y> &&r) noexcept {
225 this->reassign(std::move(r));
226 return *this;
227}
228
229/**
230 *
231 */
232template<class T>
234WeakConstPointerTo(const To *ptr) :
235 WeakPointerToBase<T>((typename WeakConstPointerTo<T>::To *)ptr)
236{
237}
238
239/**
240 *
241 */
242template<class T>
244WeakConstPointerTo(const PointerTo<T> &copy) :
245 WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
246{
247}
248
249/**
250 *
251 */
252template<class T>
255 WeakPointerToBase<T>(*(const PointerToBase<T> *)&copy)
256{
257}
258
259/**
260 *
261 */
262template<class T>
265 WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
266{
267}
268
269/**
270 *
271 */
272template<class T>
275 WeakPointerToBase<T>(*(const WeakPointerToBase<T> *)&copy)
276{
277}
278
279/**
280 *
281 */
282template<class T>
284WeakConstPointerTo(WeakPointerTo<T> &&from) noexcept :
285 WeakPointerToBase<T>(std::move(from))
286{
287}
288
289/**
290 *
291 */
292template<class T>
295 WeakPointerToBase<T>(std::move(from))
296{
297}
298
299/**
300 *
301 */
302template<class T>
303template<class Y>
304ALWAYS_INLINE WeakConstPointerTo<T>::
305WeakConstPointerTo(const WeakPointerTo<Y> &r) noexcept :
307{
308}
309
310/**
311 *
312 */
313template<class T>
314template<class Y>
315ALWAYS_INLINE WeakConstPointerTo<T>::
316WeakConstPointerTo(const WeakConstPointerTo<Y> &r) noexcept :
318{
319}
320
321/**
322 *
323 */
324template<class T>
325template<class Y>
326ALWAYS_INLINE WeakConstPointerTo<T>::
327WeakConstPointerTo(const PointerTo<Y> &r) noexcept :
329{
330}
331
332/**
333 *
334 */
335template<class T>
336template<class Y>
337ALWAYS_INLINE WeakConstPointerTo<T>::
338WeakConstPointerTo(const ConstPointerTo<Y> &r) noexcept :
340{
341}
342
343/**
344 *
345 */
346template<class T>
347template<class Y>
348ALWAYS_INLINE WeakConstPointerTo<T>::
350 WeakPointerToBase<T>(std::move(r))
351{
352}
353
354/**
355 *
356 */
357template<class T>
358template<class Y>
359ALWAYS_INLINE WeakConstPointerTo<T>::
361 WeakPointerToBase<T>(std::move(r))
362{
363}
364
365/**
366 *
367 */
368template<class T>
369INLINE const typename WeakConstPointerTo<T>::To &WeakConstPointerTo<T>::
370operator *() const {
371 assert(!this->was_deleted());
372 return *((To *)WeakPointerToBase<T>::_void_ptr);
373}
374
375/**
376 *
377 */
378template<class T>
379INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
380operator -> () const {
381 assert(!this->was_deleted());
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
392template<class T>
394operator const T * () const {
395 assert(!this->was_deleted());
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 */
408template<class T>
410lock() const {
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 */
420template<class T>
421INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
422p() const {
423 assert(!this->was_deleted());
425}
426
427/**
428 * Returns the original pointer value, even if the object has since been
429 * deleted.
430 */
431template<class T>
432INLINE const typename WeakConstPointerTo<T>::To *WeakConstPointerTo<T>::
433get_orig() const {
435}
436
437/**
438 *
439 */
440template<class T>
442operator = (const To *ptr) {
443 ((WeakConstPointerTo<T> *)this)->reassign((To *)ptr);
444 return *this;
445}
446
447/**
448 *
449 */
450template<class T>
452operator = (const PointerTo<T> &copy) {
453 ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
454 return *this;
455}
456
457/**
458 *
459 */
460template<class T>
462operator = (const ConstPointerTo<T> &copy) {
463 ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
464 return *this;
465}
466
467/**
468 *
469 */
470template<class T>
472operator = (const WeakPointerTo<T> &copy) {
473 ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
474 return *this;
475}
476
477/**
478 *
479 */
480template<class T>
483 ((WeakConstPointerTo<T> *)this)->reassign(*(const PointerToBase<T> *)&copy);
484 return *this;
485}
486
487/**
488 *
489 */
490template<class T>
492operator = (WeakPointerTo<T> &&from) noexcept {
493 this->reassign(std::move(from));
494 return *this;
495}
496
497/**
498 *
499 */
500template<class T>
502operator = (WeakConstPointerTo<T> &&from) noexcept {
503 this->reassign(std::move(from));
504 return *this;
505}
506
507/**
508 *
509 */
510template<class T>
511template<class Y>
513operator = (const WeakPointerTo<Y> &r) noexcept {
514 this->reassign(r);
515 return *this;
516}
517
518/**
519 *
520 */
521template<class T>
522template<class Y>
524operator = (const WeakConstPointerTo<Y> &r) noexcept {
525 this->reassign(r);
526 return *this;
527}
528
529/**
530 *
531 */
532template<class T>
533template<class Y>
535operator = (const PointerTo<Y> &r) noexcept {
536 this->reassign(r);
537 return *this;
538}
539
540/**
541 *
542 */
543template<class T>
544template<class Y>
546operator = (const ConstPointerTo<Y> &r) noexcept {
547 this->reassign(r);
548 return *this;
549}
550
551/**
552 *
553 */
554template<class T>
555template<class Y>
557operator = (WeakPointerTo<Y> &&r) noexcept {
558 this->reassign(std::move(r));
559 return *this;
560}
561
562/**
563 *
564 */
565template<class T>
566template<class Y>
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.
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,...
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...
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.