process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
core::posix::this_process::env Namespace Reference

Functions

CORE_POSIX_DLL_PUBLIC void for_each (const std::function< void(const std::string &, const std::string &)> &functor) noexcept(true)
 for_each invokes a functor for every key-value pair in the environment. More...
 
CORE_POSIX_DLL_PUBLIC std::string get_or_throw (const std::string &key)
 get queries the value of an environment variable. More...
 
CORE_POSIX_DLL_PUBLIC std::string get (const std::string &key, const std::string &default_value=std::string()) noexcept(true)
 get queries the value of an environment variable. More...
 
CORE_POSIX_DLL_PUBLIC void unset_or_throw (const std::string &key)
 unset_or_throw removes the variable with name key from the environment. More...
 
CORE_POSIX_DLL_PUBLIC bool unset (const std::string &key, std::error_code &se) noexcept(true)
 unset removes the variable with name key from the environment. More...
 
CORE_POSIX_DLL_PUBLIC void set_or_throw (const std::string &key, const std::string &value)
 set_or_throw will adjust the contents of the variable identified by key to the provided value. More...
 
CORE_POSIX_DLL_PUBLIC bool set (const std::string &key, const std::string &value, std::error_code &se) noexcept(true)
 set will adjust the contents of the variable identified by key to the provided value. More...
 

Function Documentation

void core::posix::this_process::env::for_each ( const std::function< void(const std::string &, const std::string &)> &  functor)
noexcept

for_each invokes a functor for every key-value pair in the environment.

Parameters
[in]functorInvoked for every key-value pair.

Definition at line 55 of file this_process.cpp.

References environ.

Referenced by TEST().

std::string core::posix::this_process::env::get ( const std::string &  key,
const std::string &  default_value = std::string() 
)
noexcept

get queries the value of an environment variable.

Parameters
[in]keyName of the variable to query the value for.
[in]default_valueDefault value to return when key is not present in the environment.
Returns
Contents of the variable or an empty string if the variable is not defined.

Definition at line 84 of file this_process.cpp.

Referenced by TEST().

std::string core::posix::this_process::env::get_or_throw ( const std::string &  key)

get queries the value of an environment variable.

Exceptions
std::runtime_errorif there is no variable with the given key defined in the env.
Parameters
[in]keyName of the variable to query the value for.
Returns
Contents of the variable.

Definition at line 68 of file this_process.cpp.

bool core::posix::this_process::env::set ( const std::string &  key,
const std::string &  value,
std::error_code &  se 
)
noexcept

set will adjust the contents of the variable identified by key to the provided value.

Returns
false in case of errors, true otherwise.
Parameters
[in]keyName of the variable to set the value for.
[in]valueNew contents of the variable.
[out]seReceives the details in case of errors.

Definition at line 131 of file this_process.cpp.

void core::posix::this_process::env::set_or_throw ( const std::string &  key,
const std::string &  value 
)

set_or_throw will adjust the contents of the variable identified by key to the provided value.

Exceptions
std::system_errorin case of errors.
Parameters
[in]keyName of the variable to set the value for.
[in]valueNew contents of the variable.

Definition at line 119 of file this_process.cpp.

Referenced by TEST().

bool core::posix::this_process::env::unset ( const std::string &  key,
std::error_code &  se 
)
noexcept

unset removes the variable with name key from the environment.

Returns
false in case of errors, true otherwise.
Parameters
[in]keyName of the variable to unset.
[out]seReceives error details if unset returns false.

Definition at line 103 of file this_process.cpp.

void core::posix::this_process::env::unset_or_throw ( const std::string &  key)

unset_or_throw removes the variable with name key from the environment.

Exceptions
std::system_errorin case of errors.
Parameters
[in]keyName of the variable to unset.

Definition at line 93 of file this_process.cpp.

Referenced by TEST().