From: Tomek Mrugalski Date: Fri, 8 May 2015 14:26:52 +0000 (+0200) Subject: [3793] Several consts added. X-Git-Tag: trac3513_base~5^2~1^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef7934c8f9653f127a1eda08ac4371097aaec4f6;p=thirdparty%2Fkea.git [3793] Several consts added. --- diff --git a/src/lib/stats/context.cc b/src/lib/stats/context.cc index a4840197d1..66bb18cfd1 100644 --- a/src/lib/stats/context.cc +++ b/src/lib/stats/context.cc @@ -18,8 +18,8 @@ namespace isc { namespace stats { -ObservationPtr StatContext::get(const std::string& name) { - std::map::iterator obs = stats_.find(name); +ObservationPtr StatContext::get(const std::string& name) const { + std::map::const_iterator obs = stats_.find(name); if (obs == stats_.end()) { return (ObservationPtr()); } else { @@ -28,8 +28,8 @@ ObservationPtr StatContext::get(const std::string& name) { } void StatContext::add(const ObservationPtr& obs) { - std::map::iterator obs = stats_.find(name); - if (obs == stats_.end()) { + std::map::iterator existing = stats_.find(obs->getName()); + if (existing == stats_.end()) { stats_.insert(make_pair(obs->getName() ,obs)); } else { isc_throw(InvalidStatType, "Statistic named " << obs->getName() diff --git a/src/lib/stats/context.h b/src/lib/stats/context.h index 4506fdd3be..c9bf8c80eb 100644 --- a/src/lib/stats/context.h +++ b/src/lib/stats/context.h @@ -41,7 +41,7 @@ class StatContext { /// @brief attempts to get an observation /// @param name name of the statistic /// @return appropriate Observation object (or NULL) - ObservationPtr get(const std::string& name); + ObservationPtr get(const std::string& name) const; /// @brief Adds a new observation /// @param obs observation to be added diff --git a/src/lib/stats/observation.cc b/src/lib/stats/observation.cc index 019120200f..35d9624a96 100644 --- a/src/lib/stats/observation.cc +++ b/src/lib/stats/observation.cc @@ -84,24 +84,24 @@ void Observation::setValueInternal(SampleType value, StorageType& storage, } } -IntegerSample Observation::getInteger() { +IntegerSample Observation::getInteger() const { return (getValueInternal(integer_samples_, STAT_INTEGER)); } -FloatSample Observation::getFloat() { +FloatSample Observation::getFloat() const { return (getValueInternal(float_samples_, STAT_FLOAT)); } -DurationSample Observation::getDuration() { +DurationSample Observation::getDuration() const { return (getValueInternal(duration_samples_, STAT_DURATION)); } -StringSample Observation::getString() { +StringSample Observation::getString() const { return (getValueInternal(string_samples_, STAT_STRING)); } template -SampleType Observation::getValueInternal(Storage& storage, Type exp_type) { +SampleType Observation::getValueInternal(Storage& storage, Type exp_type) const { if (type_ != exp_type) { isc_throw(InvalidStatType, "Invalid statistic type requested: " << typeToText(exp_type) << ", but the actual type is " @@ -155,7 +155,7 @@ Observation::durationToText(StatsDuration dur) { } isc::data::ConstElementPtr -Observation::getJSON() { +Observation::getJSON() const { ElementPtr entry = isc::data::Element::createList(); // a single observation ElementPtr value; diff --git a/src/lib/stats/observation.h b/src/lib/stats/observation.h index 9328ceb3c5..f877fa0e64 100644 --- a/src/lib/stats/observation.h +++ b/src/lib/stats/observation.h @@ -183,26 +183,26 @@ class Observation { /// @brief Returns observed integer sample /// @return observed sample (value + timestamp) /// @throw InvalidStatType if statistic is not integer - IntegerSample getInteger(); + IntegerSample getInteger() const; /// @brief Returns observed float sample /// @return observed sample (value + timestamp) /// @throw InvalidStatType if statistic is not fp - FloatSample getFloat(); + FloatSample getFloat() const; /// @brief Returns observed duration sample /// @return observed sample (value + timestamp) /// @throw InvalidStatType if statistic is not time duration - DurationSample getDuration(); + DurationSample getDuration() const; /// @brief Returns observed string sample /// @return observed sample (value + timestamp) /// @throw InvalidStatType if statistic is not a string - StringSample getString(); + StringSample getString() const; /// @brief Returns as a JSON structure /// @return JSON structures representing all observations - isc::data::ConstElementPtr getJSON(); + isc::data::ConstElementPtr getJSON() const; /// @brief Converts statistic type to string /// @return textual name of statistic type @@ -217,7 +217,7 @@ class Observation { static std::string durationToText(StatsDuration dur); /// @brief Returns observation name - std::string getName() { + std::string getName() const { return (name_); } @@ -247,7 +247,7 @@ class Observation { /// @throw InvalidStatType if observation type mismatches /// @return Observed sample template - SampleType getValueInternal(Storage& storage, Type exp_type); + SampleType getValueInternal(Storage& storage, Type exp_type) const; /// @brief Observation (statistic) name std::string name_;