erwi/reader
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
A simple single-header-only c++ library for reading in key/value pairs from text files to be
used e.g. to easily specify settings/configuration in programs.
The text file must specifies key/value pairs separated by the '=' sign, e.g.:
key1 = a_value
Values can be numbers, strings, arrays of numbers or arrays of strings:
stringKey = some_word # comments are supported!
numericKey = 1e-4
arrayOfNumbers = [1,3,5e-3]
arrayOfText = [first, second, third , 4]
Comments can be insterted following the '#' character.
Use:
1. include the "reader.h" file.
#include <reader.h>
2. Create a reader object:
Reader reader;
3. Read a text file:
reader.readSettings("test.txt");
4. Read in values :
try {
string s = reader.getValueByKey<string>("stringKey");
std::vector<float> = reader.getValueByKey<std::vector<float>>("keyName");
if (reader.containsKey("OptionalKey) ){
int optionalInt = reader.getValueByKey<int>("OptionalKey");
}
}catch(ReaderError e){
e.printError();
}
5. Compile with a c++11 compatible compiler
Exceptions will be thrown when things don't work out. For example when trying to
read incompaible types. The thrown exception contains in addition to a convenience
print method the following data:
1. Reason for exception.
2. Name of input file..
3. Line number in input file causing the exception.