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