YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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.
 
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.
 
std::string get_string (const std::string &key, bool *found=nullptr)
 Read a string from an environment variable.
 
std::string get_string (const std::string &key, const std::string &defaultValue)
 Read a string from an environment variable with a default value.
 
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.
 
std::vector< std::string > get_path (const std::string &key, bool *found=nullptr)
 Read a path from an environment variable.
 
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.
 
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.
 
bool get_bool (const std::string &key, bool defaultValue=false)
 Read a bool value from an environment variable.
 
template<typename T >
get_numeric (const std::string &key, T defaultValue=static_cast< T >(0))
 Read an numeric value from an environment variable.
 
bool set_string (const std::string &key, const std::string &value)
 Set a string to an environment variable.
 
bool set_path (const std::string &key, const std::vector< std::string > &value)
 Set a path to an environment variable.
 
bool set_bool (const std::string &key, bool value)
 Set a bool to an environment variable (as 1 or 0).
 
template<typename T >
bool set_numeric (const std::string &key, bool value)
 Set a numeric value to an environment variable.
 
bool unset (const std::string &key)
 Remove an environment variable.
 
bool is_set (const std::string &key)
 Check if an environment variable is set.
 
std::string getEnvironment (const char *key, bool *found=nullptr)
 Read a string from an environment variable.
 
void setEnvironment (const std::string &key, const std::string &value)
 Set or change an environment variable.
 
void unsetEnvironment (const std::string &key)
 Remove an environment variable.
 

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 172 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 191 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 118 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 148 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 132 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 66 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 102 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 87 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 307 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 288 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 52 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 242 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 259 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 228 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 209 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 322 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 39 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 272 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 336 of file environment.h.

Variable Documentation

◆ path_separator

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

Definition at line 27 of file environment.h.