21#ifndef G_ENVIRONMENT_H
22#define G_ENVIRONMENT_H
42 G_EXCEPTION( Error ,
tx(
"invalid environment variable") ) ;
44 static std::string
get(
const std::string & name ,
const std::string & default_ ) ;
47 static void put(
const std::string & name ,
const std::string &
value ) ;
57 explicit Environment(
const std::map<std::string,std::string> & ) ;
63 void add(
const std::string & name ,
const std::string &
value ) ;
67 bool contains(
const std::string & name )
const ;
70 std::string
value(
const std::string & name ,
const std::string & default_ = {} )
const ;
73 void set(
const std::string & name ,
const std::string &
value ) ;
76 const char *
ptr() const noexcept ;
81 char **
v() const noexcept ;
84 bool empty() const noexcept ;
108 using Map =
std::map<
std::
string,
std::
string> ;
109 using List =
std::vector<
std::
string> ;
110 static
char * stringdup( const
std::
string & ) ;
118 std::vector<
std::
string> m_list ;
119 std::vector<
char*> m_pointers ;
120 std::
string m_block ;
126 return m_map.empty() ;
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().
std::string value(const std::string &name, const std::string &default_={}) const
Returns the value of the given variable in this set.
bool valid() const
Returns true if the class invariants are satisfied.
static void put(const std::string &name, const std::string &value)
Sets the environment variable value.
static std::string get(const std::string &name, const std::string &default_)
Returns the environment variable value or the given default.
~Environment()=default
Destructor.
bool empty() const noexcept
Returns true if empty.
static Environment inherit()
Returns an empty() environment, as if default constructed.
static Environment minimal(bool sbin=false)
Returns a minimal, safe set of environment variables.
void add(const std::string &name, const std::string &value)
Adds a variable to this set.
const char * ptr() const noexcept
Returns a contiguous block of memory containing the null-terminated strings with an extra zero byte a...
void set(const std::string &name, const std::string &value)
Inserts or updates a variable in this set.
bool contains(const std::string &name) const
Returns true if the given variable is in this set.
char ** v() const noexcept
Returns a null-terminated array of pointers.
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().