-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.h
49 lines (39 loc) · 1.96 KB
/
config.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
#pragma once
#include "filedefinitions.h"
//read only config
class config
{
public:
using value_type = std::vector<std::string>; //a value consists of multiple splited values
using section_type = std::unordered_map<std::string, value_type>; //a section contains multiple key-value pairs
using config_type = std::unordered_map<std::string, section_type>; //a config contains multiple sections
config() = default;
~config() = default;
config(const std::string& filename);
//
bool load(const std::string& filename);
bool is_loaded() const;
void clear();
//
section_type operator[](const std::string& section);
section_type section(const std::string& name);
value_type value(const std::string& section, const std::string& key);
std::vector<int> value_as_int(const std::string& section, const std::string& key);
std::vector<bool> value_as_bool(const std::string& section, const std::string& key, bool def);
std::vector<double> value_as_double(const std::string& section, const std::string& key);
std::vector<std::string> value_as_strings(const std::string& section, const std::string& key);
int read_int(const std::string& section, const std::string& key, int def);
bool read_bool(const std::string& section, const std::string& key, bool def);
std::string read_string(const std::string& section, const std::string& key, std::string def);
//private:
static void trim(std::string& string, const char* filter = " \t\r\n");
static void remove_annotation(std::string& string);
static std::string split(std::string& left, char delim = '=');
static value_type split_values(const std::string& string);
static bool is_section(const std::string& string);
static bool is_empty(const std::string string);
static void convert_section_name(std::string& string);
static bool is_annotation(const std::string& string);
static bool getline(const std::string& filestring, size_t& off, std::string& result);
config_type _config;
};