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... | |
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_={}) const |
Returns the value of the given variable in this set. More... | |
bool | add (std::string_view key, std::string_view value) |
Adds an environment variable. Returns false if invalid. More... | |
std::string | block () const |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero byte at the end. More... | |
std::wstring | block (std::wstring(*)(std::string_view)) const |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero character at the end. More... | |
bool | empty () const noexcept |
Returns true if empty. More... | |
std::map< std::string, std::string > | map () const |
Returns the environment as a map. 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 G::Path | getPath (const std::string &name, const G::Path &={}) |
Returns the environment variable value as a G::Path object. More... | |
static void | put (const std::string &name, const std::string &value) |
Sets the environment variable value. More... | |
static Environment | minimal (bool sbin=false) |
Returns a minimal, safe set of environment variables. More... | |
static Environment | inherit () |
Returns an empty() environment, as if default constructed. More... | |
static std::vector< char * > | array (const std::string &block) |
Returns a pointer array pointing into the given block(), with const-casts. More... | |
static std::vector< char * > | array (std::string &&envblock)=delete |
Deleted overload. | |
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().
Definition at line 41 of file genvironment.h.
|
explicit |
Constructor from a map.
Definition at line 30 of file genvironment.cpp.
bool G::Environment::add | ( | std::string_view | key, |
std::string_view | value | ||
) |
Adds an environment variable. Returns false if invalid.
Definition at line 48 of file genvironment.cpp.
|
static |
Returns a pointer array pointing into the given block(), with const-casts.
Definition at line 100 of file genvironment.cpp.
std::string G::Environment::block | ( | ) | const |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero byte at the end.
Definition at line 74 of file genvironment.cpp.
std::wstring G::Environment::block | ( | std::wstring(*)(std::string_view) | fn | ) | const |
Returns a contiguous block of memory containing the null-terminated strings with an extra zero character at the end.
Definition at line 87 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 62 of file genvironment.cpp.
|
inlinenoexcept |
Returns true if empty.
Definition at line 115 of file genvironment.h.
|
static |
Returns the environment variable value or the given default.
Definition at line 35 of file genvironment_unix.cpp.
Returns the environment variable value as a G::Path object.
Definition at line 42 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 121 of file genvironment.h.
|
inline |
Returns the environment as a map.
Definition at line 109 of file genvironment.h.
|
static |
Returns a minimal, safe set of environment variables.
Definition at line 63 of file genvironment_unix.cpp.
|
static |
Sets the environment variable value.
Definition at line 55 of file genvironment_unix.cpp.
std::string G::Environment::value | ( | const std::string & | name, |
const std::string & | default_ = {} |
||
) | const |
Returns the value of the given variable in this set.
Definition at line 68 of file genvironment.cpp.