Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::Environment Class Reference

Interrogate and extend environment variables. More...

#include <Environment.hh>

Public Types

Type aliases
using key_type = Container::key_type
 
using mapped_type = Container::mapped_type
 
using value_type = Container::value_type
 
using const_iterator = Container::const_iterator
 
using VecKVRef = std::vector< std::reference_wrapper< value_type > >
 

Public Member Functions

mapped_type const & operator[] (key_type const &)
 Get an environment variable from current or system enviroments.
 
bool insert (value_type const &value)
 Set a single environment variable that hasn't yet been set. More...
 
VecKVRef const & ordered_environment () const
 Get an ordered (by access) vector of key/value pairs.
 
void clear ()
 Remove all entries.
 
void merge (Environment const &other)
 Insert but don't override from another environment.
 

Detailed Description

Interrogate and extend environment variables.

This makes it easier to generate reproducible runs, launch Celeritas remotely, or integrate with application drivers. The environment variables may be encoded as JSON input to supplement or override system environment variables, or set programmatically via this API call. Later the environment class can be interrogated to find which environment variables were accessed.

Unlike the standard environment which returns a null pointer for an unset variable, this returns an empty string.

Note
This class is not thread-safe on its own. The celeritas::getenv free function however is safe, although it should only be used in setup (single-thread) steps.
Once inserted into the environment map, values cannot be changed. Standard practice in the code is to evaluate the environment variable exactly once and cache the result as a static const variable. If you really wanted to, you could call celeritas::environment() = {}; but that could result in the end-of-run diagnostic reporting different values than the ones actually used during the code's setup.

Member Function Documentation

◆ insert()

bool celeritas::Environment::insert ( value_type const &  value)

Set a single environment variable that hasn't yet been set.

Existing environment variables will not be overwritten.

Returns
Whether insertion took place

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