Panda3D
Loading...
Searching...
No Matches
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
24class 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 */
32public:
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.
65private:
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
97 Path _path;
98
99 bool _return_hidden;
100 bool _return_stashed;
101 bool _case_insensitive;
102
103friend std::ostream &operator << (std::ostream &, FindApproxPath::ComponentType);
104friend INLINE std::ostream &operator << (std::ostream &, const FindApproxPath::Component &);
105};
106
107std::ostream &
108operator << (std::ostream &out, FindApproxPath::ComponentType type);
109
110INLINE std::ostream &
111operator << (std::ostream &out, const FindApproxPath::Component &component) {
112 component.output(out);
113 return out;
114}
115
116INLINE std::ostream &
117operator << (std::ostream &out, const FindApproxPath &path) {
118 path.output(out);
119 return out;
120}
121
122#include "findApproxPath.I"
123
124#endif
This class is local to this package only; it doesn't get exported.
bool matches_component(int index, PandaNode *node) const
Returns true if the nth component of the path matches the indicated node, false otherwise.
void output_component(std::ostream &out, int index) const
Formats the nth component of the path to the indicated output stream.
bool return_hidden() const
Returns true if this path allows returning of hidden nodes, false otherwise.
void add_match_one(int flags)
Adds a component that will match any node (but not a chain of many nodes).
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.
bool add_flags(const std::string &str_flags)
Adds a sequence of control flags.
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_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 case_insensitive() const
Returns true if the search is case-insensitive, false if it is case- sensitive.
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 ...
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(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...
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_many(int flags)
Adds a component that will match a chain of zero or more consecutive nodes.
bool add_string(const std::string &str_path)
Adds a sequence of components separated by slashes, followed optionally by a semicolon and a sequence...
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_pointer(PandaNode *pointer, int flags)
Adds a component that must match a particular node exactly, by pointer.
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,...
int get_num_components() const
Returns the number of components in the path.
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
Definition globPattern.h:32
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.