-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconffile.h
119 lines (83 loc) · 2.54 KB
/
conffile.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
////////////////////////////////////////////////////////////////////////////////////////
//
// humifand - the humidity fan deamon
//
// Please check www.way2.net for more information
//
// (c) Copyright 2014 by way2.net Services.
//
////////////////////////////////////////////////////////////////////////////////////////
#ifndef CONFFILE_H
#define CONFFILE_H
////////////////////////////////////////////////////////////////////////////////////////
#include <map>
#include <string>
#include <algorithm>
#include <functional>
////////////////////////////////////////////////////////////////////////////////////////
// trim from start
static inline std::string <rim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
static inline std::string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
}
// trim from both ends
static inline std::string &trim(std::string &s) {
return ltrim(rtrim(s));
}
////////////////////////////////////////////////////////////////////////////////////////
#define CONF ConfFile::getConfFile()
////////////////////////////////////////////////////////////////////////////////////////
class ConfFile
{
public:
// --- config file reader
int processConfigFile(const char *f_cfpath);
// --- command line accessors
void coSetVerbose(bool f_d)
{
m_VerboseMode = f_d;
}
bool coGetVerbose(void)
{
return m_VerboseMode;
}
void coSetDaemonMode(bool f_d)
{
m_DaemonMode = f_d;
}
bool coGetDaemonMode(void)
{
return m_DaemonMode;
}
// --- options accessors
void Clear(void);
std::string GetOption(const char *f_key);
int GetOptionInt(const char *f_key);
int GetOptionIntDefault(const char *f_key,int f_default);
float GetOptionFloat(const char *f_key);
float GetOptionFloatDefault(const char *f_key,float f_default);
bool isValid(const char *f_key);
// --- debugging
void PrintConfMap(void);
// --- singleton accessor
static ConfFile* getConfFile();
private:
ConfFile();
ConfFile( const ConfFile&){};
ConfFile& operator=(const ConfFile& )
{
return *this;
};
static ConfFile* m_pThis;
typedef std::map < std::string, std::string > StringStringMap;
StringStringMap myMap;
bool m_VerboseMode;
bool m_DaemonMode;
};
////////////////////////////////////////////////////////////////////////////////////////
#endif