SystemEnvironment
#include <tpau-cpp-kernal/SystemEnvironment.h>
class SystemEnvironment
Access to system environment variables.
Since C++ does not provide a standard way to access environment variables, this class provides a platform-independent interface for getting, setting, and unsetting environment variables.
On Windows it uses GetEnvironmentVariable, SetEnvironmentVariable, since they are available in all build environments. However, variables changed this way won't reflect when queried using std::getenv.
On POSIX systems it uses getenv, setenv, and unsetenv.
method getstatic
Get the value of an environment variable.
| static std::optional< std::string > get | ( | const std::string & name | ); |
| PARAMETER | DESCRIPTION |
|---|---|
name |
The name of the environment variable. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< std::string > |
The value of the environment variable, or {} if it is not set. |
method is_setstatic
Check if an environment variable is set.
| static bool is_set | ( | const std::string & name | ); |
| PARAMETER | DESCRIPTION |
|---|---|
name |
The name of the environment variable. |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method setstatic
Set the value of an environment variable.
| static void set | ( | const std::string & name, | |
| const std::string & value, | |||
| bool overwrite = true | ); |
| PARAMETER | DESCRIPTION |
|---|---|
name |
The name of the environment variable. |
value |
The value to set the environment variable to. |
overwrite |
Whether to overwrite the environment variable if it is already set. |
| THROWS | DESCRIPTION |
|---|---|
Exception |
If the environment variable could not be set. |
method unsetstatic
Unset an environment variable.
| static void unset | ( | const std::string & name | ); |
| PARAMETER | DESCRIPTION |
|---|---|
name |
The name of the environment variable. |
| THROWS | DESCRIPTION |
|---|---|
Exception |
If the environment variable could not be unset. |