Panda3D
executionEnvironment.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file executionEnvironment.h
10  * @author drose
11  * @date 2000-05-15
12  */
13 
14 #ifndef EXECUTIONENVIRONMENT_H
15 #define EXECUTIONENVIRONMENT_H
16 
17 #include "dtoolbase.h"
18 
19 #include "vector_string.h"
20 #include "filename.h"
21 
22 #include <map>
23 
24 /**
25  * Encapsulates access to the environment variables and command-line arguments
26  * at the time of execution. This is encapsulated to support accessing these
27  * things during static init time, which seems to be risky at best.
28  */
29 class EXPCL_DTOOL_DTOOLUTIL ExecutionEnvironment {
30 private:
32 
33 PUBLISHED:
34  INLINE static bool has_environment_variable(const std::string &var);
35  INLINE static std::string get_environment_variable(const std::string &var);
36  INLINE static void set_environment_variable(const std::string &var, const std::string &value);
37 
38  INLINE static void shadow_environment_variable(const std::string &var, const std::string &value);
39  INLINE static void clear_shadow(const std::string &var);
40 
41  static std::string expand_string(const std::string &str);
42 
43  INLINE static size_t get_num_args();
44  INLINE static std::string get_arg(size_t n);
45 
46  INLINE static std::string get_binary_name();
47  INLINE static std::string get_dtool_name();
48 
49  INLINE static void set_binary_name(const std::string &name);
50  INLINE static void set_dtool_name(const std::string &name);
51 
52  static Filename get_cwd();
53 
54 PUBLISHED:
55  MAKE_MAP_PROPERTY(environment_variables, has_environment_variable,
56  get_environment_variable, set_environment_variable);
57 
58  MAKE_SEQ_PROPERTY(args, get_num_args, get_arg);
59  MAKE_PROPERTY(binary_name, get_binary_name, set_binary_name);
60  MAKE_PROPERTY(dtool_name, get_dtool_name, set_dtool_name);
61  MAKE_PROPERTY(cwd, get_cwd);
62 
63 private:
64  bool ns_has_environment_variable(const std::string &var) const;
65  std::string ns_get_environment_variable(const std::string &var) const;
66  void ns_set_environment_variable(const std::string &var, const std::string &value);
67  void ns_shadow_environment_variable(const std::string &var, const std::string &value);
68  void ns_clear_shadow(const std::string &var);
69 
70  size_t ns_get_num_args() const;
71  std::string ns_get_arg(size_t n) const;
72 
73  std::string ns_get_binary_name() const;
74  std::string ns_get_dtool_name() const;
75 
76  static ExecutionEnvironment *get_ptr();
77 
78  void read_environment_variables();
79  void read_args();
80 
81 private:
82  typedef std::map<std::string, std::string> EnvironmentVariables;
83  EnvironmentVariables _variables;
84 
85  typedef vector_string CommandArguments;
86  CommandArguments _args;
87 
88  std::string _binary_name;
89  std::string _dtool_name;
90 
91  static ExecutionEnvironment *_global_ptr;
92 };
93 
94 #include "executionEnvironment.I"
95 
96 #endif
Encapsulates access to the environment variables and command-line arguments at the time of execution.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.