From f70875d89d0b319a4218f7989c1dbb77402b15de Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 9 Nov 2009 09:26:00 +0000 Subject: [PATCH] add some constness --- src/utils/conftree.cpp | 11 ++++++----- src/utils/conftree.h | 28 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/utils/conftree.cpp b/src/utils/conftree.cpp index dd7f27e3..4337e231 100755 --- a/src/utils/conftree.cpp +++ b/src/utils/conftree.cpp @@ -198,7 +198,7 @@ ConfSimple::ConfSimple(const char *fname, int readonly, bool tildexp) parseinput(input); } -ConfSimple::StatusCode ConfSimple::getStatus() +ConfSimple::StatusCode ConfSimple::getStatus() const { switch (status) { case STATUS_RO: return STATUS_RO; @@ -207,18 +207,18 @@ ConfSimple::StatusCode ConfSimple::getStatus() } } -int ConfSimple::get(const string &nm, string &value, const string &sk) +int ConfSimple::get(const string &nm, string &value, const string &sk) const { if (!ok()) return 0; // Find submap - map >::iterator ss; + map >::const_iterator ss; if ((ss = m_submaps.find(sk)) == m_submaps.end()) return 0; // Find named value - map::iterator s; + map::const_iterator s; if ((s = ss->second.find(nm)) == ss->second.end()) return 0; value = s->second; @@ -442,7 +442,7 @@ bool ConfSimple::write() // Write out the tree in configuration file format: // This does not check holdWrites, this is done by write(void), which // lets ie: listall work even when holdWrites is set -bool ConfSimple::write(ostream& out) +bool ConfSimple::write(ostream& out) const { if (!ok()) return false; @@ -546,6 +546,7 @@ bool ConfSimple::hasNameAnywhere(const string& nm) // ////////////////////////////////////////////////////////////////////////// int ConfTree::get(const std::string &name, string &value, const string &sk) + const { if (sk.empty() || sk[0] != '/') { // LOGDEB((stderr, "ConfTree::get: looking in global space\n")); diff --git a/src/utils/conftree.h b/src/utils/conftree.h index dda0df1e..8c77d425 100755 --- a/src/utils/conftree.h +++ b/src/utils/conftree.h @@ -95,11 +95,11 @@ public: enum StatusCode {STATUS_ERROR=0, STATUS_RO=1, STATUS_RW=2}; virtual ~ConfNull() {}; virtual int get(const string &name, string &value, - const string &sk = string()) = 0; + const string &sk = string()) const = 0; virtual bool hasNameAnywhere(const string& nm) = 0; virtual int set(const string &nm, const string &val, const string &sk = string()) = 0; - virtual bool ok() = 0; + virtual bool ok() const = 0; virtual list getNames(const string &sk, const char* = 0) = 0; virtual int erase(const string &, const string &) = 0; virtual int eraseKey(const string &) = 0; @@ -157,7 +157,8 @@ public: * global space if sk is empty). * @return 0 if name not found, 1 else */ - virtual int get(const string &name, string &value, const string &sk = string()); + virtual int get(const string &name, string &value, + const string &sk = string()) const; /** * Set value for named parameter in specified subsection (or global) @@ -175,8 +176,8 @@ public: */ virtual int eraseKey(const string &sk); - virtual StatusCode getStatus(); - virtual bool ok() {return getStatus() != STATUS_ERROR;} + virtual StatusCode getStatus() const; + virtual bool ok() const {return getStatus() != STATUS_ERROR;} /** * Walk the configuration values, calling function for each. @@ -232,6 +233,11 @@ public: return *this; } + /** + * Write in file format to out + */ + bool write(ostream& out) const; + protected: bool dotildexpand; StatusCode status; @@ -250,7 +256,6 @@ private: void parseinput(istream& input); bool write(); - bool write(ostream& out); // Internal version of set: no RW checking virtual int i_set(const string &nm, const string &val, const string &sk, bool init = false); @@ -296,7 +301,7 @@ public: * parents. * @return 0 if name not found, 1 else */ - virtual int get(const string &name, string &value, const string &sk); + virtual int get(const string &name, string &value, const string &sk) const; }; /** @@ -353,9 +358,9 @@ public: return *this; } - virtual int get(const string &name, string &value, const string &sk) + virtual int get(const string &name, string &value, const string &sk) const { - typename list::iterator it; + typename list::const_iterator it; for (it = m_confs.begin();it != m_confs.end();it++) { if ((*it)->get(name, value, sk)) return true; @@ -373,7 +378,8 @@ public: return false; } - virtual int set(const string &nm, const string &val, const string &sk = string()) + virtual int set(const string &nm, const string &val, + const string &sk = string()) { if (!m_ok) return 0; @@ -443,7 +449,7 @@ public: return sks; } - virtual bool ok() {return m_ok;} + virtual bool ok() const {return m_ok;} private: bool m_ok;