E-MailRelay
Public Member Functions | Static Public Member Functions | List of all members
G::Environment Class Reference

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...
 
Environmentoperator= (const Environment &)
 Assigment operator. More...
 
Environmentoperator= (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...
 

Detailed Description

Holds a set of environment variables and also provides static methods to wrap getenv() and putenv().

Definition at line 38 of file genvironment.h.

Constructor & Destructor Documentation

◆ Environment() [1/3]

G::Environment::Environment ( const std::map< std::string, std::string > &  map)
explicit

Constructor from a map.

Definition at line 32 of file genvironment.cpp.

◆ Environment() [2/3]

G::Environment::Environment ( const Environment other)

Copy constructor.

Definition at line 38 of file genvironment.cpp.

◆ Environment() [3/3]

G::Environment::Environment ( Environment &&  other)
noexcept

Move constructor.

Definition at line 44 of file genvironment.cpp.

Member Function Documentation

◆ add()

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.

◆ contains()

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.

◆ empty()

bool G::Environment::empty ( ) const
inlinenoexcept

Returns true if empty.

Definition at line 121 of file genvironment.h.

◆ get()

std::string G::Environment::get ( const std::string &  name,
const std::string &  default_ 
)
static

Returns the environment variable value or the given default.

Definition at line 27 of file genvironment_unix.cpp.

◆ inherit()

G::Environment G::Environment::inherit ( )
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.

◆ minimal()

G::Environment G::Environment::minimal ( )
static

Returns a minimal, safe set of environment variables.

Definition at line 46 of file genvironment_unix.cpp.

◆ operator=() [1/2]

G::Environment & G::Environment::operator= ( const Environment other)

Assigment operator.

Definition at line 68 of file genvironment.cpp.

◆ operator=() [2/2]

G::Environment & G::Environment::operator= ( Environment &&  other)
noexcept

Move assigment operator.

Definition at line 74 of file genvironment.cpp.

◆ ptr()

const char * G::Environment::ptr ( ) const
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.

◆ put()

void G::Environment::put ( const std::string &  name,
const std::string &  value 
)
static

Sets the environment variable value.

Definition at line 39 of file genvironment_unix.cpp.

◆ set()

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.

◆ v()

char ** G::Environment::v ( ) const
noexcept

Returns a null-terminated array of pointers.

Definition at line 135 of file genvironment.cpp.

◆ valid()

bool G::Environment::valid ( ) const

Returns true if the class invariants are satisfied.

Used in testing.

Definition at line 60 of file genvironment.cpp.

◆ value()

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.


The documentation for this class was generated from the following files: