A configuration file as a key/value store.
More...
#include <utils.h>
|
| ConfigFile (const char *input_file_name) |
|
bool | load_config (const char *input_file_name) |
|
int | num_keys () |
|
bool | get_key (const char *key, int &value) |
|
bool | get_key (const char *key, double &value) |
|
bool | get_key (const char *key, std::string &value) |
|
void | debug_put (const std::string key, const std::string val) |
|
|
std::map< std::string, std::string > | config |
| The configuration key/value store.
|
|
A configuration file as a key/value store.
The configuration is loaded when constructing the object and available for reading as int, double or string via get_key().
The input file format removes anything to the right of a // as a remark. It uses a single equal (=) character to separate the key from the value. It also performs a very simple form of quote replacement using CleanConfigArgument().
◆ ConfigFile()
jazz_elements::ConfigFile::ConfigFile |
( |
const char * |
input_file_name | ) |
|
Build a ConfigFile by calling load_config()
- Parameters
-
input_file_name | The input file name containing a configuration |
It returns nothing. Check num_keys() for errors.
◆ load_config()
bool jazz_elements::ConfigFile::load_config |
( |
const char * |
input_file_name | ) |
|
Load a configuration from a file.
Configuration is stored in: map<string, string> config which is private and read using the function get_key().
- Parameters
-
input_file_name | The input file name containing a configuration |
- Returns
- true if some keys were read. (There is no systematic error checking.)
◆ num_keys()
int jazz_elements::ConfigFile::num_keys |
( |
| ) |
|
Get the number of known configuration keys.
- Returns
- The number of configuration keys read from the file when constructing the object. Zero means some failure.
◆ get_key() [1/3]
bool jazz_elements::ConfigFile::get_key |
( |
const char * |
key, |
|
|
int & |
value |
|
) |
| |
Get the value for an existing configuration key.
- Parameters
-
key | The configuration key to be searched. |
value | Value to be returned only when the function returns true. |
- Returns
- True when the key exists and can be returned with the specific (overloaded) type.
◆ get_key() [2/3]
bool jazz_elements::ConfigFile::get_key |
( |
const char * |
key, |
|
|
double & |
value |
|
) |
| |
Get the value for an existing configuration key.
- Parameters
-
key | The configuration key to be searched. |
value | Value to be returned only when the function returns true. |
- Returns
- True when the key exists and can be returned with the specific (overloaded) type.
◆ get_key() [3/3]
bool jazz_elements::ConfigFile::get_key |
( |
const char * |
key, |
|
|
std::string & |
value |
|
) |
| |
Get the value for an existing configuration key.
- Parameters
-
key | The configuration key to be searched. |
value | Value to be returned only when the function returns true. |
- Returns
- True when the key exists and can be returned with the specific (overloaded) type.
◆ debug_put()
void jazz_elements::ConfigFile::debug_put |
( |
const std::string |
key, |
|
|
const std::string |
val |
|
) |
| |
DEBUG ONLY function: Set a config key manually.
- Parameters
-
key | The configuration key to be set. |
val | New value of the key as a string (also valid for int and double if the string can be converted). |
The documentation for this class was generated from the following files: