Panda3D
configVariableFilename.I
1 // Filename: configVariableFilename.I
2 // Created by: drose (22Nov04)
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: ConfigVariableFilename::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE ConfigVariableFilename::
22 ConfigVariableFilename(const string &name) :
23  ConfigVariable(name, VT_filename),
24  _local_modified(initial_invalid_cache())
25 {
26  _core->set_used();
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: ConfigVariableFilename::Constructor
31 // Access: Published
32 // Description:
33 ////////////////////////////////////////////////////////////////////
34 INLINE ConfigVariableFilename::
35 ConfigVariableFilename(const string &name, const Filename &default_value,
36  const string &description, int flags) :
37 #ifdef PRC_SAVE_DESCRIPTIONS
38  ConfigVariable(name, VT_filename, description, flags),
39 #else
40  ConfigVariable(name, VT_filename, string(), flags),
41 #endif
42  _local_modified(initial_invalid_cache())
43 {
44  _core->set_default_value(default_value);
45  _core->set_used();
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ConfigVariableFilename::operator =
50 // Access: Published
51 // Description: Reassigns the variable's local value.
52 ////////////////////////////////////////////////////////////////////
53 INLINE void ConfigVariableFilename::
54 operator = (const Filename &value) {
55  set_value(value);
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: ConfigVariableFilename::Filename typecast operator
60 // Access: Published
61 // Description: Returns the variable's value as a Filename.
62 ////////////////////////////////////////////////////////////////////
63 INLINE ConfigVariableFilename::
64 operator const Filename &() const {
65  return get_ref_value();
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: ConfigVariableFilename::c_str
70 // Access: Public
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 INLINE const char *ConfigVariableFilename::
74 c_str() const {
75  return get_ref_value().c_str();
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: ConfigVariableFilename::empty
80 // Access: Public
81 // Description:
82 ////////////////////////////////////////////////////////////////////
83 INLINE bool ConfigVariableFilename::
84 empty() const {
85  return get_ref_value().empty();
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: ConfigVariableFilename::length
90 // Access: Public
91 // Description:
92 ////////////////////////////////////////////////////////////////////
93 INLINE size_t ConfigVariableFilename::
94 length() const {
95  return get_ref_value().length();
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: ConfigVariableFilename::Indexing operator
100 // Access: Public
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 INLINE char ConfigVariableFilename::
104 operator [] (int n) const {
105  return get_ref_value()[n];
106 }
107 
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: ConfigVariableFilename::get_fullpath
111 // Access: Public
112 // Description: Returns the entire filename: directory, basename,
113 // extension. This is the same thing returned by the
114 // string typecast operator, so this function is a
115 // little redundant.
116 ////////////////////////////////////////////////////////////////////
117 INLINE string ConfigVariableFilename::
118 get_fullpath() const {
119  return get_ref_value().get_fullpath();
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: ConfigVariableFilename::get_dirname
124 // Access: Public
125 // Description: Returns the directory part of the filename. This is
126 // everything in the filename up to, but not including
127 // the rightmost slash.
128 ////////////////////////////////////////////////////////////////////
129 INLINE string ConfigVariableFilename::
130 get_dirname() const {
131  return get_ref_value().get_dirname();
132 }
133 
134 ////////////////////////////////////////////////////////////////////
135 // Function: ConfigVariableFilename::get_basename
136 // Access: Public
137 // Description: Returns the basename part of the filename. This is
138 // everything in the filename after the rightmost slash,
139 // including any extensions.
140 ////////////////////////////////////////////////////////////////////
141 INLINE string ConfigVariableFilename::
142 get_basename() const {
143  return get_ref_value().get_basename();
144 }
145 
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ConfigVariableFilename::get_fullpath_wo_extension
149 // Access: Public
150 // Description: Returns the full filename--directory and basename
151 // parts--except for the extension.
152 ////////////////////////////////////////////////////////////////////
153 INLINE string ConfigVariableFilename::
155  return get_ref_value().get_fullpath_wo_extension();
156 }
157 
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: ConfigVariableFilename::get_basename_wo_extension
161 // Access: Public
162 // Description: Returns the basename part of the filename, without
163 // the file extension.
164 ////////////////////////////////////////////////////////////////////
165 INLINE string ConfigVariableFilename::
167  return get_ref_value().get_basename_wo_extension();
168 }
169 
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: ConfigVariableFilename::get_extension
173 // Access: Public
174 // Description: Returns the file extension. This is everything after
175 // the rightmost dot, if there is one, or the empty
176 // string if there is not.
177 ////////////////////////////////////////////////////////////////////
178 INLINE string ConfigVariableFilename::
179 get_extension() const {
180  return get_ref_value().get_extension();
181 }
182 
183 ////////////////////////////////////////////////////////////////////
184 // Function: ConfigVariableFilename::Equality operator
185 // Access: Public
186 // Description:
187 ////////////////////////////////////////////////////////////////////
188 INLINE bool ConfigVariableFilename::
189 operator == (const Filename &other) const {
190  return get_ref_value() == other;
191 }
192 
193 ////////////////////////////////////////////////////////////////////
194 // Function: ConfigVariableFilename::Inequality operator
195 // Access: Public
196 // Description:
197 ////////////////////////////////////////////////////////////////////
198 INLINE bool ConfigVariableFilename::
199 operator != (const Filename &other) const {
200  return get_ref_value() != other;
201 }
202 
203 ////////////////////////////////////////////////////////////////////
204 // Function: ConfigVariableFilename::Ordering operator
205 // Access: Public
206 // Description:
207 ////////////////////////////////////////////////////////////////////
208 INLINE bool ConfigVariableFilename::
209 operator < (const Filename &other) const {
210  return get_ref_value() < other;
211 }
212 
213 ////////////////////////////////////////////////////////////////////
214 // Function: ConfigVariableFilename::set_value
215 // Access: Published
216 // Description: Reassigns the variable's local value.
217 ////////////////////////////////////////////////////////////////////
218 INLINE void ConfigVariableFilename::
219 set_value(const Filename &value) {
220  set_string_value(value);
221 }
222 
223 ////////////////////////////////////////////////////////////////////
224 // Function: ConfigVariableFilename::get_value
225 // Access: Published
226 // Description: Returns the variable's value.
227 ////////////////////////////////////////////////////////////////////
229 get_value() const {
230  // This returns a concrete rather than a reference by design, to
231  // avoid problems with scope. When we call this method from Python,
232  // we'd like to be able to keep the Filename value around longer
233  // than the lifetime of the config variable itself.
234  return get_ref_value();
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: ConfigVariableFilename::get_default_value
239 // Access: Published
240 // Description: Returns the variable's default value.
241 ////////////////////////////////////////////////////////////////////
245  if (decl != (ConfigDeclaration *)NULL) {
246  return Filename::expand_from(decl->get_string_value());
247  }
248  return Filename();
249 }
250 
251 ////////////////////////////////////////////////////////////////////
252 // Function: ConfigVariableFilename::get_word
253 // Access: Published
254 // Description: Returns the variable's nth value.
255 ////////////////////////////////////////////////////////////////////
257 get_word(int n) const {
259 }
260 
261 ////////////////////////////////////////////////////////////////////
262 // Function: ConfigVariableFilename::set_word
263 // Access: Published
264 // Description: Reassigns the variable's nth value. This makes a
265 // local copy of the variable's overall value.
266 ////////////////////////////////////////////////////////////////////
267 INLINE void ConfigVariableFilename::
268 set_word(int n, const Filename &value) {
269  set_string_word(n, value);
270 }
271 
272 ////////////////////////////////////////////////////////////////////
273 // Function: ConfigVariableFilename::get_ref_value
274 // Access: Private
275 // Description: Returns the variable's value, as a reference into the
276 // config variable itself. This is the internal method
277 // that implements get_value(), which returns a
278 // concrete.
279 ////////////////////////////////////////////////////////////////////
280 INLINE const Filename &ConfigVariableFilename::
281 get_ref_value() const {
282  TAU_PROFILE("const Filename &ConfigVariableFilename::get_ref_value() const", " ", TAU_USER);
283  if (!is_cache_valid(_local_modified)) {
284  ((ConfigVariableFilename *)this)->reload_cache();
285  }
286  return _cache;
287 }
string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:424
Filename get_default_value() const
Returns the variable&#39;s default value.
string get_basename() const
Returns the basename part of the filename.
Definition: filename.I:436
Filename get_value() const
Returns the variable&#39;s value.
void set_word(int n, const Filename &value)
Reassigns the variable&#39;s nth value.
string get_dirname() const
Returns the directory part of the filename.
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition: filename.I:398
string get_string_word(int n) const
Returns the string value of the nth word of the variable&#39;s value, or empty string if there is no nth ...
This is a convenience class to specialize ConfigVariable as a Filename type.
const ConfigDeclaration * get_default_value() const
Returns the default variable specified for this variable.
string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
static Filename expand_from(const string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e...
Definition: filename.cxx:418
string get_extension() const
Returns the file extension.
Definition: filename.I:477
string get_basename() const
Returns the basename part of the filename.
This is a generic, untyped ConfigVariable.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void set_value(const Filename &value)
Reassigns the variable&#39;s local value.
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
Definition: filename.I:460
void set_string_value(const string &value)
Changes the value assigned to this variable.
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
Definition: filename.I:448
string get_extension() const
Returns the file extension.
A single declaration of a config variable, typically defined as one line in a .prc file...
void operator=(const Filename &value)
Reassigns the variable&#39;s local value.
void set_string_word(int n, const string &value)
Changes the nth word to the indicated value without affecting the other words.
const string & get_string_value() const
Returns the value assigned to this variable.
Filename get_word(int n) const
Returns the variable&#39;s nth value.