/
config_parse.hpp
60 lines (43 loc) · 1.23 KB
/
config_parse.hpp
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
/*
* config_parse.hpp
*
*
* Config Parse Header File
*
*
* Copyright (C) 2013-2015 Bryant Moscon - bmoscon@gmail.com
*
* Please see the LICENSE file for the terms and conditions
* associated with this software.
*
*/
#ifndef __CONFIG_PARSE__
#define __CONFIG_PARSE__
#include <string>
#include <unordered_map>
#include <exception>
#include <vector>
class ConfigParse {
typedef std::unordered_map<std::string, std::string> section;
public:
ConfigParse(const char *file);
ConfigParse(const std::string &file);
typedef section::const_iterator const_iterator;
const_iterator begin(const std::string §ion) const;
const_iterator end(const std::string §ion) const;
std::string get_value(const std::string §ion, const std::string &name) const;
std::vector<std::string> get_sections() const;
private:
void parse(const char *file);
std::unordered_map<std::string, section> config;
};
class ConfigParseEx : public std::exception {
public:
ConfigParseEx(const char* m);
ConfigParseEx(const std::string& m);
ConfigParseEx(const char* m, const unsigned int l);
ConfigParseEx(const std::string& m, const unsigned int l);
virtual const char* what() const throw();
std::string msg;
};
#endif