Panda3D
|
00001 // Filename: executionEnvironment.h 00002 // Created by: drose (15May00) 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 #ifndef EXECUTIONENVIRONMENT_H 00016 #define EXECUTIONENVIRONMENT_H 00017 00018 #include "dtoolbase.h" 00019 00020 #include "vector_string.h" 00021 #include "filename.h" 00022 00023 #include <map> 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : ExecutionEnvironment 00027 // Description : Encapsulates access to the environment variables and 00028 // command-line arguments at the time of execution. 00029 // This is encapsulated to support accessing these 00030 // things during static init time, which seems to be 00031 // risky at best. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_DTOOL ExecutionEnvironment { 00034 private: 00035 ExecutionEnvironment(); 00036 00037 PUBLISHED: 00038 INLINE static bool has_environment_variable(const string &var); 00039 INLINE static string get_environment_variable(const string &var); 00040 INLINE static void set_environment_variable(const string &var, const string &value); 00041 00042 INLINE static void shadow_environment_variable(const string &var, const string &value); 00043 INLINE static void clear_shadow(const string &var); 00044 00045 static string expand_string(const string &str); 00046 00047 INLINE static int get_num_args(); 00048 INLINE static string get_arg(int n); 00049 00050 INLINE static string get_binary_name(); 00051 INLINE static string get_dtool_name(); 00052 00053 static Filename get_cwd(); 00054 00055 private: 00056 bool ns_has_environment_variable(const string &var) const; 00057 string ns_get_environment_variable(const string &var) const; 00058 void ns_set_environment_variable(const string &var, const string &value); 00059 void ns_shadow_environment_variable(const string &var, const string &value); 00060 void ns_clear_shadow(const string &var); 00061 00062 int ns_get_num_args() const; 00063 string ns_get_arg(int n) const; 00064 00065 string ns_get_binary_name() const; 00066 string ns_get_dtool_name() const; 00067 00068 static ExecutionEnvironment *get_ptr(); 00069 00070 void read_environment_variables(); 00071 void read_args(); 00072 00073 private: 00074 typedef map<string, string> EnvironmentVariables; 00075 EnvironmentVariables _variables; 00076 00077 typedef vector_string CommandArguments; 00078 CommandArguments _args; 00079 00080 string _binary_name; 00081 string _dtool_name; 00082 00083 static ExecutionEnvironment *_global_ptr; 00084 }; 00085 00086 #include "executionEnvironment.I" 00087 00088 #endif