Panda3D
executionEnvironment.h
1 // Filename: executionEnvironment.h
2 // Created by: drose (15May00)
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 #ifndef EXECUTIONENVIRONMENT_H
16 #define EXECUTIONENVIRONMENT_H
17 
18 #include "dtoolbase.h"
19 
20 #include "vector_string.h"
21 #include "filename.h"
22 
23 #include <map>
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : ExecutionEnvironment
27 // Description : Encapsulates access to the environment variables and
28 // command-line arguments at the time of execution.
29 // This is encapsulated to support accessing these
30 // things during static init time, which seems to be
31 // risky at best.
32 ////////////////////////////////////////////////////////////////////
33 class EXPCL_DTOOL ExecutionEnvironment {
34 private:
36 
37 PUBLISHED:
38  INLINE static bool has_environment_variable(const string &var);
39  INLINE static string get_environment_variable(const string &var);
40  INLINE static void set_environment_variable(const string &var, const string &value);
41 
42  INLINE static void shadow_environment_variable(const string &var, const string &value);
43  INLINE static void clear_shadow(const string &var);
44 
45  static string expand_string(const string &str);
46 
47  INLINE static int get_num_args();
48  INLINE static string get_arg(int n);
49 
50  INLINE static string get_binary_name();
51  INLINE static string get_dtool_name();
52 
53  INLINE static void set_binary_name(const string &name);
54  INLINE static void set_dtool_name(const string &name);
55 
56  static Filename get_cwd();
57 
58 private:
59  bool ns_has_environment_variable(const string &var) const;
60  string ns_get_environment_variable(const string &var) const;
61  void ns_set_environment_variable(const string &var, const string &value);
62  void ns_shadow_environment_variable(const string &var, const string &value);
63  void ns_clear_shadow(const string &var);
64 
65  int ns_get_num_args() const;
66  string ns_get_arg(int n) const;
67 
68  string ns_get_binary_name() const;
69  string ns_get_dtool_name() const;
70 
71  static ExecutionEnvironment *get_ptr();
72 
73  void read_environment_variables();
74  void read_args();
75 
76 private:
77  typedef map<string, string> EnvironmentVariables;
78  EnvironmentVariables _variables;
79 
80  typedef vector_string CommandArguments;
81  CommandArguments _args;
82 
83  string _binary_name;
84  string _dtool_name;
85 
86  static ExecutionEnvironment *_global_ptr;
87 };
88 
89 #include "executionEnvironment.I"
90 
91 #endif
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
Encapsulates access to the environment variables and command-line arguments at the time of execution...