Debian Codegraph @

src/ConfigVar.hpp

raw
1 //Defines the ConfigVar class, which implements reading options from a file
2 //into a map
3
4 // For all support, instructions and copyright go to:
5 // http://e2guardian.org/
6 // Released under the GPL v2, with the OpenSSL exception described in the README file.
7
8 #ifndef __HPP_CONFIGVAR
9 #define __HPP_CONFIGVAR
10
11 // INCLUDES
12 #include <cstring>
13 #include <map>
14 #include "String.hpp"
15
16 // DECLARATIONS
17 class ConfigVar
18 {
19 public:
20 ConfigVar();
21
22 // read the given file, splitting option/value at the given delimiter
23 ConfigVar(const char *filename, const char *delimiter = "=");
24 int readVar(const char *filename, const char *delimiter = "=");
25
26 // return the value for the named option
27 String entry(const char *reference);
28 String operator[](const char *reference);
29
30 private:
31 // comparison operator (maps are sorted) - true if s1 comes before s2
32 struct ltstr {
33 bool operator()(String s1, String s2) const
34 {
35 return strcmp(s1.toCharArray(), s2.toCharArray()) < 0;
36 }
37 };
38
39 // the map itself - key type, value type, key comparison operator
40 std::map<String, String, ltstr> params;
41 };
42
43 #endif