mp2p_icp_common library
Overview
Core data structures and utilities for mp2p_icp
// global functions std::string mp2p_icp::expand_yaml_variables( const std::string& text, const std::map<std::string, std::string>& variables = {} ); mrpt::containers::yaml mp2p_icp::load_yaml_file( const std::string& fileName, const std::map<std::string, std::string>& variables = {} );
Global Functions
std::string mp2p_icp::expand_yaml_variables( const std::string& text, const std::map<std::string, std::string>& variables = {} )
Replaces all ${VAR} and ${VAR|default} tokens in a YAML text.
Each variable is resolved from (first match wins):
The environment variable
VAR.An entry
VARinvariables.The inline default after
|, which may be empty (${VAR|}).
If none applies, an exception is thrown. Only CURRENT_YAML_FILE_PATH is looked up in variables before the environment. Tokens within YAML comments (after a # that starts the line or follows a blank, outside quotes) are not expanded, and substituted values are not scanned again for more tokens.
Expansion works on the raw text, so tokens may appear anywhere, including within quoted strings or formulas, e.g. "robot_x - ${RANGE|10.0}".
This is a subset of the YAML pre-processing in MOLA’s mola_yaml package, which also supports file includes and shell commands.
mrpt::containers::yaml mp2p_icp::load_yaml_file( const std::string& fileName, const std::map<std::string, std::string>& variables = {} )
Loads a YAML file, expanding its variables with expand_yaml_variables().
In addition to variables, the variable CURRENT_YAML_FILE_PATH is always the directory of the file, overriding any variable of the same name.
Parameters:
std::exception |
If the file cannot be read, a variable is undefined and has no default, or the expanded text is not valid YAML. |