# ExecutionEnvironment¶

class ExecutionEnvironment

Encapsulates access to the environment variables and command-line arguments at the time of execution. This is encapsulated to support accessing these things during static init time, which seems to be risky at best.

Inheritance diagram

ExecutionEnvironment(ExecutionEnvironment const&) = default

You shouldn’t need to construct one of these; there’s only one and it constructs itself.

void clear_shadow(std::string const &var)

Removes a value set by a previous call to shadow_environment_variable(), and lets the actual value of the variable show again.

static std::string expand_string(std::string const &str)

Reads the string, looking for environment variable names marked by a $. Expands all such variable names. A repeated dollar sign ($\$) is mapped to a single dollar sign.

Returns the expanded string.

std::string get_arg(std::size_t n)

Returns the nth command-line argument. The index n must be in the range [0 .. get_num_args()). The first parameter, n == 0, is the first actual parameter, not the binary name.

std::string get_binary_name(void)

Returns the name of the binary executable that started this program, if it can be determined.

static Filename get_cwd(void)

Returns the name of the current working directory.

std::string get_dtool_name(void)

Returns the name of the libdtool DLL that is used in this program, if it can be determined.

std::string get_environment_variable(std::string const &var)

Returns the definition of the indicated environment variable, or the empty string if the variable is undefined.

std::size_t get_num_args(void)

Returns the number of command-line arguments available, not counting arg 0, the binary name.

bool has_environment_variable(std::string const &var)

Returns true if the indicated environment variable is defined.

void set_binary_name(std::string const &name)

Do not use.

void set_dtool_name(std::string const &name)

Do not use.

void set_environment_variable(std::string const &var, std::string const &value)

Changes the definition of the indicated environment variable.

void shadow_environment_variable(std::string const &var, std::string const &value)

Changes the apparent definition of the indicated environment variable by masking it within this class with a new value. This does not change the actual environment variable, but future calls to get_environment_variable() will return this new value.