Panda3D
configVariableFilename.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 configVariableFilename.I
10  * @author drose
11  * @date 2004-11-22
12  */
13 
14 /**
15  *
16  */
17 INLINE ConfigVariableFilename::
18 ConfigVariableFilename(const std::string &name) :
19  ConfigVariable(name, VT_filename),
20  _local_modified(initial_invalid_cache())
21 {
22  _core->set_used();
23 }
24 
25 /**
26  *
27  */
28 INLINE ConfigVariableFilename::
29 ConfigVariableFilename(const std::string &name, const Filename &default_value,
30  const std::string &description, int flags) :
31 #ifdef PRC_SAVE_DESCRIPTIONS
32  ConfigVariable(name, VT_filename, description, flags),
33 #else
34  ConfigVariable(name, VT_filename, std::string(), flags),
35 #endif
36  _local_modified(initial_invalid_cache())
37 {
38  _core->set_default_value(default_value);
39  _core->set_used();
40 }
41 
42 /**
43  * Reassigns the variable's local value.
44  */
45 INLINE void ConfigVariableFilename::
46 operator = (const Filename &value) {
47  set_value(value);
48 }
49 
50 /**
51  * Returns the variable's value as a Filename.
52  */
53 INLINE ConfigVariableFilename::
54 operator const Filename &() const {
55  return get_ref_value();
56 }
57 
58 /**
59  *
60  */
61 INLINE const char *ConfigVariableFilename::
62 c_str() const {
63  return get_ref_value().c_str();
64 }
65 
66 /**
67  *
68  */
69 INLINE bool ConfigVariableFilename::
70 empty() const {
71  return get_ref_value().empty();
72 }
73 
74 /**
75  *
76  */
77 INLINE size_t ConfigVariableFilename::
78 length() const {
79  return get_ref_value().length();
80 }
81 
82 /**
83  *
84  */
85 INLINE char ConfigVariableFilename::
86 operator [] (size_t n) const {
87  return get_ref_value()[n];
88 }
89 
90 
91 /**
92  * Returns the entire filename: directory, basename, extension. This is the
93  * same thing returned by the string typecast operator, so this function is a
94  * little redundant.
95  */
96 INLINE std::string ConfigVariableFilename::
97 get_fullpath() const {
98  return get_ref_value().get_fullpath();
99 }
100 
101 /**
102  * Returns the directory part of the filename. This is everything in the
103  * filename up to, but not including the rightmost slash.
104  */
105 INLINE std::string ConfigVariableFilename::
106 get_dirname() const {
107  return get_ref_value().get_dirname();
108 }
109 
110 /**
111  * Returns the basename part of the filename. This is everything in the
112  * filename after the rightmost slash, including any extensions.
113  */
114 INLINE std::string ConfigVariableFilename::
115 get_basename() const {
116  return get_ref_value().get_basename();
117 }
118 
119 
120 /**
121  * Returns the full filename--directory and basename parts--except for the
122  * extension.
123  */
124 INLINE std::string ConfigVariableFilename::
126  return get_ref_value().get_fullpath_wo_extension();
127 }
128 
129 
130 /**
131  * Returns the basename part of the filename, without the file extension.
132  */
133 INLINE std::string ConfigVariableFilename::
135  return get_ref_value().get_basename_wo_extension();
136 }
137 
138 
139 /**
140  * Returns the file extension. This is everything after the rightmost dot, if
141  * there is one, or the empty string if there is not.
142  */
143 INLINE std::string ConfigVariableFilename::
144 get_extension() const {
145  return get_ref_value().get_extension();
146 }
147 
148 /**
149  *
150  */
151 INLINE bool ConfigVariableFilename::
152 operator == (const Filename &other) const {
153  return get_ref_value() == other;
154 }
155 
156 /**
157  *
158  */
159 INLINE bool ConfigVariableFilename::
160 operator != (const Filename &other) const {
161  return get_ref_value() != other;
162 }
163 
164 /**
165  *
166  */
167 INLINE bool ConfigVariableFilename::
168 operator < (const Filename &other) const {
169  return get_ref_value() < other;
170 }
171 
172 /**
173  * Reassigns the variable's local value.
174  */
175 INLINE void ConfigVariableFilename::
176 set_value(const Filename &value) {
177  set_string_value(value);
178 }
179 
180 /**
181  * Returns the variable's value.
182  */
183 INLINE Filename ConfigVariableFilename::
184 get_value() const {
185  // This returns a concrete rather than a reference by design, to avoid
186  // problems with scope. When we call this method from Python, we'd like to
187  // be able to keep the Filename value around longer than the lifetime of the
188  // config variable itself.
189  return get_ref_value();
190 }
191 
192 /**
193  * Returns the variable's default value.
194  */
195 INLINE Filename ConfigVariableFilename::
196 get_default_value() const {
197  const ConfigDeclaration *decl = ConfigVariable::get_default_value();
198  if (decl != nullptr) {
199  return Filename::expand_from(decl->get_string_value());
200  }
201  return Filename();
202 }
203 
204 /**
205  * Returns the variable's nth value.
206  */
208 get_word(size_t n) const {
209  return Filename::expand_from(get_string_word(n));
210 }
211 
212 /**
213  * Reassigns the variable's nth value. This makes a local copy of the
214  * variable's overall value.
215  */
216 INLINE void ConfigVariableFilename::
217 set_word(size_t n, const Filename &value) {
218  set_string_word(n, value);
219 }
220 
221 /**
222  * Returns the variable's value, as a reference into the config variable
223  * itself. This is the internal method that implements get_value(), which
224  * returns a concrete.
225  */
226 INLINE const Filename &ConfigVariableFilename::
227 get_ref_value() const {
228  TAU_PROFILE("const Filename &ConfigVariableFilename::get_ref_value() const", " ", TAU_USER);
229  if (!is_cache_valid(_local_modified)) {
230  ((ConfigVariableFilename *)this)->reload_cache();
231  }
232  return _cache;
233 }
std::string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:358
const std::string & get_string_value() const
Returns the value assigned to this variable.
std::string get_extension() const
Returns the file extension.
This is a convenience class to specialize ConfigVariable as a Filename type.
static Filename expand_from(const std::string &user_string, Type type=T_general)
Returns the same thing as from_os_specific(), but embedded environment variable references (e....
Definition: filename.cxx:407
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
Definition: filename.I:386
std::string get_basename() const
Returns the basename part of the filename.
set_value
Reassigns the variable's local value.
Filename get_word(size_t n) const
Returns the variable's nth value.
std::string get_dirname() const
Returns the directory 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:39
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition: filename.I:338
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
void set_word(size_t n, const Filename &value)
Reassigns the variable's nth value.
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
std::string get_extension() const
Returns the file extension.
Definition: filename.I:400
std::string get_basename() const
Returns the basename part of the filename.
Definition: filename.I:367
A single declaration of a config variable, typically defined as one line in a .prc file,...
void operator=(const Filename &value)
Reassigns the variable's local value.
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
Definition: filename.I:377