Panda3D
Loading...
Searching...
No Matches
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 */
29class EXPCL_DTOOL_DTOOLUTIL ExecutionEnvironment {
30private:
31 ExecutionEnvironment();
32
33PUBLISHED:
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
54PUBLISHED:
55 MAKE_MAP_PROPERTY(environment_variables, has_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
63private:
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
81private:
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
95
96#endif
static void clear_shadow(const std::string &var)
Removes a value set by a previous call to shadow_environment_variable(), and lets the actual value of...
get_dtool_name
Returns the name of the libdtool DLL that is used in this program, if it can be determined.
static std::string expand_string(const std::string &str)
Reads the string, looking for environment variable names marked by a $.
set_environment_variable
Changes the definition of the indicated environment variable.
get_num_args
Returns the number of command-line arguments available, not counting arg 0, the binary name.
static void shadow_environment_variable(const std::string &var, const std::string &value)
Changes the apparent definition of the indicated environment variable by masking it within this class...
has_environment_variable
Returns true if the indicated environment variable is defined.
get_environment_variable
Returns the definition of the indicated environment variable, or the empty string if the variable is ...
get_binary_name
Returns the name of the binary executable that started this program, if it can be determined.
get_cwd
Returns the name of the current working directory.
get_arg
Returns the nth command-line argument.
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
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.