Jazz 1.25.+
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
jazz_elements::ConfigFile Class Reference

A configuration file as a key/value store. More...

#include <utils.h>

Public Member Functions

 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)
 

Private Attributes

std::map< std::string, std::string > config
 The configuration key/value store.
 

Detailed Description

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().

Constructor & Destructor Documentation

◆ ConfigFile()

jazz_elements::ConfigFile::ConfigFile ( const char *  input_file_name)

Build a ConfigFile by calling load_config()

Parameters
input_file_nameThe input file name containing a configuration

It returns nothing. Check num_keys() for errors.

Member Function Documentation

◆ 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_nameThe 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
keyThe configuration key to be searched.
valueValue 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
keyThe configuration key to be searched.
valueValue 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
keyThe configuration key to be searched.
valueValue 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
keyThe configuration key to be set.
valNew 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: