CARMA C++
|
Common functions for manipulating key-value config files This class contains no state. More...
#include <carma/util/KeyValueConfigFile.h>
Public Member Functions | |
KeyValueConfigFile () | |
Default constructor. More... | |
virtual | ~KeyValueConfigFile () |
Destructor. More... | |
Static Public Member Functions | |
static std::map< std::string, std::string > | load (const std::string &filename, const std::string &delimiter="=", const std::string &commentStr="#", const std::string ¯oStartStr="${", const std::string ¯oEndStr="}", const bool &useEnvironment=true) |
read a config file and return its values as a key-value map Lines which begin with commentStr are considered comments and are not processed. More... | |
Common functions for manipulating key-value config files This class contains no state.
Definition at line 29 of file KeyValueConfigFile.h.
carma::util::KeyValueConfigFile::KeyValueConfigFile | ( | ) |
Default constructor.
|
virtual |
Destructor.
|
static |
read a config file and return its values as a key-value map Lines which begin with commentStr are considered comments and are not processed.
Lines with more than one delimiter are not processed. Tabs and blank spaces are removed from the beginning and end (but not the middle) of both keys and values. Macro expansion (a'la Makefiles) is used using macroStartStr
and macroEndStr
. For example, in a file with the following lines
foo = bar baz = ${foo}.raz
This method will expand baz
to bar.raz
(assuming the default values of macroStartStr
and macroEndStr
are used). If a macro has not been defined previously in the config file, but is an environment variable, the value of the environment variable will be substituted unless the useEnvironment
parameter is false
config files may be included in config files by using the
include <filename>
directive. The path of the included file must be relative to the file which includes it. include
directives may occur at any point in a config file; the result is just if the code in the included file had been inserted in place of the include
directive (e.g., any variables defined prior to the include
directive will be overwritten if they are defined again in the include file, any variables defined in the include file will be overwritten if they are redefined in the original file after the include
directive
filename | the file to read |
delimiter | the key-value delimiter to use |
commentStr | lines starting with this string (after stripping leading spaces will be treated as comments |
macroStartStr | string indicating the start of a macro |
macroEndStr | string indicating the end of a macro |
useEnvironment | if true, search for an environment variable matching the macro and use its value if it exists |
NotFoundException | if file cannot be read |