21#ifndef G_ENVIRONMENT_H
22#define G_ENVIRONMENT_H
41 static std::string
get(
const std::string & name ,
const std::string & default_ ) ;
44 static void put(
const std::string & name ,
const std::string &
value ) ;
54 explicit Environment(
const std::map<std::string,std::string> & ) ;
60 void add(
const std::string & name ,
const std::string &
value ) ;
64 bool contains(
const std::string & name )
const ;
67 std::string
value(
const std::string & name ,
const std::string & default_ = std::string() )
const ;
70 void set(
const std::string & name ,
const std::string &
value ) ;
73 const char *
ptr() const noexcept ;
78 char **
v() const noexcept ;
81 bool empty() const noexcept ;
105 using Map = std::map<std::
string,std::
string> ;
106 using List = std::vector<std::
string> ;
107 static
char * stringdup( const std::
string & ) ;
115 std::vector<std::
string> m_list ;
116 std::vector<
char*> m_pointers ;
117 std::
string m_block ;
123 return m_map.empty() ;
Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().
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()
Returns a minimal, safe set of environment variables.
std::string value(const std::string &name, const std::string &default_=std::string()) const
Returns the value of the given variable in this set.
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.