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_;
return;
}
-CounterDictionary::ValueType
+const CounterDictionary::ConstIterator::value_type&
CounterDictionaryConstIteratorImpl::dereference() const {
- return (CounterDictionary::ValueType(iterator_->first,
- *(iterator_->second)));
+ return (iterator_->first);
}
bool
impl_(new CounterDictionaryConstIteratorImpl(source))
{}
-const CounterDictionary::ValueType
+const CounterDictionary::ConstIterator::value_type&
CounterDictionary::ConstIterator::dereference() const
{
return (impl_->dereference());
/// 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
/// counters to statistics module.
class ConstIterator :
public boost::iterator_facade<ConstIterator,
- const ValueType,
+ const std::string,
boost::forward_traversal_tag>
{
private:
/// \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;
};
// 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<const CounterDictionary &>(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