|
rambrain
|
Reader class to read in and properly parse config files. More...
#include <configreader.h>
Public Member Functions | |
| configReader () | |
| Init a new reader. More... | |
| bool | readConfig () |
| Read in and parse config. More... | |
| void | setCustomConfigPath (const string &path) |
| Simple setter. More... | |
| configuration & | getConfig () |
| Simple getter. More... | |
| bool | readSuccessfully () const |
| Simple getter. More... | |
| void | setReread () |
| Simple setter. More... | |
Private Member Functions | |
| bool | reopenStreams () |
| (Re)Open streams to config files More... | |
| bool | parseConfigFile (istream &stream, vector< configLineBase * > &readLines) |
| Parse config file. More... | |
| bool | parseConfigBlock (istream &stream, vector< configLineBase * > &readLines) |
| Parse an identified configuration block and extract all matching variables. More... | |
| string | getApplicationName () const |
| Extract the current binary's name out of the /proc file system. More... | |
| string | getHomeDir () const |
| Look up the home directory of the current user. More... | |
| void | stripLeadingTrailingWhitespace (string &str) const |
| Strips any leading and trailing whitespace from a given string. More... | |
Private Attributes | |
| const string | globalConfigPath = "/etc/rambrain.conf" |
| string | localConfigPath = "" |
| string | customConfigPath = "" |
| const regexMatcher | regex |
| ifstream | streams [3] |
| configuration | config |
| bool | readSuccess = false |
Friends | |
| class | ::configReader_Unit_ParseProgramName_Test |
Reader class to read in and properly parse config files.
A sample config file looks like following:
[default]
key1 = value1
key2 = value2
[binname1]
key = value
...
While keys are exactly the names of members of the configuration struct There are three different locations to search for a config file, in descending priority: custom location > user home dir > global Not all options need to be supplied. Missing options are taken from the default block or (if not present there either) from the defaults Also all different files are taken into account to supply missing options
Definition at line 163 of file configreader.h.
| rambrain::configReader::configReader | ( | ) |
Init a new reader.
Definition at line 152 of file configreader.cpp.
|
private |
Extract the current binary's name out of the /proc file system.
Definition at line 295 of file configreader.cpp.
|
inline |
Simple getter.
Definition at line 192 of file configreader.h.
|
private |
Look up the home directory of the current user.
Definition at line 312 of file configreader.cpp.
|
private |
Parse an identified configuration block and extract all matching variables.
| stream | The input stream |
| readLines | Vector to track which config options are already read |
Definition at line 247 of file configreader.cpp.
|
private |
Parse config file.
Look for default block as well as block matching the current binary name (which has priority of course)
| stream | The input stream |
| readLines | Vector to track which config options are already read |
Definition at line 209 of file configreader.cpp.
| bool rambrain::configReader::readConfig | ( | ) |
Read in and parse config.
Definition at line 157 of file configreader.cpp.
|
inline |
Simple getter.
Definition at line 202 of file configreader.h.
|
private |
(Re)Open streams to config files
Order is Custom location > Local user space > Global config
Definition at line 177 of file configreader.cpp.
|
inline |
Simple setter.
Definition at line 185 of file configreader.h.
|
inline |
Simple setter.
Definition at line 208 of file configreader.h.
|
private |
Strips any leading and trailing whitespace from a given string.
| str | The string to be stripped |
Definition at line 318 of file configreader.cpp.
|
friend |
Definition at line 273 of file configreader.h.
|
private |
Definition at line 267 of file configreader.h.
|
private |
Definition at line 261 of file configreader.h.
|
private |
Definition at line 259 of file configreader.h.
|
private |
Definition at line 260 of file configreader.h.
|
private |
Definition at line 269 of file configreader.h.
|
private |
Definition at line 263 of file configreader.h.
|
private |
Definition at line 265 of file configreader.h.