YARP
Yet Another Robot Platform
yarp::conf::environment Namespace Reference

Functions

template<typename ContainerT = std::vector<std::string>>
ContainerT split_path (const typename ContainerT::value_type &s)
 Utility to split a string containing a path separated by the path_separator, which depends on the system, into a vector of strings. More...
 
template<typename ContainerT = std::vector<std::string>>
ContainerT::value_type join_path (const ContainerT &v)
 Utility to join a vector of strings into a single string separated by the proper path_separator, which depends on the system. More...
 
std::string get_string (const std::string &key, bool *found=nullptr)
 Read a string from an environment variable. More...
 
std::string get_string (const std::string &key, const std::string &defaultValue)
 Read a string from an environment variable with a default value. More...
 
std::string get_string (const std::string &key, const std::string &altKey, const std::string &altDefaultValue, const std::string &altAppend={})
 Read a string from an environment variable with with a fallback. More...
 
std::vector< std::string > get_path (const std::string &key, bool *found=nullptr)
 Read a path from an environment variable. More...
 
std::vector< std::string > get_path (const std::string &key, const std::string &defaultValue)
 Read a path from an environment variable with a default value. More...
 
std::vector< std::string > get_path (const std::string &key, const std::string &altKey, const std::string &altDefaultValue, const std::string &altAppend={})
 Read a path from an environment variable with a fallback. More...
 
bool get_bool (const std::string &key, bool defaultValue=false)
 Read a bool value from an environment variable. More...
 
template<typename T >
get_numeric (const std::string &key, T defaultValue=static_cast< T >(0))
 Read an numeric value from an environment variable. More...
 
bool set_string (const std::string &key, const std::string &value)
 Set a string to an environment variable. More...
 
bool set_path (const std::string &key, const std::vector< std::string > &value)
 Set a path to an environment variable. More...
 
bool set_bool (const std::string &key, bool value)
 Set a bool to an environment variable (as 1 or 0). More...
 
template<typename T >
bool set_numeric (const std::string &key, bool value)
 Set a numeric value to an environment variable. More...
 
bool unset (const std::string &key)
 Remove an environment variable. More...
 
bool is_set (const std::string &key)
 Check if an environment variable is set. More...
 
std::string getEnvironment (const char *key, bool *found=nullptr)
 Read a string from an environment variable. More...
 
void setEnvironment (const std::string &key, const std::string &value)
 Set or change an environment variable. More...
 
void unsetEnvironment (const std::string &key)
 Remove an environment variable. More...
 

Variables

static constexpr char path_separator = ':'
 

Function Documentation

◆ get_bool()

bool yarp::conf::environment::get_bool ( const std::string &  key,
bool  defaultValue = false 
)
inline

Read a bool value from an environment variable.

Parameters
keythe environment variable to read
defaultValuethe default value to return if the environment variable is not found
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 174 of file environment.h.

◆ get_numeric()

template<typename T >
T yarp::conf::environment::get_numeric ( const std::string &  key,
defaultValue = static_cast<T>(0) 
)
inline

Read an numeric value from an environment variable.

Parameters
keythe environment variable to read
defaultValuethe default value to return if the environment variable is not found
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 193 of file environment.h.

◆ get_path() [1/3]

std::vector<std::string> yarp::conf::environment::get_path ( const std::string &  key,
bool *  found = nullptr 
)
inline

Read a path from an environment variable.

Parameters
keythe environment variable to read
foundan optional variable to set to true iff variable is found
Returns
the value of the environment variable, or empty if not found
Since
YARP 3.5

Definition at line 120 of file environment.h.

◆ get_path() [2/3]

std::vector<std::string> yarp::conf::environment::get_path ( const std::string &  key,
const std::string &  altKey,
const std::string &  altDefaultValue,
const std::string &  altAppend = {} 
)
inline

Read a path from an environment variable with a fallback.

Parameters
keythe environment variable to read
altKeythe alternative variable to read if key is not defined
altDefaultValuethe default for the alternative value to use if environment variable is not found
altAppenda string to append to each directory in the alternative variable (or its default) if key is not defined
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 150 of file environment.h.

◆ get_path() [3/3]

std::vector<std::string> yarp::conf::environment::get_path ( const std::string &  key,
const std::string &  defaultValue 
)
inline

Read a path from an environment variable with a default value.

Parameters
keythe environment variable to read
defaultValuethe default value to return if the environment variable is not found
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 134 of file environment.h.

◆ get_string() [1/3]

std::string yarp::conf::environment::get_string ( const std::string &  key,
bool *  found = nullptr 
)
inline

Read a string from an environment variable.

Parameters
keythe environment variable to read
foundan optional variable to set to true iff variable is found
Returns
the value of the environment variable, or "" if not found
Since
YARP 3.5

Definition at line 68 of file environment.h.

◆ get_string() [2/3]

std::string yarp::conf::environment::get_string ( const std::string &  key,
const std::string &  altKey,
const std::string &  altDefaultValue,
const std::string &  altAppend = {} 
)
inline

Read a string from an environment variable with with a fallback.

Parameters
keythe environment variable to read
defaultValuethe default value to return if the environment variable is not found
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 104 of file environment.h.

◆ get_string() [3/3]

std::string yarp::conf::environment::get_string ( const std::string &  key,
const std::string &  defaultValue 
)
inline

Read a string from an environment variable with a default value.

Parameters
keythe environment variable to read
defaultValuethe default value to return if the environment variable is not found
Returns
the value of the environment variable, or defaultValue if not found
Since
YARP 3.5

Definition at line 89 of file environment.h.

◆ getEnvironment()

std::string yarp::conf::environment::getEnvironment ( const char *  key,
bool *  found = nullptr 
)
inline

Read a string from an environment variable.

Parameters
keythe environment variable to read
foundan optional variable to set to true iff variable is found
Returns
the value of the environment variable, or "" if not found
Since
YARP 3.4
Deprecated:
since YARP 3.5. Use yarp::conf::environment::get_string() instead

Definition at line 309 of file environment.h.

◆ is_set()

bool yarp::conf::environment::is_set ( const std::string &  key)
inline

Check if an environment variable is set.

Parameters
keythe environment variable to check
Returns
true if the variable is set, false otherwise

Definition at line 290 of file environment.h.

◆ join_path()

template<typename ContainerT = std::vector<std::string>>
ContainerT::value_type yarp::conf::environment::join_path ( const ContainerT &  v)
inline

Utility to join a vector of strings into a single string separated by the proper path_separator, which depends on the system.

Parameters
sthe vector of strings to join
Returns
a strings containing the generated path

Definition at line 54 of file environment.h.

◆ set_bool()

bool yarp::conf::environment::set_bool ( const std::string &  key,
bool  value 
)
inline

Set a bool to an environment variable (as 1 or 0).

Parameters
keythe environment variable to set or change
valuethe target value
Returns
true if the environment variable was set, false on error.
Since
YARP 3.5

Definition at line 244 of file environment.h.

◆ set_numeric()

template<typename T >
bool yarp::conf::environment::set_numeric ( const std::string &  key,
bool  value 
)
inline

Set a numeric value to an environment variable.

Parameters
keythe environment variable to set or change
valuethe target value
Returns
true if the environment variable was set, false on error.
Since
YARP 3.5

Definition at line 261 of file environment.h.

◆ set_path()

bool yarp::conf::environment::set_path ( const std::string &  key,
const std::vector< std::string > &  value 
)
inline

Set a path to an environment variable.

Parameters
keythe environment variable to set or change
valuethe target value
Returns
true if the environment variable was set, false on error.
Since
YARP 3.5

Definition at line 230 of file environment.h.

◆ set_string()

bool yarp::conf::environment::set_string ( const std::string &  key,
const std::string &  value 
)
inline

Set a string to an environment variable.

Parameters
keythe environment variable to set or change
valuethe target value
Returns
true if the environment variable was set, false on error.
Since
YARP 3.5

Definition at line 211 of file environment.h.

◆ setEnvironment()

void yarp::conf::environment::setEnvironment ( const std::string &  key,
const std::string &  value 
)
inline

Set or change an environment variable.

Parameters
keythe environment variable to set or change
valuethe target value
Since
YARP 3.4
Deprecated:
since YARP 3.5. Use yarp::conf::environment::set_string() instead

Definition at line 324 of file environment.h.

◆ split_path()

template<typename ContainerT = std::vector<std::string>>
ContainerT yarp::conf::environment::split_path ( const typename ContainerT::value_type &  s)
inline

Utility to split a string containing a path separated by the path_separator, which depends on the system, into a vector of strings.

Parameters
sthe string to split
Returns
a vector of strings each containing one of the element of the path

Definition at line 41 of file environment.h.

◆ unset()

bool yarp::conf::environment::unset ( const std::string &  key)
inline

Remove an environment variable.

Parameters
keythe environment variable to remove
Returns
true if the operation was successful, false on error.
Since
YARP 3.5

Definition at line 274 of file environment.h.

◆ unsetEnvironment()

void yarp::conf::environment::unsetEnvironment ( const std::string &  key)
inline

Remove an environment variable.

Parameters
keythe environment variable to remove
Since
YARP 3.4
Deprecated:
since YARP 3.5. Use yarp::conf::environment::unset() instead

Definition at line 338 of file environment.h.

Variable Documentation

◆ path_separator

constexpr char yarp::conf::environment::path_separator = ':'
staticconstexpr

Definition at line 29 of file environment.h.