E-MailRelay
|
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv(). More...
#include <genvironment.h>
Public Member Functions | |
Environment (const std::map< std::string, std::string > &) | |
Constructor from a map. More... | |
~Environment ()=default | |
Destructor. | |
void | add (const std::string &name, const std::string &value) |
Adds a variable to this set. More... | |
bool | contains (const std::string &name) const |
Returns true if the given variable is in this set. More... | |
std::string | value (const std::string &name, const std::string &default_=std::string()) const |
Returns the value of the given variable in this set. More... | |
void | set (const std::string &name, const std::string &value) |
Inserts or updates a variable in this set. More... | |
const char * | ptr () const noexcept |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero byte at the end. More... | |
char ** | v () const noexcept |
Returns a null-terminated array of pointers. More... | |
bool | empty () const noexcept |
Returns true if empty. More... | |
Environment (const Environment &) | |
Copy constructor. More... | |
Environment (Environment &&) noexcept | |
Move constructor. More... | |
Environment & | operator= (const Environment &) |
Assigment operator. More... | |
Environment & | operator= (Environment &&) noexcept |
Move assigment operator. More... | |
bool | valid () const |
Returns true if the class invariants are satisfied. More... | |
Static Public Member Functions | |
static std::string | get (const std::string &name, const std::string &default_) |
Returns the environment variable value or the given default. More... | |
static void | put (const std::string &name, const std::string &value) |
Sets the environment variable value. More... | |
static Environment | minimal () |
Returns a minimal, safe set of environment variables. More... | |
static Environment | inherit () |
Returns an empty() environment, as if default constructed. More... | |
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().
Definition at line 38 of file genvironment.h.
|
explicit |
Constructor from a map.
Definition at line 32 of file genvironment.cpp.
G::Environment::Environment | ( | const Environment & | other | ) |
Copy constructor.
Definition at line 38 of file genvironment.cpp.
|
noexcept |
Move constructor.
Definition at line 44 of file genvironment.cpp.
void G::Environment::add | ( | const std::string & | name, |
const std::string & | value | ||
) |
Adds a variable to this set.
Does nothing if already present.
Definition at line 122 of file genvironment.cpp.
bool G::Environment::contains | ( | const std::string & | name | ) | const |
Returns true if the given variable is in this set.
Definition at line 145 of file genvironment.cpp.
|
inlinenoexcept |
Returns true if empty.
Definition at line 121 of file genvironment.h.
|
static |
Returns the environment variable value or the given default.
Definition at line 27 of file genvironment_unix.cpp.
|
inlinestatic |
Returns an empty() environment, as if default constructed.
This is syntactic sugar for the G::NewProcess interface.
Definition at line 127 of file genvironment.h.
|
static |
Returns a minimal, safe set of environment variables.
Definition at line 46 of file genvironment_unix.cpp.
G::Environment & G::Environment::operator= | ( | const Environment & | other | ) |
Assigment operator.
Definition at line 68 of file genvironment.cpp.
|
noexcept |
Move assigment operator.
Definition at line 74 of file genvironment.cpp.
|
noexcept |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero byte at the end.
Definition at line 140 of file genvironment.cpp.
|
static |
Sets the environment variable value.
Definition at line 39 of file genvironment_unix.cpp.
void G::Environment::set | ( | const std::string & | name, |
const std::string & | value | ||
) |
Inserts or updates a variable in this set.
Definition at line 129 of file genvironment.cpp.
|
noexcept |
Returns a null-terminated array of pointers.
Definition at line 135 of file genvironment.cpp.
bool G::Environment::valid | ( | ) | const |
Returns true if the class invariants are satisfied.
Used in testing.
Definition at line 60 of file genvironment.cpp.
std::string G::Environment::value | ( | const std::string & | name, |
const std::string & | default_ = std::string() |
||
) | const |
Returns the value of the given variable in this set.
Definition at line 150 of file genvironment.cpp.