marked const conftree methods
This commit is contained in:
parent
27da60c015
commit
d2757f3bce
@ -201,9 +201,17 @@ ConfSimple::StatusCode ConfSimple::getStatus() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfSimple::sourceChanged()
|
bool ConfSimple::sourceChanged() const
|
||||||
{
|
{
|
||||||
return i_changed(false);
|
if (!m_filename.empty()) {
|
||||||
|
struct stat st;
|
||||||
|
if (stat(m_filename.c_str(), &st) == 0) {
|
||||||
|
if (m_fmtime != st.st_mtime) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfSimple::i_changed(bool upd)
|
bool ConfSimple::i_changed(bool upd)
|
||||||
@ -408,12 +416,13 @@ int ConfSimple::eraseKey(const string &sk)
|
|||||||
// Walk the tree, calling user function at each node
|
// Walk the tree, calling user function at each node
|
||||||
ConfSimple::WalkerCode
|
ConfSimple::WalkerCode
|
||||||
ConfSimple::sortwalk(WalkerCode (*walker)(void *,const string&,const string&),
|
ConfSimple::sortwalk(WalkerCode (*walker)(void *,const string&,const string&),
|
||||||
void *clidata)
|
void *clidata) const
|
||||||
{
|
{
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return WALK_STOP;
|
return WALK_STOP;
|
||||||
// For all submaps:
|
// For all submaps:
|
||||||
for (map<string, map<string, string> >::iterator sit = m_submaps.begin();
|
for (map<string, map<string, string> >::const_iterator sit =
|
||||||
|
m_submaps.begin();
|
||||||
sit != m_submaps.end(); sit++) {
|
sit != m_submaps.end(); sit++) {
|
||||||
|
|
||||||
// Possibly emit submap name:
|
// Possibly emit submap name:
|
||||||
@ -422,8 +431,8 @@ ConfSimple::sortwalk(WalkerCode (*walker)(void *,const string&,const string&),
|
|||||||
return WALK_STOP;
|
return WALK_STOP;
|
||||||
|
|
||||||
// Walk submap
|
// Walk submap
|
||||||
map<string, string> &sm = sit->second;
|
const map<string, string> &sm = sit->second;
|
||||||
for (map<string, string>::iterator it = sm.begin();it != sm.end();
|
for (map<string, string>::const_iterator it = sm.begin();it != sm.end();
|
||||||
it++) {
|
it++) {
|
||||||
if (walker(clidata, it->first, it->second) == WALK_STOP)
|
if (walker(clidata, it->first, it->second) == WALK_STOP)
|
||||||
return WALK_STOP;
|
return WALK_STOP;
|
||||||
@ -505,19 +514,19 @@ bool ConfSimple::write(ostream& out) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfSimple::showall()
|
void ConfSimple::showall() const
|
||||||
{
|
{
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return;
|
return;
|
||||||
write(std::cout);
|
write(std::cout);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> ConfSimple::getNames(const string &sk, const char *pattern)
|
vector<string> ConfSimple::getNames(const string &sk, const char *pattern) const
|
||||||
{
|
{
|
||||||
vector<string> mylist;
|
vector<string> mylist;
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return mylist;
|
return mylist;
|
||||||
map<string, map<string, string> >::iterator ss;
|
map<string, map<string, string> >::const_iterator ss;
|
||||||
if ((ss = m_submaps.find(sk)) == m_submaps.end()) {
|
if ((ss = m_submaps.find(sk)) == m_submaps.end()) {
|
||||||
return mylist;
|
return mylist;
|
||||||
}
|
}
|
||||||
@ -531,20 +540,20 @@ vector<string> ConfSimple::getNames(const string &sk, const char *pattern)
|
|||||||
return mylist;
|
return mylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> ConfSimple::getSubKeys()
|
vector<string> ConfSimple::getSubKeys() const
|
||||||
{
|
{
|
||||||
vector<string> mylist;
|
vector<string> mylist;
|
||||||
if (!ok())
|
if (!ok())
|
||||||
return mylist;
|
return mylist;
|
||||||
mylist.reserve(m_submaps.size());
|
mylist.reserve(m_submaps.size());
|
||||||
map<string, map<string, string> >::iterator ss;
|
map<string, map<string, string> >::const_iterator ss;
|
||||||
for (ss = m_submaps.begin(); ss != m_submaps.end(); ss++) {
|
for (ss = m_submaps.begin(); ss != m_submaps.end(); ss++) {
|
||||||
mylist.push_back(ss->first);
|
mylist.push_back(ss->first);
|
||||||
}
|
}
|
||||||
return mylist;
|
return mylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfSimple::hasNameAnywhere(const string& nm)
|
bool ConfSimple::hasNameAnywhere(const string& nm) const
|
||||||
{
|
{
|
||||||
vector<string>keys = getSubKeys();
|
vector<string>keys = getSubKeys();
|
||||||
for (vector<string>::const_iterator it = keys.begin();
|
for (vector<string>::const_iterator it = keys.begin();
|
||||||
|
|||||||
@ -97,18 +97,18 @@ public:
|
|||||||
virtual ~ConfNull() {};
|
virtual ~ConfNull() {};
|
||||||
virtual int get(const string &name, string &value,
|
virtual int get(const string &name, string &value,
|
||||||
const string &sk = string()) const = 0;
|
const string &sk = string()) const = 0;
|
||||||
virtual bool hasNameAnywhere(const string& nm) = 0;
|
virtual bool hasNameAnywhere(const string& nm) const = 0;
|
||||||
virtual int set(const string &nm, const string &val,
|
virtual int set(const string &nm, const string &val,
|
||||||
const string &sk = string()) = 0;
|
const string &sk = string()) = 0;
|
||||||
virtual bool ok() const = 0;
|
virtual bool ok() const = 0;
|
||||||
virtual vector<string> getNames(const string &sk, const char* = 0) = 0;
|
virtual vector<string> getNames(const string &sk, const char* = 0)const = 0;
|
||||||
virtual int erase(const string &, const string &) = 0;
|
virtual int erase(const string &, const string &) = 0;
|
||||||
virtual int eraseKey(const string &) = 0;
|
virtual int eraseKey(const string &) = 0;
|
||||||
virtual void showall() {};
|
virtual void showall() const {};
|
||||||
virtual vector<string> getSubKeys() = 0;
|
virtual vector<string> getSubKeys() const = 0;
|
||||||
virtual vector<string> getSubKeys(bool) = 0;
|
virtual vector<string> getSubKeys(bool) const = 0;
|
||||||
virtual bool holdWrites(bool) = 0;
|
virtual bool holdWrites(bool) = 0;
|
||||||
virtual bool sourceChanged() = 0;
|
virtual bool sourceChanged() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,7 +143,7 @@ public:
|
|||||||
virtual ~ConfSimple() {};
|
virtual ~ConfSimple() {};
|
||||||
|
|
||||||
/** Origin file changed. Only makes sense if we read the data from a file */
|
/** Origin file changed. Only makes sense if we read the data from a file */
|
||||||
virtual bool sourceChanged();
|
virtual bool sourceChanged() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decide if we actually rewrite the backing-store after modifying the
|
* Decide if we actually rewrite the backing-store after modifying the
|
||||||
@ -197,30 +197,35 @@ public:
|
|||||||
virtual WalkerCode sortwalk(WalkerCode
|
virtual WalkerCode sortwalk(WalkerCode
|
||||||
(*wlkr)(void *cldata, const string &nm,
|
(*wlkr)(void *cldata, const string &nm,
|
||||||
const string &val),
|
const string &val),
|
||||||
void *clidata);
|
void *clidata) const;
|
||||||
|
|
||||||
/** Print all values to stdout */
|
/** Print all values to stdout */
|
||||||
virtual void showall();
|
virtual void showall() const;
|
||||||
|
|
||||||
/** Return all names in given submap. */
|
/** Return all names in given submap. */
|
||||||
virtual vector<string> getNames(const string &sk, const char *pattern = 0);
|
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
||||||
|
const;
|
||||||
|
|
||||||
/** Check if name is present in any submap. This is relatively expensive
|
/** Check if name is present in any submap. This is relatively expensive
|
||||||
* but useful for saving further processing sometimes */
|
* but useful for saving further processing sometimes */
|
||||||
virtual bool hasNameAnywhere(const string& nm);
|
virtual bool hasNameAnywhere(const string& nm) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all subkeys
|
* Return all subkeys
|
||||||
*/
|
*/
|
||||||
virtual vector<string> getSubKeys(bool) {return getSubKeys();}
|
virtual vector<string> getSubKeys(bool) const
|
||||||
virtual vector<string> getSubKeys();
|
{
|
||||||
|
return getSubKeys();
|
||||||
|
}
|
||||||
|
virtual vector<string> getSubKeys() const;
|
||||||
/** Test for subkey existence */
|
/** Test for subkey existence */
|
||||||
virtual bool hasSubKey(const string& sk)
|
virtual bool hasSubKey(const string& sk) const
|
||||||
{
|
{
|
||||||
return m_submaps.find(sk) != m_submaps.end();
|
return m_submaps.find(sk) != m_submaps.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual string getFilename() {return m_filename;}
|
virtual string getFilename() const
|
||||||
|
{return m_filename;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor. Expensive but less so than a full rebuild
|
* Copy constructor. Expensive but less so than a full rebuild
|
||||||
@ -306,7 +311,8 @@ public:
|
|||||||
: ConfSimple(readonly, true) {}
|
: ConfSimple(readonly, true) {}
|
||||||
virtual ~ConfTree() {};
|
virtual ~ConfTree() {};
|
||||||
ConfTree(const ConfTree& r) : ConfSimple(r) {};
|
ConfTree(const ConfTree& r) : ConfSimple(r) {};
|
||||||
ConfTree& operator=(const ConfTree& r) {
|
ConfTree& operator=(const ConfTree& r)
|
||||||
|
{
|
||||||
ConfSimple::operator=(r);
|
ConfSimple::operator=(r);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -373,7 +379,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool sourceChanged()
|
virtual bool sourceChanged() const
|
||||||
{
|
{
|
||||||
typename vector<T*>::const_iterator it;
|
typename vector<T*>::const_iterator it;
|
||||||
for (it = m_confs.begin();it != m_confs.end();it++) {
|
for (it = m_confs.begin();it != m_confs.end();it++) {
|
||||||
@ -393,9 +399,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool hasNameAnywhere(const string& nm)
|
virtual bool hasNameAnywhere(const string& nm) const
|
||||||
{
|
{
|
||||||
typename vector<T*>::iterator it;
|
typename vector<T*>::const_iterator it;
|
||||||
for (it = m_confs.begin();it != m_confs.end();it++) {
|
for (it = m_confs.begin();it != m_confs.end();it++) {
|
||||||
if ((*it)->hasNameAnywhere(nm))
|
if ((*it)->hasNameAnywhere(nm))
|
||||||
return true;
|
return true;
|
||||||
@ -448,21 +454,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
virtual vector<string> getNames(const string &sk, const char *pattern = 0)
|
||||||
|
const
|
||||||
{
|
{
|
||||||
return getNames1(sk, pattern, false);
|
return getNames1(sk, pattern, false);
|
||||||
}
|
}
|
||||||
virtual vector<string> getNamesShallow(const string &sk, const char *patt = 0)
|
virtual vector<string> getNamesShallow(const string &sk,
|
||||||
|
const char *patt = 0) const
|
||||||
{
|
{
|
||||||
return getNames1(sk, patt, true);
|
return getNames1(sk, patt, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual vector<string> getNames1(const string &sk, const char *pattern,
|
virtual vector<string> getNames1(const string &sk, const char *pattern,
|
||||||
bool shallow)
|
bool shallow) const
|
||||||
{
|
{
|
||||||
vector<string> nms;
|
vector<string> nms;
|
||||||
typename vector<T*>::iterator it;
|
typename vector<T*>::const_iterator it;
|
||||||
bool skfound = false;
|
bool skfound = false;
|
||||||
for (it = m_confs.begin();it != m_confs.end(); it++) {
|
for (it = m_confs.begin(); it != m_confs.end(); it++) {
|
||||||
if ((*it)->hasSubKey(sk)) {
|
if ((*it)->hasSubKey(sk)) {
|
||||||
skfound = true;
|
skfound = true;
|
||||||
vector<string> lst = (*it)->getNames(sk, pattern);
|
vector<string> lst = (*it)->getNames(sk, pattern);
|
||||||
@ -477,12 +485,15 @@ public:
|
|||||||
return nms;
|
return nms;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual vector<string> getSubKeys(){return getSubKeys(false);}
|
virtual vector<string> getSubKeys() const
|
||||||
virtual vector<string> getSubKeys(bool shallow)
|
{
|
||||||
|
return getSubKeys(false);
|
||||||
|
}
|
||||||
|
virtual vector<string> getSubKeys(bool shallow) const
|
||||||
{
|
{
|
||||||
vector<string> sks;
|
vector<string> sks;
|
||||||
typename vector<T*>::iterator it;
|
typename vector<T*>::const_iterator it;
|
||||||
for (it = m_confs.begin();it != m_confs.end(); it++) {
|
for (it = m_confs.begin(); it != m_confs.end(); it++) {
|
||||||
vector<string> lst;
|
vector<string> lst;
|
||||||
lst = (*it)->getSubKeys();
|
lst = (*it)->getSubKeys();
|
||||||
sks.insert(sks.end(), lst.begin(), lst.end());
|
sks.insert(sks.end(), lst.begin(), lst.end());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user