-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_parser.h
38 lines (34 loc) · 1.03 KB
/
config_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Function that reads a configuration file, which has the structure consisting of
* pairs of format <name>sep<value>, where sep is the separator string e.g. =,
* and reads them into a map with <name> acting as the key
* and <value> acting as the associated value.
*
* Empty lines and white space is removed before processing. Also, text on the right of
* and including the symbol # are considered as comments.
*
*/
#ifndef CONFIG_PARSER_H
#define CONFIG_PARSER_H
#include <string>
#include <complex>
#include <vector>
#include <fstream>
#include <map>
using namespace std;
// Input:
// const_string& file_path: path to the configuration file
// const string& sep: the separator string, default being =
// Output:
// a map of <name>, <value> pairs.
//
// Example: if a input file example.cfg consists of the content
//
// # Two variables
//
// a = 1.0
// b = var
//
// The resulting map consits of pairs {"a","1.0"} and {"b","var"}.
map<string,string> load_config_file(const string& file_path, const string& sep = "=");
#endif