The ConfigFileReader parses Windows .ini like file into map<string, string>
The file is list of pairs, the key and the value, separated by an equal sign '='. Pair is not permitted to span more than one line.
Start of the section is denoted by [SectionName]. Section name is added to the following keys name e.g. SectionName.KeyName Next section ends the previous one (use [] to set no section).
Commentary :
- begins with a hash ('#') as the first non-space character on the line.
- begins with semi-colon (;) anywhere and spans to the end of the line
By default it parses input file or stream to the end (EOF). It can be set up to stop on given section name. It is useful when file contains not only pairs "key = value" but also raw data that spans across several lines.
Example:
This is an example
command = copy
In the following we could also define section [source]
to shorten keys names
source.directory = C:\Documents and Settings\Jennifer\My Documents source.size = 4 ; number of files source.files = file1.cpp file2.cpp file3.cpp file4.cpp ; file names cannot have white-spaces [destination] directory = C:\Temp
Usage:
ConfigFileReader ini("iniFileName");
std::string command; ini.getValue("command", command);
std::string sourceDir, destinationDir; ini.getValue("source.directory", sourceDir); ini.getValue("destination.directory", destinationDir);
int numberOfFiles = 10; // or ini.getValue("source.size",numberOfFiles); // int numberOfFiles = ini.get<int>("source.size", 10);
ini.getValue("source.number of files", numberOfFiles); // it will not change the value because this key do not exist
std::vector<std::string> fileNames(numberOfFiles);
ini.getValues("source.files", fileNames.begin(), fileNames.end());
More examples in capdAux/examples/configFileReader