Skip to content

SystemEnvironment

#include <tpau-cpp-kernal/SystemEnvironment.h>

INCLUDE FILE
#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.

DEFINITION
class SystemEnvironment;

method getstatic

Get the value of an environment variable.

DEFINITION
static std::optional< std::string >  get ( const std::string & name );
PARAMETERDESCRIPTION
name

The name of the environment variable.

RETURNSDESCRIPTION
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.

DEFINITION
static bool  is_set ( const std::string & name );
PARAMETERDESCRIPTION
name

The name of the environment variable.

RETURNSDESCRIPTION
bool

true if the environment variable is set, false otherwise.

method setstatic

Set the value of an environment variable.

DEFINITION
static void  set ( const std::string & name,
const std::string & value,
bool  overwrite = true );
PARAMETERDESCRIPTION
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.

THROWSDESCRIPTION
Exception

If the environment variable could not be set.

method unsetstatic

Unset an environment variable.

DEFINITION
static void  unset ( const std::string & name );
PARAMETERDESCRIPTION
name

The name of the environment variable.

THROWSDESCRIPTION
Exception

If the environment variable could not be unset.