Panda3D

configVariableSearchPath.I

00001 // Filename: configVariableSearchPath.I
00002 // Created by:  drose (21Oct04)
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: ConfigVariableSearchPath::Constructor
00018 //       Access: Published
00019 //  Description: 
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE ConfigVariableSearchPath::
00022 ConfigVariableSearchPath(const string &name, 
00023                          const string &description, int flags) :
00024 #ifdef PRC_SAVE_DESCRIPTIONS
00025   ConfigVariableBase(name, VT_search_path, description, flags),
00026 #else
00027   ConfigVariableBase(name, VT_search_path, string(), flags),
00028 #endif
00029   _default_value(Filename(".")),
00030   _local_modified(initial_invalid_cache())
00031 {
00032   // A SearchPath variable implicitly defines a default value of the empty
00033   // string.  This is just to prevent the core variable from
00034   // complaining should anyone ask for its solitary value.
00035   if (_core->get_default_value() == (ConfigDeclaration *)NULL) {
00036     _core->set_default_value("");
00037   }
00038   _core->set_used();
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: ConfigVariableSearchPath::Constructor
00043 //       Access: Published
00044 //  Description: 
00045 ////////////////////////////////////////////////////////////////////
00046 INLINE ConfigVariableSearchPath::
00047 ConfigVariableSearchPath(const string &name, 
00048                          const DSearchPath &default_value,
00049                          const string &description, int flags) :
00050 #ifdef PRC_SAVE_DESCRIPTIONS
00051   ConfigVariableBase(name, VT_search_path, description, flags),
00052 #else
00053   ConfigVariableBase(name, VT_search_path, string(), flags),
00054 #endif
00055   _default_value(default_value),
00056   _local_modified(initial_invalid_cache())
00057 {
00058   // A SearchPath variable implicitly defines a default value of the empty
00059   // string.  This is just to prevent the core variable from
00060   // complaining should anyone ask for its solitary value.
00061   if (_core->get_default_value() == (ConfigDeclaration *)NULL) {
00062     _core->set_default_value("");
00063   }
00064   _core->set_used();
00065 }
00066 
00067 ////////////////////////////////////////////////////////////////////
00068 //     Function: ConfigVariableSearchPath::Constructor
00069 //       Access: Published
00070 //  Description: 
00071 ////////////////////////////////////////////////////////////////////
00072 INLINE ConfigVariableSearchPath::
00073 ConfigVariableSearchPath(const string &name, 
00074                          const string &default_value,
00075                          const string &description, int flags) :
00076 #ifdef PRC_SAVE_DESCRIPTIONS
00077   ConfigVariableBase(name, VT_search_path, description, flags),
00078 #else
00079   ConfigVariableBase(name, VT_search_path, string(), flags),
00080 #endif
00081   _default_value(Filename(default_value)),
00082   _local_modified(initial_invalid_cache())
00083 {
00084   // A SearchPath variable implicitly defines a default value of the empty
00085   // string.  This is just to prevent the core variable from
00086   // complaining should anyone ask for its solitary value.
00087   if (_core->get_default_value() == (ConfigDeclaration *)NULL) {
00088     _core->set_default_value("");
00089   }
00090   _core->set_used();
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: ConfigVariableSearchPath::Destructor
00095 //       Access: Published
00096 //  Description: 
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE ConfigVariableSearchPath::
00099 ~ConfigVariableSearchPath() {
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: ConfigVariableSearchPath::DSearchPath typecast
00104 //       Access: Published
00105 //  Description: Returns the variable's value.
00106 ////////////////////////////////////////////////////////////////////
00107 INLINE ConfigVariableSearchPath::
00108 operator const DSearchPath & () const {
00109   return get_value();
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: ConfigVariableSearchPath::get_value
00114 //       Access: Published
00115 //  Description: 
00116 ////////////////////////////////////////////////////////////////////
00117 INLINE const DSearchPath &ConfigVariableSearchPath::
00118 get_value() const {
00119   TAU_PROFILE("const DSearchPath &ConfigVariableSearchPath::get_value() const", " ", TAU_USER);
00120   if (!is_cache_valid(_local_modified)) {
00121     ((ConfigVariableSearchPath *)this)->reload_search_path();
00122   }
00123   return _cache;
00124 }
00125 
00126 ////////////////////////////////////////////////////////////////////
00127 //     Function: ConfigVariableSearchPath::get_default_value
00128 //       Access: Published
00129 //  Description: 
00130 ////////////////////////////////////////////////////////////////////
00131 INLINE const DSearchPath &ConfigVariableSearchPath::
00132 get_default_value() const {
00133   return _default_value;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: ConfigVariableSearchPath::clear_local_value
00138 //       Access: Published
00139 //  Description: Removes all the directories locally added to the
00140 //               search list, and restores it to its original form.
00141 ////////////////////////////////////////////////////////////////////
00142 INLINE bool ConfigVariableSearchPath::
00143 clear_local_value() {
00144   nassertr(_core != (ConfigVariableCore *)NULL, false);
00145 
00146   bool any_to_clear = !_prefix.is_empty() || _postfix.is_empty();
00147   _prefix.clear();
00148   _postfix.clear();
00149   
00150   if (_core->clear_local_value()) {
00151     any_to_clear = true;
00152   }
00153 
00154   _local_modified = initial_invalid_cache();
00155   return any_to_clear;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: ConfigVariableSearchPath::clear
00160 //       Access: Published
00161 //  Description: Removes all the directories locally added to the
00162 //               search list, and restores it to its original form.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE void ConfigVariableSearchPath::
00165 clear() {
00166   clear_local_value();
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: ConfigVariableSearchPath::append_directory
00171 //       Access: Published
00172 //  Description: Adds a new directory to the end of the search list.
00173 ////////////////////////////////////////////////////////////////////
00174 INLINE void ConfigVariableSearchPath::
00175 append_directory(const Filename &directory) {
00176   _postfix.append_directory(directory);
00177   _local_modified = initial_invalid_cache();
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: ConfigVariableSearchPath::prepend_directory
00182 //       Access: Published
00183 //  Description: Adds a new directory to the front of the search list.
00184 ////////////////////////////////////////////////////////////////////
00185 INLINE void ConfigVariableSearchPath::
00186 prepend_directory(const Filename &directory) {
00187   _prefix.prepend_directory(directory);
00188   _local_modified = initial_invalid_cache();
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //     Function: ConfigVariableSearchPath::append_path
00193 //       Access: Published
00194 //  Description: Adds all of the directories listed in the search path
00195 //               to the end of the search list.
00196 ////////////////////////////////////////////////////////////////////
00197 INLINE void ConfigVariableSearchPath::
00198 append_path(const string &path, const string &separator) {
00199   _postfix.append_path(path, separator);
00200   _local_modified = initial_invalid_cache();
00201 }
00202 
00203 ////////////////////////////////////////////////////////////////////
00204 //     Function: ConfigVariableSearchPath::append_path
00205 //       Access: Published
00206 //  Description: Adds all of the directories listed in the search path
00207 //               to the end of the search list.
00208 ////////////////////////////////////////////////////////////////////
00209 INLINE void ConfigVariableSearchPath::
00210 append_path(const DSearchPath &path) {
00211   _postfix.append_path(path);
00212   _local_modified = initial_invalid_cache();
00213 }
00214 
00215 ////////////////////////////////////////////////////////////////////
00216 //     Function: ConfigVariableSearchPath::prepend_path
00217 //       Access: Published
00218 //  Description: Adds all of the directories listed in the search path
00219 //               to the beginning of the search list.
00220 ////////////////////////////////////////////////////////////////////
00221 INLINE void ConfigVariableSearchPath::
00222 prepend_path(const DSearchPath &path) {
00223   _prefix.prepend_path(path);
00224   _local_modified = initial_invalid_cache();
00225 }
00226 
00227 ////////////////////////////////////////////////////////////////////
00228 //     Function: ConfigVariableSearchPath::is_empty
00229 //       Access: Published
00230 //  Description: Returns true if the search list is empty, false
00231 //               otherwise.
00232 ////////////////////////////////////////////////////////////////////
00233 INLINE bool ConfigVariableSearchPath::
00234 is_empty() const {
00235   return get_value().is_empty();
00236 }
00237 
00238 ////////////////////////////////////////////////////////////////////
00239 //     Function: ConfigVariableSearchPath::get_num_directories
00240 //       Access: Published
00241 //  Description: Returns the number of directories on the search list.
00242 ////////////////////////////////////////////////////////////////////
00243 INLINE int ConfigVariableSearchPath::
00244 get_num_directories() const {
00245   return get_value().get_num_directories();
00246 }
00247 
00248 ////////////////////////////////////////////////////////////////////
00249 //     Function: ConfigVariableSearchPath::get_directory
00250 //       Access: Published
00251 //  Description: Returns the nth directory on the search list.
00252 ////////////////////////////////////////////////////////////////////
00253 INLINE const Filename &ConfigVariableSearchPath::
00254 get_directory(int n) const {
00255   return get_value().get_directory(n);
00256 }
00257 
00258 ////////////////////////////////////////////////////////////////////
00259 //     Function: ConfigVariableSearchPath::find_file
00260 //       Access: Published
00261 //  Description: Searches all the directories in the search list for
00262 //               the indicated file, in order.  Returns the full
00263 //               matching pathname of the first match if found, or the
00264 //               empty string if not found.
00265 ////////////////////////////////////////////////////////////////////
00266 INLINE Filename ConfigVariableSearchPath::
00267 find_file(const Filename &filename) const {
00268   return get_value().find_file(filename);
00269 }
00270 
00271 ////////////////////////////////////////////////////////////////////
00272 //     Function: ConfigVariableSearchPath::find_all_files
00273 //       Access: Published
00274 //  Description: Searches all the directories in the search list for
00275 //               the indicated file, in order.  Fills up the results
00276 //               list with *all* of the matching filenames found, if
00277 //               any.  Returns the number of matches found.
00278 //
00279 //               It is the responsibility of the the caller to clear
00280 //               the results list first; otherwise, the newly-found
00281 //               files will be appended to the list.
00282 ////////////////////////////////////////////////////////////////////
00283 INLINE int ConfigVariableSearchPath::
00284 find_all_files(const Filename &filename,
00285                DSearchPath::Results &results) const {
00286   return get_value().find_all_files(filename, results);
00287 }
00288 
00289 ////////////////////////////////////////////////////////////////////
00290 //     Function: ConfigVariableSearchPath::find_all_files
00291 //       Access: Published
00292 //  Description: This variant of find_all_files() returns the new
00293 //               Results object, instead of filling on in on the
00294 //               parameter list.  This is a little more convenient to
00295 //               call from Python.
00296 ////////////////////////////////////////////////////////////////////
00297 INLINE DSearchPath::Results ConfigVariableSearchPath::
00298 find_all_files(const Filename &filename) const {
00299   return get_value().find_all_files(filename);
00300 }
00301 
00302 ////////////////////////////////////////////////////////////////////
00303 //     Function: ConfigVariableSearchPath::output
00304 //       Access: Published
00305 //  Description: 
00306 ////////////////////////////////////////////////////////////////////
00307 INLINE void ConfigVariableSearchPath::
00308 output(ostream &out) const {
00309   get_value().output(out);
00310 }
00311 
00312 ////////////////////////////////////////////////////////////////////
00313 //     Function: ConfigVariableSearchPath::write
00314 //       Access: Published
00315 //  Description: 
00316 ////////////////////////////////////////////////////////////////////
00317 INLINE void ConfigVariableSearchPath::
00318 write(ostream &out) const {
00319   get_value().write(out);
00320 }
00321 
00322 INLINE ostream &
00323 operator << (ostream &out, const ConfigVariableSearchPath &variable) {
00324   variable.output(out);
00325   return out;
00326 }
 All Classes Functions Variables Enumerations