Panda3D
|
00001 // Filename: configVariableFilename.I 00002 // Created by: drose (22Nov04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ConfigVariableFilename::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE ConfigVariableFilename:: 00022 ConfigVariableFilename(const string &name) : 00023 ConfigVariable(name, VT_filename), 00024 _local_modified(initial_invalid_cache()) 00025 { 00026 _core->set_used(); 00027 } 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: ConfigVariableFilename::Constructor 00031 // Access: Published 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE ConfigVariableFilename:: 00035 ConfigVariableFilename(const string &name, const Filename &default_value, 00036 const string &description, int flags) : 00037 #ifdef PRC_SAVE_DESCRIPTIONS 00038 ConfigVariable(name, VT_filename, description, flags), 00039 #else 00040 ConfigVariable(name, VT_filename, string(), flags), 00041 #endif 00042 _local_modified(initial_invalid_cache()) 00043 { 00044 _core->set_default_value(default_value); 00045 _core->set_used(); 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: ConfigVariableFilename::operator = 00050 // Access: Published 00051 // Description: Reassigns the variable's local value. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE void ConfigVariableFilename:: 00054 operator = (const Filename &value) { 00055 set_value(value); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: ConfigVariableFilename::Filename typecast operator 00060 // Access: Published 00061 // Description: Returns the variable's value as a Filename. 00062 //////////////////////////////////////////////////////////////////// 00063 INLINE ConfigVariableFilename:: 00064 operator const Filename &() const { 00065 return get_ref_value(); 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: ConfigVariableFilename::c_str 00070 // Access: Public 00071 // Description: 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE const char *ConfigVariableFilename:: 00074 c_str() const { 00075 return get_ref_value().c_str(); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: ConfigVariableFilename::empty 00080 // Access: Public 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE bool ConfigVariableFilename:: 00084 empty() const { 00085 return get_ref_value().empty(); 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: ConfigVariableFilename::length 00090 // Access: Public 00091 // Description: 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE size_t ConfigVariableFilename:: 00094 length() const { 00095 return get_ref_value().length(); 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: ConfigVariableFilename::Indexing operator 00100 // Access: Public 00101 // Description: 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE char ConfigVariableFilename:: 00104 operator [] (int n) const { 00105 return get_ref_value()[n]; 00106 } 00107 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: ConfigVariableFilename::get_fullpath 00111 // Access: Public 00112 // Description: Returns the entire filename: directory, basename, 00113 // extension. This is the same thing returned by the 00114 // string typecast operator, so this function is a 00115 // little redundant. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE string ConfigVariableFilename:: 00118 get_fullpath() const { 00119 return get_ref_value().get_fullpath(); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: ConfigVariableFilename::get_dirname 00124 // Access: Public 00125 // Description: Returns the directory part of the filename. This is 00126 // everything in the filename up to, but not including 00127 // the rightmost slash. 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE string ConfigVariableFilename:: 00130 get_dirname() const { 00131 return get_ref_value().get_dirname(); 00132 } 00133 00134 //////////////////////////////////////////////////////////////////// 00135 // Function: ConfigVariableFilename::get_basename 00136 // Access: Public 00137 // Description: Returns the basename part of the filename. This is 00138 // everything in the filename after the rightmost slash, 00139 // including any extensions. 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE string ConfigVariableFilename:: 00142 get_basename() const { 00143 return get_ref_value().get_basename(); 00144 } 00145 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: ConfigVariableFilename::get_fullpath_wo_extension 00149 // Access: Public 00150 // Description: Returns the full filename--directory and basename 00151 // parts--except for the extension. 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE string ConfigVariableFilename:: 00154 get_fullpath_wo_extension() const { 00155 return get_ref_value().get_fullpath_wo_extension(); 00156 } 00157 00158 00159 //////////////////////////////////////////////////////////////////// 00160 // Function: ConfigVariableFilename::get_basename_wo_extension 00161 // Access: Public 00162 // Description: Returns the basename part of the filename, without 00163 // the file extension. 00164 //////////////////////////////////////////////////////////////////// 00165 INLINE string ConfigVariableFilename:: 00166 get_basename_wo_extension() const { 00167 return get_ref_value().get_basename_wo_extension(); 00168 } 00169 00170 00171 //////////////////////////////////////////////////////////////////// 00172 // Function: ConfigVariableFilename::get_extension 00173 // Access: Public 00174 // Description: Returns the file extension. This is everything after 00175 // the rightmost dot, if there is one, or the empty 00176 // string if there is not. 00177 //////////////////////////////////////////////////////////////////// 00178 INLINE string ConfigVariableFilename:: 00179 get_extension() const { 00180 return get_ref_value().get_extension(); 00181 } 00182 00183 //////////////////////////////////////////////////////////////////// 00184 // Function: ConfigVariableFilename::Equality operator 00185 // Access: Public 00186 // Description: 00187 //////////////////////////////////////////////////////////////////// 00188 INLINE bool ConfigVariableFilename:: 00189 operator == (const Filename &other) const { 00190 return get_ref_value() == other; 00191 } 00192 00193 //////////////////////////////////////////////////////////////////// 00194 // Function: ConfigVariableFilename::Inequality operator 00195 // Access: Public 00196 // Description: 00197 //////////////////////////////////////////////////////////////////// 00198 INLINE bool ConfigVariableFilename:: 00199 operator != (const Filename &other) const { 00200 return get_ref_value() != other; 00201 } 00202 00203 //////////////////////////////////////////////////////////////////// 00204 // Function: ConfigVariableFilename::Ordering operator 00205 // Access: Public 00206 // Description: 00207 //////////////////////////////////////////////////////////////////// 00208 INLINE bool ConfigVariableFilename:: 00209 operator < (const Filename &other) const { 00210 return get_ref_value() < other; 00211 } 00212 00213 //////////////////////////////////////////////////////////////////// 00214 // Function: ConfigVariableFilename::set_value 00215 // Access: Published 00216 // Description: Reassigns the variable's local value. 00217 //////////////////////////////////////////////////////////////////// 00218 INLINE void ConfigVariableFilename:: 00219 set_value(const Filename &value) { 00220 set_string_value(value); 00221 } 00222 00223 //////////////////////////////////////////////////////////////////// 00224 // Function: ConfigVariableFilename::get_value 00225 // Access: Published 00226 // Description: Returns the variable's value. 00227 //////////////////////////////////////////////////////////////////// 00228 INLINE Filename ConfigVariableFilename:: 00229 get_value() const { 00230 // This returns a concrete rather than a reference by design, to 00231 // avoid problems with scope. When we call this method from Python, 00232 // we'd like to be able to keep the Filename value around longer 00233 // than the lifetime of the config variable itself. 00234 return get_ref_value(); 00235 } 00236 00237 //////////////////////////////////////////////////////////////////// 00238 // Function: ConfigVariableFilename::get_default_value 00239 // Access: Published 00240 // Description: Returns the variable's default value. 00241 //////////////////////////////////////////////////////////////////// 00242 INLINE Filename ConfigVariableFilename:: 00243 get_default_value() const { 00244 const ConfigDeclaration *decl = ConfigVariable::get_default_value(); 00245 if (decl != (ConfigDeclaration *)NULL) { 00246 return Filename::expand_from(decl->get_string_value()); 00247 } 00248 return Filename(); 00249 } 00250 00251 //////////////////////////////////////////////////////////////////// 00252 // Function: ConfigVariableFilename::get_word 00253 // Access: Published 00254 // Description: Returns the variable's nth value. 00255 //////////////////////////////////////////////////////////////////// 00256 INLINE Filename ConfigVariableFilename:: 00257 get_word(int n) const { 00258 return Filename::expand_from(get_string_word(n)); 00259 } 00260 00261 //////////////////////////////////////////////////////////////////// 00262 // Function: ConfigVariableFilename::set_word 00263 // Access: Published 00264 // Description: Reassigns the variable's nth value. This makes a 00265 // local copy of the variable's overall value. 00266 //////////////////////////////////////////////////////////////////// 00267 INLINE void ConfigVariableFilename:: 00268 set_word(int n, const Filename &value) { 00269 set_string_word(n, value); 00270 } 00271 00272 //////////////////////////////////////////////////////////////////// 00273 // Function: ConfigVariableFilename::get_ref_value 00274 // Access: Private 00275 // Description: Returns the variable's value, as a reference into the 00276 // config variable itself. This is the internal method 00277 // that implements get_value(), which returns a 00278 // concrete. 00279 //////////////////////////////////////////////////////////////////// 00280 INLINE const Filename &ConfigVariableFilename:: 00281 get_ref_value() const { 00282 TAU_PROFILE("const Filename &ConfigVariableFilename::get_ref_value() const", " ", TAU_USER); 00283 if (!is_cache_valid(_local_modified)) { 00284 ((ConfigVariableFilename *)this)->reload_cache(); 00285 } 00286 return _cache; 00287 }