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.
|
| 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>
boolhas_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::coutby default, but can be changed. Users should aim for not printing tostd::coutdirectly in a command, but useenv->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::cerrby default, but can be changed. Users should aim for not printing tostd::cerrdirectly in a command, but useenv->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()anderr().
-
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
setcommand.- Parameters
key: Key for the valuedefault_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 toread_text --str filewould set the default option to--str, such that a immediate call toprintwould not need the--stroption 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_OPTIONtotrue, before thealice.hppis 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
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)
-
using