Panda3D
pathReplace.I
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 pathReplace.I
10  * @author drose
11  * @date 2003-02-07
12  */
13 
14 /**
15  * Resets the error flag to the no-error state. had_error() will return false
16  * until a new error is generated.
17  */
18 INLINE void PathReplace::
20  _error_flag = false;
21 }
22 
23 /**
24  * Returns true if an error was detected since the last call to clear_error(),
25  * false otherwise.
26  */
27 INLINE bool PathReplace::
28 had_error() const {
29  return _error_flag;
30 }
31 
32 /**
33  * Removes all the patterns from the specification.
34  */
35 INLINE void PathReplace::
36 clear() {
37  clear_error();
38  _entries.clear();
39 }
40 
41 /**
42  * Adds the indicated original/replace pattern to the specification. If a
43  * filename is encountered whose initial prefix matches the indicated
44  * orig_prefix, that prefix will be replaced with replacement_prefix.
45  */
46 INLINE void PathReplace::
47 add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix) {
48  _entries.push_back(Entry(orig_prefix, replacement_prefix));
49 }
50 
51 /**
52  * Returns the number of original/replace patterns that have been added.
53  */
54 INLINE int PathReplace::
56  return _entries.size();
57 }
58 
59 /**
60  * Returns the original prefix associated with the nth pattern.
61  */
62 INLINE const std::string &PathReplace::
63 get_orig_prefix(int n) const {
64  nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._orig_prefix);
65  return _entries[n]._orig_prefix;
66 }
67 
68 /**
69  * Returns the replacement prefix associated with the nth pattern.
70  */
71 INLINE const std::string &PathReplace::
72 get_replacement_prefix(int n) const {
73  nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._replacement_prefix);
74  return _entries[n]._replacement_prefix;
75 }
76 
77 /**
78  * Returns true if the PathReplace object specifies no action, or false if
79  * convert_path() may do something.
80  */
81 INLINE bool PathReplace::
82 is_empty() const {
83  return (_entries.empty() && _path.is_empty() && _path_store == PS_keep);
84 }
85 
86 /**
87  * Calls match_path() followed by store_path(), to replace the initial prefix
88  * and then convert the file for storing, as the user indicated.
89  */
91 convert_path(const Filename &orig_filename, const DSearchPath &additional_path) {
92  Filename fullpath, outpath;
93  full_convert_path(orig_filename, additional_path, fullpath, outpath);
94  return outpath;
95 }
96 
97 /**
98  *
99  */
100 INLINE PathReplace::Component::
101 Component(const std::string &component) :
102  _orig_prefix(component),
103  _double_star(component == "**")
104 {
105 }
106 
107 /**
108  *
109  */
110 INLINE PathReplace::Component::
111 Component(const PathReplace::Component &copy) :
112  _orig_prefix(copy._orig_prefix),
113  _double_star(copy._double_star)
114 {
115 }
116 
117 /**
118  *
119  */
120 INLINE void PathReplace::Component::
121 operator = (const PathReplace::Component &copy) {
122  _orig_prefix = copy._orig_prefix;
123  _double_star = copy._double_star;
124 }
125 
126 /**
127  *
128  */
129 INLINE PathReplace::Entry::
130 Entry(const PathReplace::Entry &copy) :
131  _orig_prefix(copy._orig_prefix),
132  _orig_components(copy._orig_components),
133  _is_local(copy._is_local),
134  _replacement_prefix(copy._replacement_prefix)
135 {
136 }
137 
138 /**
139  *
140  */
141 INLINE void PathReplace::Entry::
142 operator = (const PathReplace::Entry &copy) {
143  _orig_prefix = copy._orig_prefix;
144  _orig_components = copy._orig_components;
145  _is_local = copy._is_local;
146  _replacement_prefix = copy._replacement_prefix;
147 }
const std::string & get_orig_prefix(int n) const
Returns the original prefix associated with the nth pattern.
Definition: pathReplace.I:63
bool is_empty() const
Returns true if the search list is empty, false otherwise.
void full_convert_path(const Filename &orig_filename, const DSearchPath &additional_path, Filename &resolved_path, Filename &output_path)
Converts the input path into two different forms: A resolved path, and an output path.
int get_num_patterns() const
Returns the number of original/replace patterns that have been added.
Definition: pathReplace.I:55
void add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix)
Adds the indicated original/replace pattern to the specification.
Definition: pathReplace.I:47
const std::string & get_replacement_prefix(int n) const
Returns the replacement prefix associated with the nth pattern.
Definition: pathReplace.I:72
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
bool is_empty() const
Returns true if the PathReplace object specifies no action, or false if convert_path() may do somethi...
Definition: pathReplace.I:82
void clear()
Removes all the patterns from the specification.
Definition: pathReplace.I:36
This class stores a list of directories that can be searched, in order, to locate a particular file.
Definition: dSearchPath.h:28
void clear_error()
Resets the error flag to the no-error state.
Definition: pathReplace.I:19
bool had_error() const
Returns true if an error was detected since the last call to clear_error(), false otherwise.
Definition: pathReplace.I:28
Filename convert_path(const Filename &orig_filename, const DSearchPath &additional_path=DSearchPath())
Calls match_path() followed by store_path(), to replace the initial prefix and then convert the file ...
Definition: pathReplace.I:91