Environment

Method
Description
store
Retrieves store from environment.
has_store
Checks whether environment has store for some data type.
out
Retreives standard output stream.
err
Retreives standard error stream.
reroute
Changes output and error streams.
commands
Returns map of commands.
categories
Returns map of categories.
aliases
Returns a map of aliases.
set_default_option
Sets default store option.
default_option
Returns the current default store option.
has_default_option
Checks whether a default store option is enabled and set.
has_default_option
Checks whether a default store option is enabled and set from a set of options.
is_default_option
Checks whether option is default store option.
class environment

Shell environment.

The environment gives access to shell related properties, e.g., the commands and stores.

Public Types

using ptr = std::shared_ptr<environment>

Smart pointer alias for environment.

Public Functions

template<typename T>
store_container<T> &store() const

Retrieves store from environment.

The store can be accessed using its type.

template<typename T>
bool has_store() const

Checks whether environment has store for some data type.

Stores are defined by their type.

std::ostream &out() const

Retreives standard output stream.

This method returns a reference to the current standard output stream. In stand-alone application mode, this is std::cout by default, but can be changed. Users should aim for not printing to std::cout directly in a command, but use env->out() instead.

std::ostream &err() const

Retreives standard error stream.

This method returns a reference to the current standard error stream. In stand-alone application mode, this is std::cerr by default, but can be changed. Users should aim for not printing to std::cerr directly in a command, but use env->err() instead.

void reroute(std::ostream &new_out, std::ostream &new_err)

Changes output and error streams.

This method allows to change the output streams which are returned by out() and err().

const std::unordered_map<std::string, std::shared_ptr<command>> &commands() const

Returns map of commands.

The keys correspond to the command names in the shell.

const std::unordered_map<std::string, std::vector<std::string>> &categories() const

Returns map of categories.

Keys are catgory names pointing to a vector of command names that can be used to index into commands().

const std::unordered_map<std::string, std::string> &aliases() const

Returns a map of aliases.

Keys are the alias regular expressions mapping to substitutions.

const std::string &variable(const std::string &key, const std::string &default_value = std::string()) const

Get environment variable.

Finds an environment variable or returns a default value. Variables can be set with the set command.

Parameters
  • key: Key for the value
  • default_value: Default value

void set_default_option(const std::string &default_option)

Sets default store option.

The environment can keep track of a default store option that can be changed after every command. For example, if one has a store for strings (accessed via option --str) and one for numbers (access via option --int), then a call to read_text --str file would set the default option to --str, such that a immediate call to print would not need the --str option to print the string. The default store option is displayed in the prompt.

This behavior needs to be enabled by defining the macro ALICE_SETTINGS_WITH_DEFAULT_OPTION to true, before the alice.hpp is included.

Parameters
  • default_option: Updates default store option for next commands

const std::string &default_option() const

Returns the current default store option.

bool has_default_option() const

Checks whether a default store option is enabled and set.

bool has_default_option(std::vector<std::string> const &list) const

Checks whether a default store option is enabled and set from a set of options.

bool is_default_option(const std::string &option) const

Checks whether option is default store option.

This method also checks whether default store options are enabled. If not, this method always returns false.

Parameters
  • option: Option argument to check (fill name without dashes)