Panda3D
weakNodePath.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 weakNodePath.I
10  * @author drose
11  * @date 2004-09-29
12  */
13 
14 /**
15  *
16  */
17 INLINE WeakNodePath::
18 WeakNodePath(const NodePath &node_path) :
19  _head(node_path._head),
20  _backup_key(0)
21 {
22 }
23 
24 /**
25  *
26  */
27 INLINE WeakNodePath::
28 WeakNodePath(const WeakNodePath &copy) :
29  _head(copy._head),
30  _backup_key(copy._backup_key)
31 {
32 }
33 
34 /**
35  *
36  */
37 INLINE WeakNodePath::
38 ~WeakNodePath() {
39 }
40 
41 /**
42  *
43  */
44 INLINE void WeakNodePath::
45 operator = (const NodePath &node_path) {
46  _head = node_path._head;
47  _backup_key = 0;
48 }
49 
50 /**
51  *
52  */
53 INLINE void WeakNodePath::
54 operator = (const WeakNodePath &copy) {
55  _head = copy._head;
56  _backup_key = copy._backup_key;
57 }
58 
59 /**
60  * Sets this NodePath to the empty NodePath. It will no longer point to any
61  * node.
62  */
63 INLINE void WeakNodePath::
64 clear() {
65  _head.clear();
66  _backup_key = 0;
67 }
68 
69 /**
70  * Returns true if this NodePath points to a valid, non-null node.
71  */
72 INLINE WeakNodePath::
73 operator bool () const {
74  return _head.is_valid_pointer();
75 }
76 
77 /**
78  * Returns true if the NodePath contains no nodes, or if it has been deleted.
79  */
80 INLINE bool WeakNodePath::
81 is_empty() const {
82  return _head == nullptr || _head.was_deleted();
83 }
84 
85 /**
86  * Returns true if the NodePath we were referencing has been quietly deleted
87  * outside of the WeakNodePath.
88  */
89 INLINE bool WeakNodePath::
90 was_deleted() const {
91  return _head != nullptr && _head.was_deleted();
92 }
93 
94 /**
95  * Returns the NodePath held within this object, or an empty NodePath with the
96  * error flag set if the object was deleted.
97  */
99 get_node_path() const {
100  NodePath result;
101  result._head = _head.lock();
102  if (!_head.is_null() && result._head == nullptr) {
103  result._error_type = NodePath::ET_fail;
104  }
105  return result;
106 }
107 
108 /**
109  * Returns the PandaNode held within this object, or nullptr if the object was
110  * deleted.
111  */
112 INLINE PT(PandaNode) WeakNodePath::
113 node() const {
114  if (auto head = _head.lock()) {
115  return head->get_node();
116  } else {
117  return nullptr;
118  }
119 }
120 
121 /**
122  * Returns true if the two paths are equivalent; that is, if they contain the
123  * same list of nodes in the same order.
124  */
125 INLINE bool WeakNodePath::
126 operator == (const NodePath &other) const {
127  return _head.get_orig() == other._head && !_head.was_deleted();
128 }
129 
130 /**
131  * Returns true if the two paths are not equivalent.
132  */
133 INLINE bool WeakNodePath::
134 operator != (const NodePath &other) const {
135  return !operator == (other);
136 }
137 
138 /**
139  * Returns true if this NodePath sorts before the other one, false otherwise.
140  * The sorting order of two nonequivalent NodePaths is consistent but
141  * undefined, and is useful only for storing NodePaths in a sorted container
142  * like an STL set.
143  */
144 INLINE bool WeakNodePath::
145 operator < (const NodePath &other) const {
146  return _head.owner_before(other._head);
147 }
148 
149 /**
150  * Returns a number less than zero if this NodePath sorts before the other
151  * one, greater than zero if it sorts after, or zero if they are equivalent.
152  *
153  * Two NodePaths are considered equivalent if they consist of exactly the same
154  * list of nodes in the same order. Otherwise, they are different; different
155  * NodePaths will be ranked in a consistent but undefined ordering; the
156  * ordering is useful only for placing the NodePaths in a sorted container
157  * like an STL set.
158  */
159 INLINE int WeakNodePath::
160 compare_to(const NodePath &other) const {
161  if (operator != (other)) {
162  return _head.owner_before(other._head) ? -1 : 1;
163  }
164  return 0;
165 }
166 
167 /**
168  * Returns true if the two paths are equivalent; that is, if they contain the
169  * same list of nodes in the same order.
170  */
171 INLINE bool WeakNodePath::
172 operator == (const WeakNodePath &other) const {
173  return !_head.owner_before(other._head) && !other._head.owner_before(_head);
174 }
175 
176 /**
177  * Returns true if the two paths are not equivalent.
178  */
179 INLINE bool WeakNodePath::
180 operator != (const WeakNodePath &other) const {
181  return _head.owner_before(other._head) || other._head.owner_before(_head);
182 }
183 
184 /**
185  * Returns true if this WeakNodePath sorts before the other one, false
186  * otherwise. The sorting order of two nonequivalent WeakNodePaths is
187  * consistent but undefined, and is useful only for storing WeakNodePaths in a
188  * sorted container like an STL set.
189  */
190 INLINE bool WeakNodePath::
191 operator < (const WeakNodePath &other) const {
192  return _head.owner_before(other._head);
193 }
194 
195 /**
196  * Returns a number less than zero if this WeakNodePath sorts before the other
197  * one, greater than zero if it sorts after, or zero if they are equivalent.
198  *
199  * Two WeakNodePaths are considered equivalent if they consist of exactly the
200  * same list of nodes in the same order. Otherwise, they are different;
201  * different WeakNodePaths will be ranked in a consistent but undefined
202  * ordering; the ordering is useful only for placing the WeakNodePaths in a
203  * sorted container like an STL set.
204  */
205 INLINE int WeakNodePath::
206 compare_to(const WeakNodePath &other) const {
207  return other._head.owner_before(_head) - _head.owner_before(other._head);
208 }
209 
210 /**
211  * Returns the same values as NodePath::get_key().
212  */
213 INLINE int WeakNodePath::
214 get_key() const {
215  if (auto head = _head.lock()) {
216  _backup_key = head->get_key();
217  }
218  return _backup_key;
219 }
220 
221 INLINE std::ostream &operator << (std::ostream &out, const WeakNodePath &node_path) {
222  node_path.output(out);
223  return out;
224 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
void clear()
Sets this NodePath to the empty NodePath.
Definition: weakNodePath.I:64
PT(PandaNode) WeakNodePath
Returns the PandaNode held within this object, or nullptr if the object was deleted.
Definition: weakNodePath.I:112
bool is_empty() const
Returns true if the NodePath contains no nodes, or if it has been deleted.
Definition: weakNodePath.I:81
NodePath get_node_path() const
Returns the NodePath held within this object, or an empty NodePath with the error flag set if the obj...
Definition: weakNodePath.I:99
bool operator==(const NodePath &other) const
Returns true if the two paths are equivalent; that is, if they contain the same list of nodes in the ...
Definition: nodePath.I:1921
This class is a wrapper around a NodePath that, unlike the actual NodePath class, doesn't hold a refe...
Definition: weakNodePath.h:32
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
bool was_deleted() const
Returns true if the NodePath we were referencing has been quietly deleted outside of the WeakNodePath...
Definition: weakNodePath.I:90