From: Yoshitaka Aharen Date: Tue, 13 Dec 2011 07:45:52 +0000 (+0900) Subject: [510] modify interface for enumerating zone names in CounterDictionary X-Git-Tag: trac2351_base~323^2~3^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b14866797ef758fd4e3a920b8ca9eab50053e120;p=thirdparty%2Fkea.git [510] modify interface for enumerating zone names in CounterDictionary --- diff --git a/src/lib/statistics/counter_dict.cc b/src/lib/statistics/counter_dict.cc index 8f5bc2b062..08302be813 100644 --- a/src/lib/statistics/counter_dict.cc +++ b/src/lib/statistics/counter_dict.cc @@ -127,7 +127,8 @@ class CounterDictionaryConstIteratorImpl { DictionaryMap::const_iterator iterator); public: void increment(); - CounterDictionary::ValueType dereference() const; + const CounterDictionary::ConstIterator::value_type& + dereference() const; bool equal(const CounterDictionaryConstIteratorImpl& other) const; private: DictionaryMap::const_iterator iterator_; @@ -174,10 +175,9 @@ CounterDictionaryConstIteratorImpl::increment() { return; } -CounterDictionary::ValueType +const CounterDictionary::ConstIterator::value_type& CounterDictionaryConstIteratorImpl::dereference() const { - return (CounterDictionary::ValueType(iterator_->first, - *(iterator_->second))); + return (iterator_->first); } bool @@ -226,7 +226,7 @@ CounterDictionary::ConstIterator::ConstIterator( impl_(new CounterDictionaryConstIteratorImpl(source)) {} -const CounterDictionary::ValueType +const CounterDictionary::ConstIterator::value_type& CounterDictionary::ConstIterator::dereference() const { return (impl_->dereference()); diff --git a/src/lib/statistics/counter_dict.h b/src/lib/statistics/counter_dict.h index f5c1fbda7f..4a4cab179b 100644 --- a/src/lib/statistics/counter_dict.h +++ b/src/lib/statistics/counter_dict.h @@ -62,19 +62,8 @@ public: /// Same as getElement() Counter& operator[](const std::string &name) const; - /// \brief A helper structure to represent an element of - /// CounterDictionary. This type is used for the iterator. - struct ValueType { - public: - const std::string& name; - const Counter& element; - ValueType(const std::string& name_, const Counter& element_) : - name(name_), element(element_) - {} - }; - /// \brief \c ConstIterator is a constant iterator that provides an - /// interface for accessing elements stored in CounterDictionary. + /// interface for enumerating name of zones stored in CounterDictionary. /// /// This class is derived from boost::iterator_facade and uses pImpl /// idiom not to expose implementation detail of @@ -84,7 +73,7 @@ public: /// counters to statistics module. class ConstIterator : public boost::iterator_facade { private: @@ -128,7 +117,7 @@ public: /// \brief An internal method to check equality. bool equal(const ConstIterator& other) const; /// \brief An internal method to dereference this iterator. - const value_type dereference() const; + const value_type& dereference() const; private: friend class boost::iterator_core_access; }; diff --git a/src/lib/statistics/tests/counter_dict_unittest.cc b/src/lib/statistics/tests/counter_dict_unittest.cc index d093e3dc56..34ab21912e 100644 --- a/src/lib/statistics/tests/counter_dict_unittest.cc +++ b/src/lib/statistics/tests/counter_dict_unittest.cc @@ -118,20 +118,24 @@ TEST_F(CounterDictionaryTest, iteratorTest) { // Walk through the elements with iterator // Check if the elements "test" and "sub.test" appears only once // and the counters have expected value - BOOST_FOREACH(CounterDictionary::ValueType i, - static_cast(counters)) + for (CounterDictionary::ConstIterator i = counters.begin(), + e = counters.end(); + i != e; + ++i + ) { - if (i.name == "test" && element_test_visited == false) { + const std::string& zone = *i; + if (zone == "test" && element_test_visited == false) { element_test_visited = true; // Check if the counters have expected value - EXPECT_EQ(i.element.get(ITEM1), 1); - EXPECT_EQ(i.element.get(ITEM2), 0); - } else if (i.name == "sub.test" && + EXPECT_EQ(counters[zone].get(ITEM1), 1); + EXPECT_EQ(counters[zone].get(ITEM2), 0); + } else if (zone == "sub.test" && element_sub_test_visited == false) { element_sub_test_visited = true; // Check if the counters have expected value - EXPECT_EQ(i.element.get(ITEM1), 0); - EXPECT_EQ(i.element.get(ITEM2), 2); + EXPECT_EQ(counters[zone].get(ITEM1), 0); + EXPECT_EQ(counters[zone].get(ITEM2), 2); } else { // Test fails when reaches here: the element is not expected or // the element appeared twice