$darkmode
fable::Environment Class Reference

Public Member Functions

 Environment (const Environment &)=default
 
 Environment (Environment &&)=default
 
Environmentoperator= (const Environment &)=default
 
Environmentoperator= (Environment &&)=default
 
 Environment (std::initializer_list< std::pair< std::string const, std::string >> init)
 
 Environment (const std::map< std::string, std::string > &defines)
 
 Environment (std::map< std::string, std::string > &&defines)
 
bool prefer_external () const
 
void prefer_external (bool value)
 
bool allow_undefined () const
 
void allow_undefined (bool value)
 
void insert (const std::string &key, const std::string &value)
 
void set (const std::string &key, const std::string &value)
 
std::optional< std::string > get (const std::string &key) const
 
std::optional< std::string > get (const std::string &key, bool prefer_external) const
 
std::string get_or (const std::string &key, const std::string &alternative) const
 
std::string get_or (const std::string &key, const std::string &alternative, bool prefer_external) const
 
std::string require (const std::string &key) const
 
std::string require (const std::string &key, bool prefer_external) const
 
std::string evaluate (const std::string &s) const
 
std::string evaluate (const std::string &s, bool prefer_external, bool allow_undefined) const
 
std::string interpolate (const std::string &s) const
 
std::string interpolate (const std::string &s, bool prefer_external, bool allow_undefined) const
 

Member Function Documentation

◆ evaluate()

std::string fable::Environment::evaluate ( const std::string &  s) const
inline

Evaluate a single variable, such as "KEY" or "KEY-ALTERNATIVE".

Throws std::out_of_range if allow_undefined() is false and std::invalid_argument if a malformed string is supplied.

◆ get()

std::optional<std::string> fable::Environment::get ( const std::string &  key) const
inline

Return the value of a literal key, trying both environment and internal defines, depending on the value of perfer_external().

If neither are defined, "" is returned when allow_undefined() is true, and a std::out_of_range error is thrown.

This is roughly equivalent to ${KEY}.

Here is the caller graph for this function:

◆ get_or()

std::string fable::Environment::get_or ( const std::string &  key,
const std::string &  alternative 
) const
inline

Return the value of a literal key, trying both environment and internal defines, depending on the value of perfer_external().

If neither are defined, alternative is returned.

This is equivalent to ${KEY-ALTERNATIVE}, and cannot fail.

Here is the call graph for this function:

◆ interpolate()

std::string fable::Environment::interpolate ( const std::string &  s) const
inline

Interpolate a string will evaluate all variable instances in a string.

Throws std::out_of_range if allow_undefined() is false and std::invalid_argument if a malformed string is supplied.

◆ require()

std::string fable::Environment::require ( const std::string &  key) const
inline

Return the value of a literal key, trying both environment and internal defines, depending on the value of perfer_external().

If neither are defined, a std::out_of_range error is thrown.

This is roughly equivalent to ${KEY?out_of_range}.


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