Panda3D
 All Classes Functions Variables Enumerations
findApproxPath.h
1 // Filename: FindApproxPath.h
2 // Created by: drose (13Mar02)
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 #ifndef FINDAPPROXPATH_H
16 #define FINDAPPROXPATH_H
17 
18 #include "pandabase.h"
19 
20 #include "globPattern.h"
21 #include "typeHandle.h"
22 #include "pvector.h"
23 #include "pnotify.h"
24 
25 class PandaNode;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : FindApproxPath
29 // Description : This class is local to this package only; it doesn't
30 // get exported. It chops a string path, as supplied to
31 // find_up() or find_down(), and breaks it up into its
32 // component pieces.
33 ////////////////////////////////////////////////////////////////////
35 public:
36  INLINE FindApproxPath();
37 
38  bool add_string(const string &str_path);
39  bool add_flags(const string &str_flags);
40  bool add_component(string str_component);
41 
42  void add_match_name(const string &name, int flags);
43  void add_match_name_glob(const string &glob, int flags);
44  void add_match_exact_type(TypeHandle type, int flags);
45  void add_match_inexact_type(TypeHandle type, int flags);
46  void add_match_tag(const string &key, int flags);
47  void add_match_tag_value(const string &key, const string &value, int flags);
48 
49  void add_match_one(int flags);
50  void add_match_many(int flags);
51  void add_match_pointer(PandaNode *pointer, int flags);
52 
53  INLINE int get_num_components() const;
54  INLINE bool is_component_match_many(int index) const;
55  INLINE bool matches_component(int index, PandaNode *node) const;
56  INLINE bool matches_stashed(int index) const;
57 
58  INLINE bool return_hidden() const;
59  INLINE bool return_stashed() const;
60  INLINE bool case_insensitive() const;
61 
62  void output(ostream &out) const;
63  INLINE void output_component(ostream &out, int index) const;
64 
65 #if !defined(WIN32_VC) && !defined(WIN64_VC)
66 // Visual C++ won't let us define the ostream operator functions for
67 // these guys if they're private--even though we declare them friends.
68 private:
69 #endif
70  enum ComponentType {
71  CT_match_name,
72  CT_match_name_insensitive,
73  CT_match_name_glob,
74  CT_match_exact_type,
75  CT_match_inexact_type,
76  CT_match_tag,
77  CT_match_tag_value,
78  CT_match_one,
79  CT_match_many,
80  CT_match_pointer
81  };
82  enum ComponentFlags {
83  CF_stashed = 0x001,
84  };
85 
86  class Component {
87  public:
88  bool matches(PandaNode *node) const;
89  void output(ostream &out) const;
90 
91  ComponentType _type;
92  string _name;
93  GlobPattern _glob;
94  TypeHandle _type_handle;
95  PandaNode *_pointer;
96  int _flags;
97  };
98 
99  typedef pvector<Component> Path;
100  Path _path;
101 
102  bool _return_hidden;
103  bool _return_stashed;
104  bool _case_insensitive;
105 
106 friend ostream &operator << (ostream &, FindApproxPath::ComponentType);
107 friend INLINE ostream &operator << (ostream &, const FindApproxPath::Component &);
108 };
109 
110 ostream &
111 operator << (ostream &out, FindApproxPath::ComponentType type);
112 
113 INLINE ostream &
114 operator << (ostream &out, const FindApproxPath::Component &component) {
115  component.output(out);
116  return out;
117 }
118 
119 INLINE ostream &
120 operator << (ostream &out, const FindApproxPath &path) {
121  path.output(out);
122  return out;
123 }
124 
125 #include "findApproxPath.I"
126 
127 #endif
void add_match_pointer(PandaNode *pointer, int flags)
Adds a component that must match a particular node exactly, by pointer.
bool matches_component(int index, PandaNode *node) const
Returns true if the nth component of the path matches the indicated node, false otherwise.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This class is local to this package only; it doesn&#39;t get exported.
bool return_hidden() const
Returns true if this path allows returning of hidden nodes, false otherwise.
bool add_flags(const string &str_flags)
Adds a sequence of control flags.
void add_match_one(int flags)
Adds a component that will match any node (but not a chain of many nodes).
void add_match_inexact_type(TypeHandle type, int flags)
Adds a component that must match the type of a node or be a base class of the node&#39;s type...
void add_match_exact_type(TypeHandle type, int flags)
Adds a component that must match the type of a node exactly, with no derived types matching...
void add_match_name_glob(const string &glob, int flags)
Adds a component that must match the name of a node using standard shell globbing rules...
void add_match_many(int flags)
Adds a component that will match a chain of zero or more consecutive nodes.
void output_component(ostream &out, int index) const
Formats the nth component of the path to the indicated output stream.
bool matches_stashed(int index) const
Returns true if the nth component of the path matches a stashed node only, false otherwise.
bool return_stashed() const
Returns true if this path allows returning of stashed nodes, false otherwise.
void add_match_name(const string &name, int flags)
Adds a component that must match the name of a node exactly.
int get_num_components() const
Returns the number of components in the path.
bool is_component_match_many(int index) const
Returns true if the nth component is of type match_many, which will require special handling...
void add_match_tag_value(const string &key, const string &value, int flags)
Adds a component that will match a node that has a tag with the indicated key.
bool case_insensitive() const
Returns true if the search is case-insensitive, false if it is case-sensitive.
void add_match_tag(const string &key, int flags)
Adds a component that will match a node that has a tag with the indicated key, no matter what the val...
bool add_string(const string &str_path)
Adds a sequence of components separated by slashes, followed optionally by a semicolon and a sequence...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
bool add_component(string str_component)
Adds a single component to the path sequence, defined by a string as might appear between slashes in ...
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
Definition: globPattern.h:37