|
a/src/utils/conftree.h |
|
b/src/utils/conftree.h |
|
... |
|
... |
35 |
* Manages a simple configuration file with subsections.
|
35 |
* Manages a simple configuration file with subsections.
|
36 |
*/
|
36 |
*/
|
37 |
class ConfSimple {
|
37 |
class ConfSimple {
|
38 |
public:
|
38 |
public:
|
39 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
39 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
40 |
private:
|
|
|
41 |
string filename; // set if we're working with a file
|
|
|
42 |
string *data; // set if we're working with an in-memory string
|
|
|
43 |
map<string, map<string, string> > submaps;
|
|
|
44 |
StatusCode status;
|
|
|
45 |
void parseinput(std::istream &input);
|
|
|
46 |
|
40 |
|
47 |
public:
|
|
|
48 |
/**
|
41 |
/**
|
49 |
* Build the object by reading content from file.
|
42 |
* Build the object by reading content from file.
|
|
|
43 |
* @param filename file to open
|
|
|
44 |
* @param readonly if true open readonly, else rw
|
|
|
45 |
* @param tildexp try tilde (home dir) expansion for subkey values
|
50 |
*/
|
46 |
*/
|
51 |
ConfSimple(const char *fname, int readonly = 0);
|
47 |
ConfSimple(const char *fname, int readonly = 0, bool tildexp = false);
|
52 |
|
48 |
|
53 |
/**
|
49 |
/**
|
54 |
* Build the object by reading content from a string
|
50 |
* Build the object by reading content from a string
|
|
|
51 |
* @param data points to the data to parse
|
|
|
52 |
* @param readonly if true open readonly, else rw
|
|
|
53 |
* @param tildexp try tilde (home dir) expansion for subsection names
|
55 |
*/
|
54 |
*/
|
56 |
ConfSimple(string *data, int readonly = 0);
|
55 |
ConfSimple(string *data, int readonly = 0, bool tildexp = false);
|
57 |
|
56 |
|
58 |
virtual ~ConfSimple() {};
|
57 |
virtual ~ConfSimple() {};
|
59 |
|
58 |
|
60 |
/**
|
59 |
/**
|
61 |
* Get value for named parameter, from specified subsection (looks in
|
60 |
* Get value for named parameter, from specified subsection (looks in
|
|
... |
|
... |
96 |
void list();
|
95 |
void list();
|
97 |
/**
|
96 |
/**
|
98 |
* Return all key names:
|
97 |
* Return all key names:
|
99 |
*/
|
98 |
*/
|
100 |
std::list<string> getKeys();
|
99 |
std::list<string> getKeys();
|
|
|
100 |
|
|
|
101 |
protected:
|
|
|
102 |
bool dotildexpand;
|
|
|
103 |
private:
|
|
|
104 |
string filename; // set if we're working with a file
|
|
|
105 |
string *data; // set if we're working with an in-memory string
|
|
|
106 |
map<string, map<string, string> > submaps;
|
|
|
107 |
StatusCode status;
|
|
|
108 |
void parseinput(std::istream &input);
|
101 |
};
|
109 |
};
|
102 |
|
110 |
|
103 |
/**
|
111 |
/**
|
104 |
* This is a configuration class which attaches tree-like signification to the
|
112 |
* This is a configuration class which attaches tree-like signification to the
|
105 |
* submap names.
|
113 |
* submap names.
|
|
... |
|
... |
122 |
public:
|
130 |
public:
|
123 |
/**
|
131 |
/**
|
124 |
* Build the object by reading content from file.
|
132 |
* Build the object by reading content from file.
|
125 |
*/
|
133 |
*/
|
126 |
ConfTree(const char *fname, int readonly = 0)
|
134 |
ConfTree(const char *fname, int readonly = 0)
|
127 |
: ConfSimple(fname, readonly) {}
|
135 |
: ConfSimple(fname, readonly, true) {}
|
128 |
virtual ~ConfTree() {};
|
136 |
virtual ~ConfTree() {};
|
129 |
|
137 |
|
130 |
/**
|
138 |
/**
|
131 |
* Get value for named parameter, from specified subsection, or its
|
139 |
* Get value for named parameter, from specified subsection, or its
|
132 |
* parents.
|
140 |
* parents.
|
|
... |
|
... |
145 |
*/
|
153 |
*/
|
146 |
static bool stringToStrings(const string &s, std::list<string> &tokens);
|
154 |
static bool stringToStrings(const string &s, std::list<string> &tokens);
|
147 |
static bool stringToBool(const string &s);
|
155 |
static bool stringToBool(const string &s);
|
148 |
};
|
156 |
};
|
149 |
|
157 |
|
150 |
|
|
|
151 |
#endif /*_CONFTREE_H_ */
|
158 |
#endif /*_CONFTREE_H_ */
|