00001 // Filename: findApproxPath.I 00002 // Created by: drose (13Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: FindApproxPath::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE FindApproxPath:: 00026 FindApproxPath() { 00027 _return_hidden = true; 00028 _return_stashed = false; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: FindApproxPath::add_match_name 00033 // Access: Public 00034 // Description: Adds a component that must match the name of a node 00035 // exactly. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE void FindApproxPath:: 00038 add_match_name(const string &name, int flags) { 00039 Component comp; 00040 comp._type = CT_match_name; 00041 comp._name = name; 00042 comp._flags = flags; 00043 _path.push_back(comp); 00044 } 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: FindApproxPath::add_match_name_glob 00048 // Access: Public 00049 // Description: Adds a component that must match the name of a node 00050 // using standard shell globbing rules, with wildcard 00051 // characters accepted. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE void FindApproxPath:: 00054 add_match_name_glob(const string &name, int flags) { 00055 Component comp; 00056 comp._type = CT_match_name_glob; 00057 comp._name = name; 00058 comp._flags = flags; 00059 _path.push_back(comp); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: FindApproxPath::add_match_exact_type 00064 // Access: Public 00065 // Description: Adds a component that must match the type of a node 00066 // exactly, with no derived types matching. 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE void FindApproxPath:: 00069 add_match_exact_type(TypeHandle type, int flags) { 00070 Component comp; 00071 comp._type = CT_match_exact_type; 00072 comp._type_handle = type; 00073 comp._flags = flags; 00074 _path.push_back(comp); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: FindApproxPath::add_match_inexact_type 00079 // Access: Public 00080 // Description: Adds a component that must match the type of a node 00081 // or be a base class of the node's type. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE void FindApproxPath:: 00084 add_match_inexact_type(TypeHandle type, int flags) { 00085 Component comp; 00086 comp._type = CT_match_inexact_type; 00087 comp._type_handle = type; 00088 comp._flags = flags; 00089 _path.push_back(comp); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: FindApproxPath::add_match_one 00094 // Access: Public 00095 // Description: Adds a component that will match any node (but not a 00096 // chain of many nodes). 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void FindApproxPath:: 00099 add_match_one(int flags) { 00100 Component comp; 00101 comp._type = CT_match_one; 00102 comp._flags = flags; 00103 _path.push_back(comp); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: FindApproxPath::add_match_many 00108 // Access: Public 00109 // Description: Adds a component that will match a chain of zero or 00110 // more consecutive nodes. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE void FindApproxPath:: 00113 add_match_many(int flags) { 00114 Component comp; 00115 comp._type = CT_match_many; 00116 comp._flags = flags; 00117 _path.push_back(comp); 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: FindApproxPath::add_match_pointer 00122 // Access: Public 00123 // Description: Adds a component that must match a particular node 00124 // exactly, by pointer. 00125 //////////////////////////////////////////////////////////////////// 00126 INLINE void FindApproxPath:: 00127 add_match_pointer(PandaNode *pointer, int flags) { 00128 Component comp; 00129 comp._type = CT_match_pointer; 00130 comp._pointer = pointer; 00131 comp._flags = flags; 00132 _path.push_back(comp); 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: FindApproxPath::get_num_components 00137 // Access: Public 00138 // Description: Returns the number of components in the path. 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE int FindApproxPath:: 00141 get_num_components() const { 00142 return _path.size(); 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: FindApproxPath::is_component_match_many 00147 // Access: Public 00148 // Description: Returns true if the nth component is of type 00149 // match_many, which will require special handling. 00150 //////////////////////////////////////////////////////////////////// 00151 INLINE bool FindApproxPath:: 00152 is_component_match_many(int index) const { 00153 nassertr(index >= 0 && index < (int)_path.size(), false); 00154 return (_path[index]._type == CT_match_many); 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: FindApproxPath::matches_component 00159 // Access: Public 00160 // Description: Returns true if the nth component of the path matches 00161 // the indicated node, false otherwise. 00162 //////////////////////////////////////////////////////////////////// 00163 INLINE bool FindApproxPath:: 00164 matches_component(int index, PandaNode *node) const { 00165 nassertr(index >= 0 && index < (int)_path.size(), false); 00166 return (_path[index].matches(node)); 00167 } 00168 00169 //////////////////////////////////////////////////////////////////// 00170 // Function: FindApproxPath::matches_stashed 00171 // Access: Public 00172 // Description: Returns true if the nth component of the path matches 00173 // a stashed node only, false otherwise. 00174 //////////////////////////////////////////////////////////////////// 00175 INLINE bool FindApproxPath:: 00176 matches_stashed(int index) const { 00177 if (index >= 0 && index < (int)_path.size()) { 00178 return ((_path[index]._flags & CF_stashed) != 0); 00179 } else { 00180 return false; 00181 } 00182 } 00183 00184 //////////////////////////////////////////////////////////////////// 00185 // Function: FindApproxPath::return_hidden 00186 // Access: Public 00187 // Description: Returns true if this path allows returning of hidden 00188 // nodes, false otherwise. 00189 //////////////////////////////////////////////////////////////////// 00190 INLINE bool FindApproxPath:: 00191 return_hidden() const { 00192 return _return_hidden; 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function: FindApproxPath::return_stashed 00197 // Access: Public 00198 // Description: Returns true if this path allows returning of stashed 00199 // nodes, false otherwise. 00200 //////////////////////////////////////////////////////////////////// 00201 INLINE bool FindApproxPath:: 00202 return_stashed() const { 00203 return _return_stashed; 00204 } 00205 00206 //////////////////////////////////////////////////////////////////// 00207 // Function: FindApproxPath::output_component 00208 // Access: Public 00209 // Description: Formats the nth component of the path to the 00210 // indicated output stream. 00211 //////////////////////////////////////////////////////////////////// 00212 INLINE void FindApproxPath:: 00213 output_component(ostream &out, int index) const { 00214 nassertv(index >= 0 && index < (int)_path.size()); 00215 out << _path[index]; 00216 }