Celeritas  0.5.0-56+6b053cd
Classes | Functions
Environment.hh File Reference
#include <functional>
#include <iosfwd>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

Classes

class  celeritas::Environment
 Interrogate and extend environment variables. More...
 
struct  celeritas::GetenvFlagResult
 Return result from getenv_flag. More...
 

Functions

Environment & celeritas::environment ()
 Access a static global environment variable. More...
 
std::string const & celeritas::getenv (std::string const &key)
 Thread-safe access to global modified environment variables. More...
 
GetenvFlagResult celeritas::getenv_flag (std::string const &key, bool default_val)
 Get a true/false flag with a default value. More...
 
std::ostream & celeritas::operator<< (std::ostream &os, Environment const &env)
 Write the accessed environment variables to a stream.
 

Function Documentation

◆ environment()

Environment & celeritas::environment ( )

Access a static global environment variable.

This static variable should be shared among Celeritas objects.

◆ getenv()

std::string const & celeritas::getenv ( std::string const &  key)

Thread-safe access to global modified environment variables.

This function will insert the current value of the key into the environment, which remains immutable over the lifetime of the program (allowing the use of static const data to be set from the environment).

◆ getenv_flag()

GetenvFlagResult celeritas::getenv_flag ( std::string const &  key,
bool  default_val 
)

Get a true/false flag with a default value.

The return value is a pair that has (1) the flag as determined by the environment variable or default value, and (2) an "insertion" flag specifying whether the default was used. The insertion result can be useful for providing a diagnostic message to the user.

  • Allowed true values: "1", "t", "yes", "true", "True"
  • Allowed false values: "0", "f", "no", "false", "False"
  • Empty value returns the default
  • Other value warns and returns the default