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
FindApproxPath::output_component
void output_component(std::ostream &out, int index) const
Formats the nth component of the path to the indicated output stream.
Definition: findApproxPath.I:96
pvector< Component >
findApproxPath.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FindApproxPath::case_insensitive
bool case_insensitive() const
Returns true if the search is case-insensitive, false if it is case- sensitive.
Definition: findApproxPath.I:88
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FindApproxPath::add_match_name_glob
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,...
Definition: findApproxPath.cxx:301
FindApproxPath::add_match_exact_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.
Definition: findApproxPath.cxx:322
FindApproxPath::get_num_components
int get_num_components() const
Returns the number of components in the path.
Definition: findApproxPath.I:28
FindApproxPath::add_flags
bool add_flags(const std::string &str_flags)
Adds a sequence of control flags.
Definition: findApproxPath.cxx:164
FindApproxPath::add_match_pointer
void add_match_pointer(PandaNode *pointer, int flags)
Adds a component that must match a particular node exactly, by pointer.
Definition: findApproxPath.cxx:397
pnotify.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
FindApproxPath::add_component
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 ...
Definition: findApproxPath.cxx:220
FindApproxPath::return_stashed
bool return_stashed() const
Returns true if this path allows returning of stashed nodes, false otherwise.
Definition: findApproxPath.I:79
FindApproxPath::return_hidden
bool return_hidden() const
Returns true if this path allows returning of hidden nodes, false otherwise.
Definition: findApproxPath.I:70
FindApproxPath::matches_stashed
bool matches_stashed(int index) const
Returns true if the nth component of the path matches a stashed node only, false otherwise.
Definition: findApproxPath.I:57
FindApproxPath
This class is local to this package only; it doesn't get exported.
Definition: findApproxPath.h:31
FindApproxPath::add_match_one
void add_match_one(int flags)
Adds a component that will match any node (but not a chain of many nodes).
Definition: findApproxPath.cxx:375
FindApproxPath::add_match_name
void add_match_name(const std::string &name, int flags)
Adds a component that must match the name of a node exactly.
Definition: findApproxPath.cxx:288
FindApproxPath::add_match_tag_value
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.
Definition: findApproxPath.cxx:362
FindApproxPath::add_match_tag
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...
Definition: findApproxPath.cxx:348
globPattern.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FindApproxPath::add_match_inexact_type
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.
Definition: findApproxPath.cxx:335
PandaNode
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
GlobPattern
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
Definition: globPattern.h:32
FindApproxPath::is_component_match_many
bool is_component_match_many(int index) const
Returns true if the nth component is of type match_many, which will require special handling.
Definition: findApproxPath.I:37
FindApproxPath::add_string
bool add_string(const std::string &str_path)
Adds a sequence of components separated by slashes, followed optionally by a semicolon and a sequence...
Definition: findApproxPath.cxx:117
FindApproxPath::matches_component
bool matches_component(int index, PandaNode *node) const
Returns true if the nth component of the path matches the indicated node, false otherwise.
Definition: findApproxPath.I:47
typeHandle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FindApproxPath::add_match_many
void add_match_many(int flags)
Adds a component that will match a chain of zero or more consecutive nodes.
Definition: findApproxPath.cxx:386