Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/get_config_path.cxx

Go to the documentation of this file.
00001 // Filename: get_config_path.cxx
00002 // Created by:  drose (01Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 
00021 #include "config_express.h"
00022 
00023 #include <executionEnvironment.h>
00024 #include "get_config_path.h"
00025 
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: get_config_path
00029 //  Description: A generic function for reading path strings
00030 //               (e.g. model-path, texture-path, etc.) from the Config
00031 //               database.  It automatically handles concatenating
00032 //               together multiple appearances of the indicated
00033 //               variable name as a single long path string.
00034 //
00035 //               static_ptr must be a statically-defined string
00036 //               pointer, unique to each different config_var_name.
00037 //               It should be initialized to NULL.  This will
00038 //               automatically be allocated and filled with the string
00039 //               path the first time this function is called;
00040 //               thereafter, the same string value will be returned.
00041 //               This allows the function to work during static init
00042 //               time when we can't be sure what has or hasn't been
00043 //               already initialized.
00044 ////////////////////////////////////////////////////////////////////
00045 DSearchPath &
00046 get_config_path(const string &config_var_name, DSearchPath *&static_ptr) {
00047   if (static_ptr == (DSearchPath *)NULL) {
00048     static_ptr = new DSearchPath;
00049 
00050     Config::ConfigTable::Symbol all_defs;
00051     config_express.GetAll(config_var_name, all_defs);
00052     if (all_defs.empty()) {
00053       // If the path is undefined, it is implicitly ".".
00054       (*static_ptr).append_path(".");
00055 
00056     } else {
00057       Config::ConfigTable::Symbol::reverse_iterator si =
00058         all_defs.rbegin();
00059       string filename = ExecutionEnvironment::expand_string((*si).Val());
00060       (*static_ptr).append_path(Filename::from_os_specific(filename), "");
00061       ++si;
00062       while (si != all_defs.rend()) {
00063         string filename = ExecutionEnvironment::expand_string((*si).Val());
00064         (*static_ptr).append_path(Filename::from_os_specific(filename), "");
00065         ++si;
00066       }
00067     }
00068     if (express_cat.is_debug()) {
00069       express_cat.debug()
00070         << config_var_name << " is " << *static_ptr << "\n";
00071     }
00072   }
00073 
00074   return *static_ptr;
00075 }

Generated on Fri May 2 00:38:23 2003 for Panda by doxygen1.3