Panda3D

weakNodePath.I

00001 // Filename: weakNodePath.I
00002 // Created by:  drose (29Sep04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: WeakNodePath::Constructor
00018 //       Access: Public
00019 //  Description: 
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE WeakNodePath::
00022 WeakNodePath(const NodePath &node_path) :
00023   _head(node_path._head),
00024   _backup_key(0)
00025 {
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: WeakNodePath::Copy Constructor
00030 //       Access: Public
00031 //  Description: 
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE WeakNodePath::
00034 WeakNodePath(const WeakNodePath &copy) :
00035   _head(copy._head),
00036   _backup_key(copy._backup_key)
00037 {
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: WeakNodePath::Destructor
00042 //       Access: Public
00043 //  Description: 
00044 ////////////////////////////////////////////////////////////////////
00045 INLINE WeakNodePath::
00046 ~WeakNodePath() {
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: WeakNodePath::operator = 
00051 //       Access: Public
00052 //  Description: 
00053 ////////////////////////////////////////////////////////////////////
00054 INLINE void WeakNodePath::
00055 operator = (const NodePath &node_path) {
00056   _head = node_path._head;
00057   _backup_key = 0;
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: WeakNodePath::operator = 
00062 //       Access: Public
00063 //  Description: 
00064 ////////////////////////////////////////////////////////////////////
00065 INLINE void WeakNodePath::
00066 operator = (const WeakNodePath &copy) {
00067   _head = copy._head;
00068   _backup_key = copy._backup_key;
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: WeakNodePath::is_empty
00073 //       Access: Public
00074 //  Description: Returns true if the NodePath contains no nodes, or if
00075 //               it has been deleted.
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE bool WeakNodePath::
00078 is_empty() const {
00079   return _head == (NodePathComponent *)NULL || _head.was_deleted();
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: WeakNodePath::was_deleted
00084 //       Access: Public
00085 //  Description: Returns true if the NodePath we were referencing has
00086 //               been quietly deleted outside of the WeakNodePath.
00087 ////////////////////////////////////////////////////////////////////
00088 INLINE bool WeakNodePath::
00089 was_deleted() const {
00090   return _head != (NodePathComponent *)NULL && _head.was_deleted();
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: WeakNodePath::get_node_path
00095 //       Access: Public
00096 //  Description: Returns the NodePath held within this object.
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE NodePath WeakNodePath::
00099 get_node_path() const {
00100   nassertr_always(!was_deleted(), NodePath::fail());
00101   NodePath result;
00102   result._head = _head;
00103   return result;
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: WeakNodePath::node
00108 //       Access: Public
00109 //  Description: Returns the PandaNode held within this object.
00110 ////////////////////////////////////////////////////////////////////
00111 INLINE PandaNode *WeakNodePath::
00112 node() const {
00113   nassertr_always(!is_empty(), (PandaNode *)NULL);
00114   return _head->get_node();
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: WeakNodePath::operator ==
00119 //       Access: Published
00120 //  Description: Returns true if the two paths are equivalent; that
00121 //               is, if they contain the same list of nodes in the same
00122 //               order.
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE bool WeakNodePath::
00125 operator == (const NodePath &other) const {
00126   return _head == other._head;
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: WeakNodePath::operator !=
00131 //       Access: Published
00132 //  Description: Returns true if the two paths are not equivalent.
00133 ////////////////////////////////////////////////////////////////////
00134 INLINE bool WeakNodePath::
00135 operator != (const NodePath &other) const {
00136   return _head != other._head;
00137 }
00138 
00139 ////////////////////////////////////////////////////////////////////
00140 //     Function: WeakNodePath::operator <
00141 //       Access: Published
00142 //  Description: Returns true if this NodePath sorts before the other
00143 //               one, false otherwise.  The sorting order of two
00144 //               nonequivalent NodePaths is consistent but undefined,
00145 //               and is useful only for storing NodePaths in a sorted
00146 //               container like an STL set.
00147 ////////////////////////////////////////////////////////////////////
00148 INLINE bool WeakNodePath::
00149 operator < (const NodePath &other) const {
00150   return _head < other._head;
00151 }
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: WeakNodePath::compare_to
00155 //       Access: Published
00156 //  Description: Returns a number less than zero if this NodePath
00157 //               sorts before the other one, greater than zero if it
00158 //               sorts after, or zero if they are equivalent.
00159 //
00160 //               Two NodePaths are considered equivalent if they
00161 //               consist of exactly the same list of nodes in the same
00162 //               order.  Otherwise, they are different; different
00163 //               NodePaths will be ranked in a consistent but
00164 //               undefined ordering; the ordering is useful only for
00165 //               placing the NodePaths in a sorted container like an
00166 //               STL set.
00167 ////////////////////////////////////////////////////////////////////
00168 INLINE int WeakNodePath::
00169 compare_to(const NodePath &other) const {
00170   if (_head != other._head) {
00171     return _head < other._head ? -1 : 1;
00172   }
00173   return 0;
00174 }
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: WeakNodePath::operator ==
00178 //       Access: Published
00179 //  Description: Returns true if the two paths are equivalent; that
00180 //               is, if they contain the same list of nodes in the same
00181 //               order.
00182 ////////////////////////////////////////////////////////////////////
00183 INLINE bool WeakNodePath::
00184 operator == (const WeakNodePath &other) const {
00185   return _head == other._head;
00186 }
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: WeakNodePath::operator !=
00190 //       Access: Published
00191 //  Description: Returns true if the two paths are not equivalent.
00192 ////////////////////////////////////////////////////////////////////
00193 INLINE bool WeakNodePath::
00194 operator != (const WeakNodePath &other) const {
00195   return _head != other._head;
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: WeakNodePath::operator <
00200 //       Access: Published
00201 //  Description: Returns true if this WeakNodePath sorts before the other
00202 //               one, false otherwise.  The sorting order of two
00203 //               nonequivalent WeakNodePaths is consistent but undefined,
00204 //               and is useful only for storing WeakNodePaths in a sorted
00205 //               container like an STL set.
00206 ////////////////////////////////////////////////////////////////////
00207 INLINE bool WeakNodePath::
00208 operator < (const WeakNodePath &other) const {
00209   return _head < other._head;
00210 }
00211 
00212 ////////////////////////////////////////////////////////////////////
00213 //     Function: WeakNodePath::compare_to
00214 //       Access: Published
00215 //  Description: Returns a number less than zero if this WeakNodePath
00216 //               sorts before the other one, greater than zero if it
00217 //               sorts after, or zero if they are equivalent.
00218 //
00219 //               Two WeakNodePaths are considered equivalent if they
00220 //               consist of exactly the same list of nodes in the same
00221 //               order.  Otherwise, they are different; different
00222 //               WeakNodePaths will be ranked in a consistent but
00223 //               undefined ordering; the ordering is useful only for
00224 //               placing the WeakNodePaths in a sorted container like an
00225 //               STL set.
00226 ////////////////////////////////////////////////////////////////////
00227 INLINE int WeakNodePath::
00228 compare_to(const WeakNodePath &other) const {
00229   if (_head != other._head) {
00230     return _head < other._head ? -1 : 1;
00231   }
00232   return 0;
00233 }
00234 
00235 ////////////////////////////////////////////////////////////////////
00236 //     Function: WeakNodePath::get_key
00237 //       Access: Public
00238 //  Description: Returns the same values as NodePath::get_key().
00239 ////////////////////////////////////////////////////////////////////
00240 INLINE int WeakNodePath::
00241 get_key() const {
00242   if (is_empty() || was_deleted()) {
00243     return _backup_key;
00244   }
00245   ((WeakNodePath *)this)->_backup_key = _head->get_key();
00246   return _backup_key;
00247 }
00248 
00249 INLINE ostream &operator << (ostream &out, const WeakNodePath &node_path) {
00250   node_path.output(out);
00251   return out;
00252 }
 All Classes Functions Variables Enumerations