Panda3D
weakNodePath.I
1 // Filename: weakNodePath.I
2 // Created by: drose (29Sep04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: WeakNodePath::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE WeakNodePath::
22 WeakNodePath(const NodePath &node_path) :
23  _head(node_path._head),
24  _backup_key(0)
25 {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: WeakNodePath::Copy Constructor
30 // Access: Public
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE WeakNodePath::
34 WeakNodePath(const WeakNodePath &copy) :
35  _head(copy._head),
36  _backup_key(copy._backup_key)
37 {
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: WeakNodePath::Destructor
42 // Access: Public
43 // Description:
44 ////////////////////////////////////////////////////////////////////
45 INLINE WeakNodePath::
46 ~WeakNodePath() {
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: WeakNodePath::operator =
51 // Access: Public
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 INLINE void WeakNodePath::
55 operator = (const NodePath &node_path) {
56  _head = node_path._head;
57  _backup_key = 0;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: WeakNodePath::operator =
62 // Access: Public
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 INLINE void WeakNodePath::
66 operator = (const WeakNodePath &copy) {
67  _head = copy._head;
68  _backup_key = copy._backup_key;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: WeakNodePath::is_empty
73 // Access: Public
74 // Description: Returns true if the NodePath contains no nodes, or if
75 // it has been deleted.
76 ////////////////////////////////////////////////////////////////////
77 INLINE bool WeakNodePath::
78 is_empty() const {
79  return _head == (NodePathComponent *)NULL || _head.was_deleted();
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: WeakNodePath::was_deleted
84 // Access: Public
85 // Description: Returns true if the NodePath we were referencing has
86 // been quietly deleted outside of the WeakNodePath.
87 ////////////////////////////////////////////////////////////////////
88 INLINE bool WeakNodePath::
89 was_deleted() const {
90  return _head != (NodePathComponent *)NULL && _head.was_deleted();
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: WeakNodePath::get_node_path
95 // Access: Public
96 // Description: Returns the NodePath held within this object.
97 ////////////////////////////////////////////////////////////////////
99 get_node_path() const {
100  nassertr_always(!was_deleted(), NodePath::fail());
101  NodePath result;
102  result._head = _head;
103  return result;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: WeakNodePath::node
108 // Access: Public
109 // Description: Returns the PandaNode held within this object.
110 ////////////////////////////////////////////////////////////////////
112 node() const {
113  nassertr_always(!is_empty(), (PandaNode *)NULL);
114  return _head->get_node();
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: WeakNodePath::operator ==
119 // Access: Published
120 // Description: Returns true if the two paths are equivalent; that
121 // is, if they contain the same list of nodes in the same
122 // order.
123 ////////////////////////////////////////////////////////////////////
124 INLINE bool WeakNodePath::
125 operator == (const NodePath &other) const {
126  return _head == other._head;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: WeakNodePath::operator !=
131 // Access: Published
132 // Description: Returns true if the two paths are not equivalent.
133 ////////////////////////////////////////////////////////////////////
134 INLINE bool WeakNodePath::
135 operator != (const NodePath &other) const {
136  return _head != other._head;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: WeakNodePath::operator <
141 // Access: Published
142 // Description: Returns true if this NodePath sorts before the other
143 // one, false otherwise. The sorting order of two
144 // nonequivalent NodePaths is consistent but undefined,
145 // and is useful only for storing NodePaths in a sorted
146 // container like an STL set.
147 ////////////////////////////////////////////////////////////////////
148 INLINE bool WeakNodePath::
149 operator < (const NodePath &other) const {
150  return _head < other._head;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: WeakNodePath::compare_to
155 // Access: Published
156 // Description: Returns a number less than zero if this NodePath
157 // sorts before the other one, greater than zero if it
158 // sorts after, or zero if they are equivalent.
159 //
160 // Two NodePaths are considered equivalent if they
161 // consist of exactly the same list of nodes in the same
162 // order. Otherwise, they are different; different
163 // NodePaths will be ranked in a consistent but
164 // undefined ordering; the ordering is useful only for
165 // placing the NodePaths in a sorted container like an
166 // STL set.
167 ////////////////////////////////////////////////////////////////////
168 INLINE int WeakNodePath::
169 compare_to(const NodePath &other) const {
170  if (_head != other._head) {
171  return _head < other._head ? -1 : 1;
172  }
173  return 0;
174 }
175 
176 ////////////////////////////////////////////////////////////////////
177 // Function: WeakNodePath::operator ==
178 // Access: Published
179 // Description: Returns true if the two paths are equivalent; that
180 // is, if they contain the same list of nodes in the same
181 // order.
182 ////////////////////////////////////////////////////////////////////
183 INLINE bool WeakNodePath::
184 operator == (const WeakNodePath &other) const {
185  return _head == other._head;
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: WeakNodePath::operator !=
190 // Access: Published
191 // Description: Returns true if the two paths are not equivalent.
192 ////////////////////////////////////////////////////////////////////
193 INLINE bool WeakNodePath::
194 operator != (const WeakNodePath &other) const {
195  return _head != other._head;
196 }
197 
198 ////////////////////////////////////////////////////////////////////
199 // Function: WeakNodePath::operator <
200 // Access: Published
201 // Description: Returns true if this WeakNodePath sorts before the other
202 // one, false otherwise. The sorting order of two
203 // nonequivalent WeakNodePaths is consistent but undefined,
204 // and is useful only for storing WeakNodePaths in a sorted
205 // container like an STL set.
206 ////////////////////////////////////////////////////////////////////
207 INLINE bool WeakNodePath::
208 operator < (const WeakNodePath &other) const {
209  return _head < other._head;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: WeakNodePath::compare_to
214 // Access: Published
215 // Description: Returns a number less than zero if this WeakNodePath
216 // sorts before the other one, greater than zero if it
217 // sorts after, or zero if they are equivalent.
218 //
219 // Two WeakNodePaths are considered equivalent if they
220 // consist of exactly the same list of nodes in the same
221 // order. Otherwise, they are different; different
222 // WeakNodePaths will be ranked in a consistent but
223 // undefined ordering; the ordering is useful only for
224 // placing the WeakNodePaths in a sorted container like an
225 // STL set.
226 ////////////////////////////////////////////////////////////////////
227 INLINE int WeakNodePath::
228 compare_to(const WeakNodePath &other) const {
229  if (_head != other._head) {
230  return _head < other._head ? -1 : 1;
231  }
232  return 0;
233 }
234 
235 ////////////////////////////////////////////////////////////////////
236 // Function: WeakNodePath::get_key
237 // Access: Public
238 // Description: Returns the same values as NodePath::get_key().
239 ////////////////////////////////////////////////////////////////////
240 INLINE int WeakNodePath::
241 get_key() const {
242  if (is_empty() || was_deleted()) {
243  return _backup_key;
244  }
245  ((WeakNodePath *)this)->_backup_key = _head->get_key();
246  return _backup_key;
247 }
248 
249 INLINE ostream &operator << (ostream &out, const WeakNodePath &node_path) {
250  node_path.output(out);
251  return out;
252 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
int get_key() const
Returns the same values as NodePath::get_key().
Definition: weakNodePath.I:241
bool is_empty() const
Returns true if the NodePath contains no nodes, or if it has been deleted.
Definition: weakNodePath.I:78
NodePath get_node_path() const
Returns the NodePath held within this object.
Definition: weakNodePath.I:99
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
Definition: nodePath.I:185
PandaNode * node() const
Returns the PandaNode held within this object.
Definition: weakNodePath.I:112
This class is a wrapper around a NodePath that, unlike the actual NodePath class, doesn&#39;t hold a refe...
Definition: weakNodePath.h:37
int compare_to(const NodePath &other) const
Returns a number less than zero if this NodePath sorts before the other one, greater than zero if it ...
Definition: weakNodePath.I:169
bool operator<(const NodePath &other) const
Returns true if this NodePath sorts before the other one, false otherwise.
Definition: weakNodePath.I:149
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: weakNodePath.I:125
bool operator!=(const NodePath &other) const
Returns true if the two paths are not equivalent.
Definition: weakNodePath.I:135
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
bool was_deleted() const
Returns true if the NodePath we were referencing has been quietly deleted outside of the WeakNodePath...
Definition: weakNodePath.I:89
This is one component of a NodePath.