Panda3D
Loading...
Searching...
No Matches
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 */
17INLINE ConfigVariableFilename::
18ConfigVariableFilename(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 */
28INLINE ConfigVariableFilename::
29ConfigVariableFilename(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 */
46operator = (const Filename &value) {
47 set_value(value);
48}
49
50/**
51 * Returns the variable's value as a Filename.
52 */
53INLINE ConfigVariableFilename::
54operator const Filename &() const {
55 return get_ref_value();
56}
57
58/**
59 *
60 */
61INLINE const char *ConfigVariableFilename::
62c_str() const {
63 return get_ref_value().c_str();
64}
65
66/**
67 *
68 */
69INLINE bool ConfigVariableFilename::
70empty() const {
71 return get_ref_value().empty();
72}
73
74/**
75 *
76 */
77INLINE size_t ConfigVariableFilename::
78length() const {
79 return get_ref_value().length();
80}
81
82/**
83 *
84 */
85INLINE char ConfigVariableFilename::
86operator [] (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 */
96INLINE std::string ConfigVariableFilename::
97get_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 */
105INLINE std::string ConfigVariableFilename::
106get_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 */
114INLINE std::string ConfigVariableFilename::
115get_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 */
124INLINE 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 */
133INLINE 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 */
143INLINE std::string ConfigVariableFilename::
144get_extension() const {
145 return get_ref_value().get_extension();
146}
147
148/**
149 *
150 */
151INLINE bool ConfigVariableFilename::
152operator == (const Filename &other) const {
153 return get_ref_value() == other;
154}
155
156/**
157 *
158 */
159INLINE bool ConfigVariableFilename::
160operator != (const Filename &other) const {
161 return get_ref_value() != other;
162}
163
164/**
165 *
166 */
167INLINE bool ConfigVariableFilename::
168operator < (const Filename &other) const {
169 return get_ref_value() < other;
170}
171
172/**
173 * Reassigns the variable's local value.
174 */
175INLINE void ConfigVariableFilename::
176set_value(const Filename &value) {
177 set_string_value(value);
178}
179
180/**
181 * Returns the variable's value.
182 */
184get_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 */
196get_default_value() const {
197 const ConfigDeclaration *decl = ConfigVariable::get_default_value();
198 if (decl != nullptr) {
200 }
201 return Filename();
202}
203
204/**
205 * Returns the variable's nth value.
206 */
208get_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 */
217set_word(size_t n, const Filename &value) {
218 set_string_word(n, value);
219}
220
221/**
222 * Allows a ConfigVariableFilename object to be passed to any Python function
223 * that accepts an os.PathLike object.
224 *
225 * @since 1.10.13
226 */
227INLINE std::wstring ConfigVariableFilename::
228__fspath__() const {
229 return get_ref_value().to_os_specific_w();
230}
231
232/**
233 * Returns the variable's value, as a reference into the config variable
234 * itself. This is the internal method that implements get_value(), which
235 * returns a concrete.
236 */
237INLINE const Filename &ConfigVariableFilename::
238get_ref_value() const {
239 TAU_PROFILE("const Filename &ConfigVariableFilename::get_ref_value() const", " ", TAU_USER);
240 if (!is_cache_valid(_local_modified)) {
241 ((ConfigVariableFilename *)this)->reload_cache();
242 }
243 return _cache;
244}
A single declaration of a config variable, typically defined as one line in a .prc file,...
const std::string & get_string_value() const
Returns the value assigned to this variable.
This is a convenience class to specialize ConfigVariable as a Filename type.
std::wstring __fspath__() const
Allows a ConfigVariableFilename object to be passed to any Python function that accepts an os....
std::string get_basename() const
Returns the basename part of the filename.
set_value
Reassigns the variable's local value.
void operator=(const Filename &value)
Reassigns the variable's local value.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
std::string get_dirname() const
Returns the directory part of the filename.
Filename get_word(size_t n) const
Returns the variable's nth value.
get_default_value
Returns the variable's default 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.
void set_word(size_t n, const Filename &value)
Reassigns the variable's nth value.
get_value
Returns the variable's value.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
This is a generic, untyped ConfigVariable.
void set_string_value(const std::string &value)
Changes the value assigned to this variable.
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
std::string get_basename() const
Returns the basename part of the filename.
Definition filename.I:367
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
Definition filename.I:377
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
std::wstring to_os_specific_w() const
The wide-string variant on to_os_specific().
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition filename.I:338
std::string get_extension() const
Returns the file extension.
Definition filename.I:400
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_dirname() const
Returns the directory part of the filename.
Definition filename.I:358
STL namespace.