Browse Source

[3793] Several consts added.

Tomek Mrugalski 10 years ago
parent
commit
ef7934c8f9
4 changed files with 18 additions and 18 deletions
  1. 4 4
      src/lib/stats/context.cc
  2. 1 1
      src/lib/stats/context.h
  3. 6 6
      src/lib/stats/observation.cc
  4. 7 7
      src/lib/stats/observation.h

+ 4 - 4
src/lib/stats/context.cc

@@ -18,8 +18,8 @@
 namespace isc {
 namespace stats {
 
-ObservationPtr StatContext::get(const std::string& name) {
-    std::map<std::string, ObservationPtr>::iterator obs = stats_.find(name);
+ObservationPtr StatContext::get(const std::string& name) const {
+    std::map<std::string, ObservationPtr>::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<std::string, ObservationPtr>::iterator obs = stats_.find(name);
-    if (obs == stats_.end()) {
+    std::map<std::string, ObservationPtr>::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()

+ 1 - 1
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

+ 6 - 6
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<IntegerSample>(integer_samples_, STAT_INTEGER));
 }
 
-FloatSample Observation::getFloat() {
+FloatSample Observation::getFloat() const {
     return (getValueInternal<FloatSample>(float_samples_, STAT_FLOAT));
 }
 
-DurationSample Observation::getDuration() {
+DurationSample Observation::getDuration() const {
     return (getValueInternal<DurationSample>(duration_samples_, STAT_DURATION));
 }
 
-StringSample Observation::getString() {
+StringSample Observation::getString() const {
     return (getValueInternal<StringSample>(string_samples_, STAT_STRING));
 }
 
 template<typename SampleType, typename Storage>
-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;

+ 7 - 7
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<typename SampleType, typename Storage>
-    SampleType getValueInternal(Storage& storage, Type exp_type);
+    SampleType getValueInternal(Storage& storage, Type exp_type) const;
 
     /// @brief Observation (statistic) name
     std::string name_;