Panda3D

configVariableSearchPath.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 configVariableSearchPath.I
10 * @author drose
11 * @date 2004-10-21
12 */
13
14 /**
15 *
16 */
17 INLINE ConfigVariableSearchPath::
18 ConfigVariableSearchPath(const std::string &name,
19 const std::string &description, int flags) :
20 #ifdef PRC_SAVE_DESCRIPTIONS
21 ConfigVariableBase(name, VT_search_path, description, flags),
22 #else
23 ConfigVariableBase(name, VT_search_path, std::string(), flags),
24 #endif
25 _default_value(Filename(".")),
26 _local_modified(initial_invalid_cache())
27 {
28 // A SearchPath variable implicitly defines a default value of the empty
29 // string. This is just to prevent the core variable from complaining
30 // should anyone ask for its solitary value.
31 if (_core->get_default_value() == nullptr) {
32 _core->set_default_value("");
33 }
34 _core->set_used();
35 }
36
37 /**
38 *
39 */
40 INLINE ConfigVariableSearchPath::
41 ConfigVariableSearchPath(const std::string &name,
42 const DSearchPath &default_value,
43 const std::string &description, int flags) :
44 #ifdef PRC_SAVE_DESCRIPTIONS
45 ConfigVariableBase(name, VT_search_path, description, flags),
46 #else
47 ConfigVariableBase(name, VT_search_path, std::string(), flags),
48 #endif
49 _default_value(default_value),
50 _local_modified(initial_invalid_cache())
51 {
52 // A SearchPath variable implicitly defines a default value of the empty
53 // string. This is just to prevent the core variable from complaining
54 // should anyone ask for its solitary value.
55 if (_core->get_default_value() == nullptr) {
56 _core->set_default_value("");
57 }
58 _core->set_used();
59 }
60
61 /**
62 *
63 */
64 INLINE ConfigVariableSearchPath::
65 ConfigVariableSearchPath(const std::string &name,
66 const std::string &default_value,
67 const std::string &description, int flags) :
68 #ifdef PRC_SAVE_DESCRIPTIONS
69 ConfigVariableBase(name, VT_search_path, description, flags),
70 #else
71 ConfigVariableBase(name, VT_search_path, std::string(), flags),
72 #endif
73 _default_value(Filename(default_value)),
74 _local_modified(initial_invalid_cache())
75 {
76 // A SearchPath variable implicitly defines a default value of the empty
77 // string. This is just to prevent the core variable from complaining
78 // should anyone ask for its solitary value.
79 if (_core->get_default_value() == nullptr) {
80 _core->set_default_value("");
81 }
82 _core->set_used();
83 }
84
85 /**
86 *
87 */
88 INLINE ConfigVariableSearchPath::
89 ~ConfigVariableSearchPath() {
90 }
91
92 /**
93 * Returns the variable's value.
94 */
95 INLINE ConfigVariableSearchPath::
96 operator DSearchPath () const {
97 return get_value();
98 }
99
100 /**
101 *
102 */
103 INLINE DSearchPath ConfigVariableSearchPath::
104 get_value() const {
105 TAU_PROFILE("const DSearchPath &ConfigVariableSearchPath::get_value() const", " ", TAU_USER);
106 DSearchPath value;
107 _lock.lock();
108 if (!is_cache_valid(_local_modified)) {
109 ((ConfigVariableSearchPath *)this)->reload_search_path();
110 }
111 value = _cache;
112 _lock.unlock();
113 return value;
114 }
115
116 /**
117 *
118 */
119 INLINE const DSearchPath &ConfigVariableSearchPath::
120 get_default_value() const {
121 return _default_value;
122 }
123
124 /**
125 * Removes all the directories locally added to the search list, and restores
126 * it to its original form.
127 */
128 INLINE bool ConfigVariableSearchPath::
129 clear_local_value() {
130 _lock.lock();
131 nassertr(_core != nullptr, false);
132
133 bool any_to_clear = !_prefix.is_empty() || _postfix.is_empty();
134 _prefix.clear();
135 _postfix.clear();
136
137 if (_core->clear_local_value()) {
138 any_to_clear = true;
139 }
140
141 _local_modified = initial_invalid_cache();
142 _lock.unlock();
143 return any_to_clear;
144 }
145
146 /**
147 * Removes all the directories locally added to the search list, and restores
148 * it to its original form.
149 */
150 INLINE void ConfigVariableSearchPath::
151 clear() {
152 clear_local_value();
153 }
154
155 /**
156 * Adds a new directory to the end of the search list.
157 */
158 INLINE void ConfigVariableSearchPath::
159 append_directory(const Filename &directory) {
160 _lock.lock();
161 _postfix.append_directory(directory);
162 _local_modified = initial_invalid_cache();
163 _lock.unlock();
164 }
165
166 /**
167 * Adds a new directory to the front of the search list.
168 */
169 INLINE void ConfigVariableSearchPath::
170 prepend_directory(const Filename &directory) {
171 _lock.lock();
172 _prefix.prepend_directory(directory);
173 _local_modified = initial_invalid_cache();
174 _lock.unlock();
175 }
176
177 /**
178 * Adds all of the directories listed in the search path to the end of the
179 * search list.
180 */
181 INLINE void ConfigVariableSearchPath::
182 append_path(const std::string &path, const std::string &separator) {
183 _lock.lock();
184 _postfix.append_path(path, separator);
185 _local_modified = initial_invalid_cache();
186 _lock.unlock();
187 }
188
189 /**
190 * Adds all of the directories listed in the search path to the end of the
191 * search list.
192 */
193 INLINE void ConfigVariableSearchPath::
194 append_path(const DSearchPath &path) {
195 _lock.lock();
196 _postfix.append_path(path);
197 _local_modified = initial_invalid_cache();
198 _lock.unlock();
199 }
200
201 /**
202 * Adds all of the directories listed in the search path to the beginning of
203 * the search list.
204 */
205 INLINE void ConfigVariableSearchPath::
206 prepend_path(const DSearchPath &path) {
207 _lock.lock();
208 _prefix.prepend_path(path);
209 _local_modified = initial_invalid_cache();
210 _lock.unlock();
211 }
212
213 /**
214 * Returns true if the search list is empty, false otherwise.
215 */
216 INLINE bool ConfigVariableSearchPath::
217 is_empty() const {
218 return get_value().is_empty();
219 }
220
221 /**
222 * Returns the number of directories on the search list.
223 */
224 INLINE size_t ConfigVariableSearchPath::
225 get_num_directories() const {
226 return get_value().get_num_directories();
227 }
228
229 /**
230 * Returns the nth directory on the search list.
231 */
232 INLINE Filename ConfigVariableSearchPath::
233 get_directory(size_t n) const {
234 Filename dir;
235 _lock.lock();
236 dir = _cache.get_directory(n);
237 _lock.unlock();
238 return dir;
239 }
240
241 /**
242 * Searches all the directories in the search list for the indicated file, in
243 * order. Returns the full matching pathname of the first match if found, or
244 * the empty string if not found.
245 */
246 INLINE Filename ConfigVariableSearchPath::
247 find_file(const Filename &filename) const {
248 return get_value().find_file(filename);
249 }
250
251 /**
252 * Searches all the directories in the search list for the indicated file, in
253 * order. Fills up the results list with *all* of the matching filenames
254 * found, if any. Returns the number of matches found.
255 *
256 * It is the responsibility of the the caller to clear the results list first;
257 * otherwise, the newly-found files will be appended to the list.
258 */
259 INLINE size_t ConfigVariableSearchPath::
260 find_all_files(const Filename &filename,
261 DSearchPath::Results &results) const {
262 return get_value().find_all_files(filename, results);
263 }
264
265 /**
266 * This variant of find_all_files() returns the new Results object, instead of
267 * filling on in on the parameter list. This is a little more convenient to
268 * call from Python.
269 */
270 INLINE DSearchPath::Results ConfigVariableSearchPath::
271 find_all_files(const Filename &filename) const {
272 return get_value().find_all_files(filename);
273 }
274
275 /**
276 *
277 */
278 INLINE void ConfigVariableSearchPath::
279 output(std::ostream &out) const {
280 get_value().output(out);
281 }
282
283 /**
284 *
285 */
286 INLINE void ConfigVariableSearchPath::
287 write(std::ostream &out) const {
288 get_value().write(out);
289 }
290
291 INLINE std::ostream &
292 operator << (std::ostream &out, const ConfigVariableSearchPath &variable) {
293 variable.output(out);
294 return out;
295 }
ConfigVariableBase
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...
Definition: configVariableBase.h:45
ConfigVariableSearchPath
This is similar to a ConfigVariableList, but it returns its list as a DSearchPath,...
Definition: configVariableSearchPath.h:36
ConfigVariableSearchPath::clear
void clear()
Removes all the directories locally added to the search list, and restores it to its original form.
Definition: configVariableSearchPath.I:151
ConfigVariableSearchPath::prepend_path
void prepend_path(const DSearchPath &path)
Adds all of the directories listed in the search path to the beginning of the search list.
Definition: configVariableSearchPath.I:206
ConfigVariableSearchPath::append_directory
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
Definition: configVariableSearchPath.I:159
ConfigVariableSearchPath::clear_local_value
bool clear_local_value()
Removes all the directories locally added to the search list, and restores it to its original form.
Definition: configVariableSearchPath.I:129
ConfigVariableSearchPath::find_all_files
size_t find_all_files(const Filename &filename, DSearchPath::Results &results) const
Searches all the directories in the search list for the indicated file, in order.
Definition: configVariableSearchPath.I:260
ConfigVariableSearchPath::prepend_directory
void prepend_directory(const Filename &directory)
Adds a new directory to the front of the search list.
Definition: configVariableSearchPath.I:170
ConfigVariableSearchPath::get_num_directories
get_num_directories
Returns the number of directories on the search list.
Definition: configVariableSearchPath.h:70
ConfigVariableSearchPath::is_empty
bool is_empty() const
Returns true if the search list is empty, false otherwise.
Definition: configVariableSearchPath.I:217
ConfigVariableSearchPath::get_directory
get_directory
Returns the nth directory on the search list.
Definition: configVariableSearchPath.h:70
ConfigVariableSearchPath::append_path
void append_path(const std::string &path, const std::string &separator=std::string())
Adds all of the directories listed in the search path to the end of the search list.
Definition: configVariableSearchPath.I:182
ConfigVariableSearchPath::find_file
Filename find_file(const Filename &filename) const
Searches all the directories in the search list for the indicated file, in order.
Definition: configVariableSearchPath.I:247
DSearchPath::Results
Definition: dSearchPath.h:30
DSearchPath
This class stores a list of directories that can be searched, in order, to locate a particular file.
Definition: dSearchPath.h:28
DSearchPath::is_empty
bool is_empty() const
Returns true if the search list is empty, false otherwise.
Definition: dSearchPath.cxx:217
DSearchPath::append_path
void append_path(const std::string &path, const std::string &separator=std::string())
Adds all of the directories listed in the search path to the end of the search list.
Definition: dSearchPath.cxx:164
DSearchPath::prepend_path
void prepend_path(const DSearchPath &path)
Adds all of the directories listed in the search path to the beginning of the search list.
Definition: dSearchPath.cxx:204
DSearchPath::prepend_directory
void prepend_directory(const Filename &directory)
Adds a new directory to the front of the search list.
Definition: dSearchPath.cxx:155
DSearchPath::clear
void clear()
Removes all the directories from the search list.
Definition: dSearchPath.cxx:139
DSearchPath::append_directory
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
Definition: dSearchPath.cxx:147
DSearchPath::get_directory
get_directory
Returns the nth directory on the search list.
Definition: dSearchPath.h:76
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39