Panda3D

Loading...
Searching...
No Matches
weakPointerToBase.h
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 weakPointerToBase.h
10 * @author drose
11 * @date 2004-09-27
12 */
13
14#ifndef WEAKPOINTERTOBASE_H
15#define WEAKPOINTERTOBASE_H
16
17#include "pandabase.h"
18#include "pointerToBase.h"
19#include "weakPointerToVoid.h"
20
21/**
22 * This is the base class for PointerTo and ConstPointerTo. Don't try to use
23 * it directly; use either derived class instead.
24 */
25 template <class T>
26 class WeakPointerToBase : public WeakPointerToVoid {
27 public:
28 typedef T To;
29
30 protected:
31 constexpr WeakPointerToBase() noexcept = default;
32 INLINE explicit WeakPointerToBase(To *ptr);
33 INLINE WeakPointerToBase(const PointerToBase<T> &copy);
34 INLINE WeakPointerToBase(const WeakPointerToBase<T> &copy);
35 INLINE WeakPointerToBase(WeakPointerToBase<T> &&from) noexcept;
36 template<class Y>
37 INLINE WeakPointerToBase(const WeakPointerToBase<Y> &r);
38 template<class Y>
39 INLINE WeakPointerToBase(WeakPointerToBase<Y> &&r) noexcept;
40
41 INLINE ~WeakPointerToBase();
42
43 void reassign(To *ptr);
44 INLINE void reassign(const PointerToBase<To> &copy);
45 INLINE void reassign(const WeakPointerToBase<To> &copy);
46 INLINE void reassign(WeakPointerToBase<To> &&from) noexcept;
47 template<class Y>
48 INLINE void reassign(const WeakPointerToBase<Y> &copy);
49 template<class Y>
50 INLINE void reassign(WeakPointerToBase<Y> &&from) noexcept;
51
52 INLINE void update_type(To *ptr);
53
54 INLINE void lock_into(PointerToBase<To> &locked) const;
55
56 // No assignment or retrieval functions are declared in WeakPointerToBase,
57 // because we will have to specialize on const vs. non-const later.
58
59 public:
60 // These comparison functions are common to all things PointerTo, so they're
61 // defined up here.
62#ifndef CPPPARSER
63 INLINE bool operator == (const To *other) const;
64 INLINE bool operator != (const To *other) const;
65 INLINE bool operator > (const To *other) const;
66 INLINE bool operator <= (const To *other) const;
67 INLINE bool operator >= (const To *other) const;
68 INLINE bool operator == (To *other) const;
69 INLINE bool operator != (To *other) const;
70 INLINE bool operator > (To *other) const;
71 INLINE bool operator <= (To *other) const;
72 INLINE bool operator >= (To *other) const;
73
74 INLINE bool operator == (std::nullptr_t) const;
75 INLINE bool operator != (std::nullptr_t) const;
76 INLINE bool operator > (std::nullptr_t) const;
77 INLINE bool operator <= (std::nullptr_t) const;
78 INLINE bool operator >= (std::nullptr_t) const;
79
80 INLINE bool operator == (const WeakPointerToBase<To> &other) const;
81 INLINE bool operator != (const WeakPointerToBase<To> &other) const;
82 INLINE bool operator > (const WeakPointerToBase<To> &other) const;
83 INLINE bool operator <= (const WeakPointerToBase<To> &other) const;
84 INLINE bool operator >= (const WeakPointerToBase<To> &other) const;
85
86 INLINE bool operator == (const PointerToBase<To> &other) const;
87 INLINE bool operator != (const PointerToBase<To> &other) const;
88 INLINE bool operator > (const PointerToBase<To> &other) const;
89 INLINE bool operator <= (const PointerToBase<To> &other) const;
90 INLINE bool operator >= (const PointerToBase<To> &other) const;
91
92 INLINE bool operator < (const To *other) const;
93 INLINE bool operator < (std::nullptr_t) const;
94 INLINE bool operator < (const WeakPointerToBase<To> &other) const;
95 INLINE bool operator < (const PointerToBase<To> &other) const;
96#endif // CPPPARSER
97
98 template<class Y>
99 INLINE bool owner_before(const WeakPointerToBase<Y> &other) const noexcept;
100 template<class Y>
101 INLINE bool owner_before(const PointerToBase<Y> &other) const noexcept;
102
103 // This is needed to be able to access the privates of other instantiations.
104 template<typename Y> friend class WeakPointerToBase;
105
106PUBLISHED:
107 INLINE void clear();
108 INLINE void refresh() const;
109
110 void output(std::ostream &out) const;
111};
112
113 template<class T>
114INLINE std::ostream &operator <<(std::ostream &out, const WeakPointerToBase<T> &pointer) {
115 pointer.output(out);
116 return out;
117}
118
119#include "weakPointerToBase.I"
120
121#endif
PointerToBase
This is the base class for PointerTo and ConstPointerTo.
Definition pointerToBase.h:29
WeakPointerToBase
This is the base class for PointerTo and ConstPointerTo.
Definition weakPointerToBase.h:26
WeakPointerToBase::output
void output(std::ostream &out) const
A handy function to output PointerTo's as a hex pointer followed by a reference count.
Definition weakPointerToBase.I:656
WeakPointerToBase::clear
void clear()
A convenient way to set the PointerTo object to NULL.
Definition weakPointerToBase.I:623
WeakPointerToBase::owner_before
bool owner_before(const PointerToBase< Y > &other) const noexcept
Defines an ordering that is guaranteed to remain consistent even after this weak pointer has expired.
Definition weakPointerToBase.I:610
WeakPointerToBase::refresh
void refresh() const
Informs the WeakPointerTo object that its pointer is no longer deleted.
Definition weakPointerToBase.I:644
WeakPointerToBase::owner_before
bool owner_before(const WeakPointerToBase< Y > &other) const noexcept
Defines an ordering that is guaranteed to remain consistent even after the weak pointers have expired...
Definition weakPointerToBase.I:597
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerToBase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
weakPointerToBase.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
weakPointerToVoid.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.