Reads and parses configuration files and provides methods to access configuration items.
More...
|
|
| Config (void) |
| | Creates empty configuration object.
|
| |
| | Config (std::string filename) |
| |
|
void | dump (void) |
| | Dumps the current configuration to stdout.
|
| |
| bool | exist (std::string key) const |
| |
| void | add (std::string key, const ByteArray &value) |
| |
| void | addString (std::string key, std::string value) |
| |
| void | addInt (std::string key, int value) |
| |
| ByteArray | get (std::string key, ByteArray def) const |
| |
| std::string | getString (std::string key, std::string def) |
| |
| int | getInt (std::string key, int def) |
| |
| std::vector< std::string > | getStringValues (std::string key) const |
| |
Reads and parses configuration files and provides methods to access configuration items.
The Config class parses a given configuration file and provides the values.
Valid lines have to be structured according the scheme:
Optionally multiple values can be assigned to a key either separated by a space or tabulator:
<KEY> = <VALUE1> <VALUE2> <VALUE3>
or spread over multiple lines each ended by a backslash:
<KEY> = <VALUE1> \
<VALUE2> \
<VALUE3>
Rules:
- leading and trailing blanks are stripped on keys and values.
- a key may not contain blanks.
- a configuration value may contain blanks (e.g. 'Device = c:/program files/myapp/config').
- backward slashes are used to indicate that a value is continued on the next line.
- a backward slash may not follow immediately to a value, at least one blank has to separate value and backward slash.
- backward slashes may not be used within values, even on Windows forward slashes have to be used within path names.
- a char ('#') may be used to comment out the current line.
- a char may only be placed in front of a key.
- invalid lines are ignored.
|
A sample configuration file looks like this:
# This is a sample CXI configuration file
LogFile = d:/temp/
cxi.log
LogLevel = 3
LogSize = 1MB
# dedicated device
#Device = PCI:0
# cluster
Device = PCI:0 \
192.168.4.183 \
192.168.4.184 \
192.168.4.185
ConnectTimeout = 5000
Timeout = 60000
The following example illustrates the usage of the Config class:
int timeout = config.
getInt(
"Timeout", -1);
Reads and parses configuration files and provides methods to access configuration items.
Definition: sw/cxi_api_c/def/config.h:28
int getInt(std::string key, int def)
Definition: config.cpp:224
void addInt(std::string key, int value)
Definition: config.cpp:181
Config(void)
Creates empty configuration object.
Definition: config.cpp:127
void dump(void)
Dumps the current configuration to stdout.
Definition: config.cpp:294
std::vector< std::string > getStringValues(std::string key) const
Definition: config.cpp:256
Command interface to CXI firmware module. Handles all communication with the CryptoServer.
Definition: sw/cxi_api_c/def/cxi.h:60