|
a/src/utils/conftree.h |
|
b/src/utils/conftree.h |
|
... |
|
... |
95 |
public:
|
95 |
public:
|
96 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
96 |
enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2};
|
97 |
virtual ~ConfNull() {};
|
97 |
virtual ~ConfNull() {};
|
98 |
virtual int get(const string &name, string &value,
|
98 |
virtual int get(const string &name, string &value,
|
99 |
const string &sk = string()) const = 0;
|
99 |
const string &sk = string()) const = 0;
|
100 |
virtual bool hasNameAnywhere(const string& nm) = 0;
|
100 |
virtual bool hasNameAnywhere(const string& nm) const = 0;
|
101 |
virtual int set(const string &nm, const string &val,
|
101 |
virtual int set(const string &nm, const string &val,
|
102 |
const string &sk = string()) = 0;
|
102 |
const string &sk = string()) = 0;
|
103 |
virtual bool ok() const = 0;
|
103 |
virtual bool ok() const = 0;
|
104 |
virtual vector<string> getNames(const string &sk, const char* = 0) = 0;
|
104 |
virtual vector<string> getNames(const string &sk, const char* = 0)const = 0;
|
105 |
virtual int erase(const string &, const string &) = 0;
|
105 |
virtual int erase(const string &, const string &) = 0;
|
106 |
virtual int eraseKey(const string &) = 0;
|
106 |
virtual int eraseKey(const string &) = 0;
|
107 |
virtual void showall() {};
|
107 |
virtual void showall() const {};
|
108 |
virtual vector<string> getSubKeys() = 0;
|
108 |
virtual vector<string> getSubKeys() const = 0;
|
109 |
virtual vector<string> getSubKeys(bool) = 0;
|
109 |
virtual vector<string> getSubKeys(bool) const = 0;
|
110 |
virtual bool holdWrites(bool) = 0;
|
110 |
virtual bool holdWrites(bool) = 0;
|
111 |
virtual bool sourceChanged() = 0;
|
111 |
virtual bool sourceChanged() const = 0;
|
112 |
};
|
112 |
};
|
113 |
|
113 |
|
114 |
/**
|
114 |
/**
|
115 |
* Manages a simple configuration file with subsections.
|
115 |
* Manages a simple configuration file with subsections.
|
116 |
*/
|
116 |
*/
|
|
... |
|
... |
141 |
ConfSimple(int readonly = 0, bool tildexp = false);
|
141 |
ConfSimple(int readonly = 0, bool tildexp = false);
|
142 |
|
142 |
|
143 |
virtual ~ConfSimple() {};
|
143 |
virtual ~ConfSimple() {};
|
144 |
|
144 |
|
145 |
/** Origin file changed. Only makes sense if we read the data from a file */
|
145 |
/** Origin file changed. Only makes sense if we read the data from a file */
|
146 |
virtual bool sourceChanged();
|
146 |
virtual bool sourceChanged() const;
|
147 |
|
147 |
|
148 |
/**
|
148 |
/**
|
149 |
* Decide if we actually rewrite the backing-store after modifying the
|
149 |
* Decide if we actually rewrite the backing-store after modifying the
|
150 |
* tree.
|
150 |
* tree.
|
151 |
*/
|
151 |
*/
|
|
... |
|
... |
195 |
*/
|
195 |
*/
|
196 |
enum WalkerCode {WALK_STOP, WALK_CONTINUE};
|
196 |
enum WalkerCode {WALK_STOP, WALK_CONTINUE};
|
197 |
virtual WalkerCode sortwalk(WalkerCode
|
197 |
virtual WalkerCode sortwalk(WalkerCode
|
198 |
(*wlkr)(void *cldata, const string &nm,
|
198 |
(*wlkr)(void *cldata, const string &nm,
|
199 |
const string &val),
|
199 |
const string &val),
|
200 |
void *clidata);
|
200 |
void *clidata) const;
|
201 |
|
201 |
|
202 |
/** Print all values to stdout */
|
202 |
/** Print all values to stdout */
|
203 |
virtual void showall();
|
203 |
virtual void showall() const;
|
204 |
|
204 |
|
205 |
/** Return all names in given submap. */
|
205 |
/** Return all names in given submap. */
|
206 |
virtual vector<string> getNames(const string &sk, const char *pattern = 0);
|
206 |
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
|
|
207 |
const;
|
207 |
|
208 |
|
208 |
/** Check if name is present in any submap. This is relatively expensive
|
209 |
/** Check if name is present in any submap. This is relatively expensive
|
209 |
* but useful for saving further processing sometimes */
|
210 |
* but useful for saving further processing sometimes */
|
210 |
virtual bool hasNameAnywhere(const string& nm);
|
211 |
virtual bool hasNameAnywhere(const string& nm) const;
|
211 |
|
212 |
|
212 |
/**
|
213 |
/**
|
213 |
* Return all subkeys
|
214 |
* Return all subkeys
|
214 |
*/
|
215 |
*/
|
215 |
virtual vector<string> getSubKeys(bool) {return getSubKeys();}
|
216 |
virtual vector<string> getSubKeys(bool) const
|
|
|
217 |
{
|
|
|
218 |
return getSubKeys();
|
|
|
219 |
}
|
216 |
virtual vector<string> getSubKeys();
|
220 |
virtual vector<string> getSubKeys() const;
|
217 |
/** Test for subkey existence */
|
221 |
/** Test for subkey existence */
|
218 |
virtual bool hasSubKey(const string& sk)
|
222 |
virtual bool hasSubKey(const string& sk) const
|
219 |
{
|
223 |
{
|
220 |
return m_submaps.find(sk) != m_submaps.end();
|
224 |
return m_submaps.find(sk) != m_submaps.end();
|
221 |
}
|
225 |
}
|
222 |
|
226 |
|
223 |
virtual string getFilename() {return m_filename;}
|
227 |
virtual string getFilename() const
|
|
|
228 |
{return m_filename;}
|
224 |
|
229 |
|
225 |
/**
|
230 |
/**
|
226 |
* Copy constructor. Expensive but less so than a full rebuild
|
231 |
* Copy constructor. Expensive but less so than a full rebuild
|
227 |
*/
|
232 |
*/
|
228 |
ConfSimple(const ConfSimple &rhs)
|
233 |
ConfSimple(const ConfSimple &rhs)
|
|
... |
|
... |
304 |
: ConfSimple(data, readonly, true) {}
|
309 |
: ConfSimple(data, readonly, true) {}
|
305 |
ConfTree(int readonly = 0)
|
310 |
ConfTree(int readonly = 0)
|
306 |
: ConfSimple(readonly, true) {}
|
311 |
: ConfSimple(readonly, true) {}
|
307 |
virtual ~ConfTree() {};
|
312 |
virtual ~ConfTree() {};
|
308 |
ConfTree(const ConfTree& r) : ConfSimple(r) {};
|
313 |
ConfTree(const ConfTree& r) : ConfSimple(r) {};
|
309 |
ConfTree& operator=(const ConfTree& r) {
|
314 |
ConfTree& operator=(const ConfTree& r)
|
|
|
315 |
{
|
310 |
ConfSimple::operator=(r);
|
316 |
ConfSimple::operator=(r);
|
311 |
return *this;
|
317 |
return *this;
|
312 |
}
|
318 |
}
|
313 |
|
319 |
|
314 |
/**
|
320 |
/**
|
|
... |
|
... |
371 |
init_from(rhs);
|
377 |
init_from(rhs);
|
372 |
}
|
378 |
}
|
373 |
return *this;
|
379 |
return *this;
|
374 |
}
|
380 |
}
|
375 |
|
381 |
|
376 |
virtual bool sourceChanged()
|
382 |
virtual bool sourceChanged() const
|
377 |
{
|
383 |
{
|
378 |
typename vector<T*>::const_iterator it;
|
384 |
typename vector<T*>::const_iterator it;
|
379 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
385 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
380 |
if ((*it)->sourceChanged())
|
386 |
if ((*it)->sourceChanged())
|
381 |
return true;
|
387 |
return true;
|
|
... |
|
... |
391 |
return true;
|
397 |
return true;
|
392 |
}
|
398 |
}
|
393 |
return false;
|
399 |
return false;
|
394 |
}
|
400 |
}
|
395 |
|
401 |
|
396 |
virtual bool hasNameAnywhere(const string& nm)
|
402 |
virtual bool hasNameAnywhere(const string& nm) const
|
397 |
{
|
403 |
{
|
398 |
typename vector<T*>::iterator it;
|
404 |
typename vector<T*>::const_iterator it;
|
399 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
405 |
for (it = m_confs.begin();it != m_confs.end();it++) {
|
400 |
if ((*it)->hasNameAnywhere(nm))
|
406 |
if ((*it)->hasNameAnywhere(nm))
|
401 |
return true;
|
407 |
return true;
|
402 |
}
|
408 |
}
|
403 |
return false;
|
409 |
return false;
|
|
... |
|
... |
446 |
{
|
452 |
{
|
447 |
return m_confs.front()->holdWrites(on);
|
453 |
return m_confs.front()->holdWrites(on);
|
448 |
}
|
454 |
}
|
449 |
|
455 |
|
450 |
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
456 |
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
|
|
457 |
const
|
451 |
{
|
458 |
{
|
452 |
return getNames1(sk, pattern, false);
|
459 |
return getNames1(sk, pattern, false);
|
453 |
}
|
460 |
}
|
454 |
virtual vector<string> getNamesShallow(const string &sk, const char *patt = 0)
|
461 |
virtual vector<string> getNamesShallow(const string &sk,
|
|
|
462 |
const char *patt = 0) const
|
455 |
{
|
463 |
{
|
456 |
return getNames1(sk, patt, true);
|
464 |
return getNames1(sk, patt, true);
|
457 |
}
|
465 |
}
|
458 |
|
466 |
|
459 |
virtual vector<string> getNames1(const string &sk, const char *pattern,
|
467 |
virtual vector<string> getNames1(const string &sk, const char *pattern,
|
460 |
bool shallow)
|
468 |
bool shallow) const
|
461 |
{
|
469 |
{
|
462 |
vector<string> nms;
|
470 |
vector<string> nms;
|
463 |
typename vector<T*>::iterator it;
|
471 |
typename vector<T*>::const_iterator it;
|
464 |
bool skfound = false;
|
472 |
bool skfound = false;
|
465 |
for (it = m_confs.begin();it != m_confs.end(); it++) {
|
473 |
for (it = m_confs.begin(); it != m_confs.end(); it++) {
|
466 |
if ((*it)->hasSubKey(sk)) {
|
474 |
if ((*it)->hasSubKey(sk)) {
|
467 |
skfound = true;
|
475 |
skfound = true;
|
468 |
vector<string> lst = (*it)->getNames(sk, pattern);
|
476 |
vector<string> lst = (*it)->getNames(sk, pattern);
|
469 |
nms.insert(nms.end(), lst.begin(), lst.end());
|
477 |
nms.insert(nms.end(), lst.begin(), lst.end());
|
470 |
}
|
478 |
}
|
|
... |
|
... |
475 |
vector<string>::iterator uit = unique(nms.begin(), nms.end());
|
483 |
vector<string>::iterator uit = unique(nms.begin(), nms.end());
|
476 |
nms.resize(uit - nms.begin());
|
484 |
nms.resize(uit - nms.begin());
|
477 |
return nms;
|
485 |
return nms;
|
478 |
}
|
486 |
}
|
479 |
|
487 |
|
480 |
virtual vector<string> getSubKeys(){return getSubKeys(false);}
|
488 |
virtual vector<string> getSubKeys() const
|
|
|
489 |
{
|
|
|
490 |
return getSubKeys(false);
|
|
|
491 |
}
|
481 |
virtual vector<string> getSubKeys(bool shallow)
|
492 |
virtual vector<string> getSubKeys(bool shallow) const
|
482 |
{
|
493 |
{
|
483 |
vector<string> sks;
|
494 |
vector<string> sks;
|
484 |
typename vector<T*>::iterator it;
|
495 |
typename vector<T*>::const_iterator it;
|
485 |
for (it = m_confs.begin();it != m_confs.end(); it++) {
|
496 |
for (it = m_confs.begin(); it != m_confs.end(); it++) {
|
486 |
vector<string> lst;
|
497 |
vector<string> lst;
|
487 |
lst = (*it)->getSubKeys();
|
498 |
lst = (*it)->getSubKeys();
|
488 |
sks.insert(sks.end(), lst.begin(), lst.end());
|
499 |
sks.insert(sks.end(), lst.begin(), lst.end());
|
489 |
if (shallow)
|
500 |
if (shallow)
|
490 |
break;
|
501 |
break;
|