-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.h
65 lines (52 loc) · 2.01 KB
/
settings.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef SETTINGS_H
#define SETTINGS_H
#include <unordered_map>
#include <string>
#include <vector>
#include <iostream>
/*** Class to read configuration settings from a text file
*
* File should contain lines like:
*
* keyword1=value1
* keyword2=value2
*
* '#' can be used for comments
*
*/
class Settings
{
private:
std::unordered_map<std::string, std::string> setting_store;
public:
/// Read settings from file
Settings(const std::string& fname);
void parse_arguments(int argc, char** argv);
/// Access value by keyword
std::string operator[](const std::string& k) const;
/// Check if a keyword exists
bool has_key(const std::string& k) const;
/// Get a value by keyword
std::string get(const std::string& k) const;
/// Get a value by keyword, converted to double
double get_double(const std::string& k) const;
/// Get a value by keyword, converted to int
int get_int(const std::string& k) const;
/// Get a value by keyword, converted to bool
bool get_bool(const std::string& k) const;
/// Get a value by keyword, converted to vector of doubles
std::vector<double> get_dv(const std::string& k) const;
/// Get a value by keyword. Return dflt if keyword is not set.
std::string get(const std::string& k, const std::string& dflt) const;
/// Get a value by keyword, converted to double. Return dflt if keyword is not set.
double get_double(const std::string& k, const double dflt) const;
/// Get a value by keyword, converted to int. Return dflt if keyword is not set.
int get_int(const std::string& k, const int dflt) const;
/// Get a value by keyword, converted to bool. Return dflt if keyword is not set.
bool get_bool(const std::string& k, const bool dflt) const;
/// Get a value by keyword, converted to vector of doubles. Return dflt if keyword is not set.
std::vector<double> get_dv(const std::string& k, const std::vector<double> dflt) const;
/// Output the current settings
friend std::ostream& operator << (std::ostream& os, const Settings& ob);
};
#endif