-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.H
66 lines (50 loc) · 1.51 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef CONFIG_H
#define CONFIG_H
#include "args.H"
#include <list>
#include <map>
/**
* @brief The configuration class
*
* Loads configuration values from an external configuration file.
* If a full path is given, uses the specific configuration file.
* If only a file name is given, searches for the specified file in the following locations:
* ~/.config/
* /etc/
*
* The configuration file has sections followed by a number of values.
* For example:
* [section1]
* value1
* value2
* [section2]
* value3
*
* Empty lines and lines starting with '#' or ';' are ignored.
* Leading and trailing whitespace in section names and values is ignored.
* Values can start with '!' making it a 'not' value.
*/
class Config
{
public:
Config(std::string const & fileName, std::string const & fullPath = std::string());
inline ~Config()
{}
/// True if the configuration is valid and can be used
inline bool valid() const
{
return _valid;
}
/// Returns values from the specified section
StringList values(std::string const & section) const;
protected:
typedef std::map<std::string, StringList> SectionsMap;
bool _valid;
SectionsMap _sections;
bool loadConfig(std::string const & fileName, std::string const & fullPath);
static std::string getLocalConfig(std::string const & fileName);
static std::string getSystemConfig(std::string const & fileName);
static void trim(std::string & s);
static bool isSection(std::string & s);
};
#endif // CONFIG_H