|
a/src/utils/conftree.h |
|
b/src/utils/conftree.h |
|
... |
|
... |
93 |
class ConfNull {
|
93 |
class ConfNull {
|
94 |
public:
|
94 |
public:
|
95 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
95 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
96 |
virtual ~ConfNull() {};
|
96 |
virtual ~ConfNull() {};
|
97 |
virtual int get(const string &name, string &value,
|
97 |
virtual int get(const string &name, string &value,
|
98 |
const string &sk = string()) = 0;
|
98 |
const string &sk = string()) const = 0;
|
99 |
virtual bool hasNameAnywhere(const string& nm) = 0;
|
99 |
virtual bool hasNameAnywhere(const string& nm) = 0;
|
100 |
virtual int set(const string &nm, const string &val,
|
100 |
virtual int set(const string &nm, const string &val,
|
101 |
const string &sk = string()) = 0;
|
101 |
const string &sk = string()) = 0;
|
102 |
virtual bool ok() = 0;
|
102 |
virtual bool ok() const = 0;
|
103 |
virtual list<string> getNames(const string &sk, const char* = 0) = 0;
|
103 |
virtual list<string> getNames(const string &sk, const char* = 0) = 0;
|
104 |
virtual int erase(const string &, const string &) = 0;
|
104 |
virtual int erase(const string &, const string &) = 0;
|
105 |
virtual int eraseKey(const string &) = 0;
|
105 |
virtual int eraseKey(const string &) = 0;
|
106 |
virtual void listall() {};
|
106 |
virtual void listall() {};
|
107 |
virtual list<string> getSubKeys() = 0;
|
107 |
virtual list<string> getSubKeys() = 0;
|
|
... |
|
... |
155 |
/**
|
155 |
/**
|
156 |
* Get value for named parameter, from specified subsection (looks in
|
156 |
* Get value for named parameter, from specified subsection (looks in
|
157 |
* global space if sk is empty).
|
157 |
* global space if sk is empty).
|
158 |
* @return 0 if name not found, 1 else
|
158 |
* @return 0 if name not found, 1 else
|
159 |
*/
|
159 |
*/
|
160 |
virtual int get(const string &name, string &value, const string &sk = string());
|
160 |
virtual int get(const string &name, string &value,
|
|
|
161 |
const string &sk = string()) const;
|
161 |
|
162 |
|
162 |
/**
|
163 |
/**
|
163 |
* Set value for named parameter in specified subsection (or global)
|
164 |
* Set value for named parameter in specified subsection (or global)
|
164 |
* @return 0 for error, 1 else
|
165 |
* @return 0 for error, 1 else
|
165 |
*/
|
166 |
*/
|
|
... |
|
... |
173 |
/**
|
174 |
/**
|
174 |
* Erase all names under given subkey (and subkey itself)
|
175 |
* Erase all names under given subkey (and subkey itself)
|
175 |
*/
|
176 |
*/
|
176 |
virtual int eraseKey(const string &sk);
|
177 |
virtual int eraseKey(const string &sk);
|
177 |
|
178 |
|
178 |
virtual StatusCode getStatus();
|
179 |
virtual StatusCode getStatus() const;
|
179 |
virtual bool ok() {return getStatus() != STATUS_ERROR;}
|
180 |
virtual bool ok() const {return getStatus() != STATUS_ERROR;}
|
180 |
|
181 |
|
181 |
/**
|
182 |
/**
|
182 |
* Walk the configuration values, calling function for each.
|
183 |
* Walk the configuration values, calling function for each.
|
183 |
* The function is called with a null nm when changing subsections (the
|
184 |
* The function is called with a null nm when changing subsections (the
|
184 |
* value is then the new subsection name)
|
185 |
* value is then the new subsection name)
|
|
... |
|
... |
229 |
m_filename = rhs.m_filename;
|
230 |
m_filename = rhs.m_filename;
|
230 |
m_submaps = rhs.m_submaps;
|
231 |
m_submaps = rhs.m_submaps;
|
231 |
}
|
232 |
}
|
232 |
return *this;
|
233 |
return *this;
|
233 |
}
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Write in file format to out
|
|
|
238 |
*/
|
|
|
239 |
bool write(ostream& out) const;
|
234 |
|
240 |
|
235 |
protected:
|
241 |
protected:
|
236 |
bool dotildexpand;
|
242 |
bool dotildexpand;
|
237 |
StatusCode status;
|
243 |
StatusCode status;
|
238 |
private:
|
244 |
private:
|
|
... |
|
... |
248 |
// Control if we're writing to the backing store
|
254 |
// Control if we're writing to the backing store
|
249 |
bool m_holdWrites;
|
255 |
bool m_holdWrites;
|
250 |
|
256 |
|
251 |
void parseinput(istream& input);
|
257 |
void parseinput(istream& input);
|
252 |
bool write();
|
258 |
bool write();
|
253 |
bool write(ostream& out);
|
|
|
254 |
// Internal version of set: no RW checking
|
259 |
// Internal version of set: no RW checking
|
255 |
virtual int i_set(const string &nm, const string &val,
|
260 |
virtual int i_set(const string &nm, const string &val,
|
256 |
const string &sk, bool init = false);
|
261 |
const string &sk, bool init = false);
|
257 |
};
|
262 |
};
|
258 |
|
263 |
|
|
... |
|
... |
294 |
/**
|
299 |
/**
|
295 |
* Get value for named parameter, from specified subsection, or its
|
300 |
* Get value for named parameter, from specified subsection, or its
|
296 |
* parents.
|
301 |
* parents.
|
297 |
* @return 0 if name not found, 1 else
|
302 |
* @return 0 if name not found, 1 else
|
298 |
*/
|
303 |
*/
|
299 |
virtual int get(const string &name, string &value, const string &sk);
|
304 |
virtual int get(const string &name, string &value, const string &sk) const;
|
300 |
};
|
305 |
};
|
301 |
|
306 |
|
302 |
/**
|
307 |
/**
|
303 |
* Use several config files, trying to get values from each in order. Used to
|
308 |
* Use several config files, trying to get values from each in order. Used to
|
304 |
* have a central config, with possible overrides from more specific
|
309 |
* have a central config, with possible overrides from more specific
|
|
... |
|
... |
351 |
init_from(rhs);
|
356 |
init_from(rhs);
|
352 |
}
|
357 |
}
|
353 |
return *this;
|
358 |
return *this;
|
354 |
}
|
359 |
}
|
355 |
|
360 |
|
356 |
virtual int get(const string &name, string &value, const string &sk)
|
361 |
virtual int get(const string &name, string &value, const string &sk) const
|
357 |
{
|
362 |
{
|
358 |
typename list<T*>::iterator it;
|
363 |
typename list<T*>::const_iterator it;
|
359 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
364 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
360 |
if ((*it)->get(name, value, sk))
|
365 |
if ((*it)->get(name, value, sk))
|
361 |
return true;
|
366 |
return true;
|
362 |
}
|
367 |
}
|
363 |
return false;
|
368 |
return false;
|
|
... |
|
... |
371 |
return true;
|
376 |
return true;
|
372 |
}
|
377 |
}
|
373 |
return false;
|
378 |
return false;
|
374 |
}
|
379 |
}
|
375 |
|
380 |
|
376 |
virtual int set(const string &nm, const string &val, const string &sk = string())
|
381 |
virtual int set(const string &nm, const string &val,
|
|
|
382 |
const string &sk = string())
|
377 |
{
|
383 |
{
|
378 |
if (!m_ok)
|
384 |
if (!m_ok)
|
379 |
return 0;
|
385 |
return 0;
|
380 |
|
386 |
|
381 |
// Avoid adding unneeded entries: if the new value matches the
|
387 |
// Avoid adding unneeded entries: if the new value matches the
|
|
... |
|
... |
441 |
sks.sort();
|
447 |
sks.sort();
|
442 |
sks.unique();
|
448 |
sks.unique();
|
443 |
return sks;
|
449 |
return sks;
|
444 |
}
|
450 |
}
|
445 |
|
451 |
|
446 |
virtual bool ok() {return m_ok;}
|
452 |
virtual bool ok() const {return m_ok;}
|
447 |
|
453 |
|
448 |
private:
|
454 |
private:
|
449 |
bool m_ok;
|
455 |
bool m_ok;
|
450 |
list<T*> m_confs;
|
456 |
list<T*> m_confs;
|
451 |
|
457 |
|