Panda3D
configVariableSearchPath.cxx
1 // Filename: configVariableSearchPath.cxx
2 // Created by: drose (21Oct04)
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 #include "configVariableSearchPath.h"
16 #include "executionEnvironment.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: ConfigVariableSearchPath::reload_search_path
20 // Access: Private
21 // Description: Recopies the config variable into the search path for
22 // returning its value.
23 ////////////////////////////////////////////////////////////////////
24 void ConfigVariableSearchPath::
25 reload_search_path() {
26  nassertv(_core != (ConfigVariableCore *)NULL);
27  mark_cache_valid(_local_modified);
28  _cache.clear();
29 
30  _cache.append_path(_prefix);
31  int num_unique_references = _core->get_num_unique_references();
32  for (int i = 0; i < num_unique_references; i++) {
33  const ConfigDeclaration *decl = _core->get_unique_reference(i);
34  const ConfigPage *page = decl->get_page();
35 
36  Filename page_filename(page->get_name());
37  Filename page_dirname = page_filename.get_dirname();
38  ExecutionEnvironment::shadow_environment_variable("THIS_PRC_DIR", page_dirname.to_os_specific());
39  string expanded = ExecutionEnvironment::expand_string(decl->get_string_value());
40  ExecutionEnvironment::clear_shadow("THIS_PRC_DIR");
41  if (!expanded.empty()) {
42  Filename dir = Filename::from_os_specific(expanded);
43  dir.make_true_case();
44  _cache.append_directory(dir);
45  }
46  }
47 
48  if (_prefix.is_empty() && _postfix.is_empty() &&
49  num_unique_references == 0) {
50  // An empty search path implicitly has the default value.
51  _cache = _default_value;
52  }
53 
54  _cache.append_path(_postfix);
55 }
string get_dirname() const
Returns the directory part of the filename.
Definition: filename.I:424
The internal definition of a ConfigVariable.
void clear()
Removes all the directories from the search list.
bool is_empty() const
Returns true if the search list is empty, false otherwise.
bool make_true_case()
On a case-insensitive operating system (e.g.
Definition: filename.cxx:1120
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
void append_path(const string &path, const string &separator=string())
Adds all of the directories listed in the search path to the end of the search list.
const string & get_name() const
Returns the name of the page.
Definition: configPage.I:44
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
ConfigPage * get_page() const
Returns the page on which this declaration can be found.
A page of ConfigDeclarations that may be loaded or unloaded.
Definition: configPage.h:33
static void clear_shadow(const string &var)
Removes a value set by a previous call to shadow_environment_variable(), and lets the actual value of...
static string expand_string(const string &str)
Reads the string, looking for environment variable names marked by a $.
A single declaration of a config variable, typically defined as one line in a .prc file...
static void shadow_environment_variable(const string &var, const string &value)
Changes the apparent definition of the indicated environment variable by masking it within this class...
const string & get_string_value() const
Returns the value assigned to this variable.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Definition: filename.cxx:332