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