Commit b1486679 authored by Yoshitaka Aharen's avatar Yoshitaka Aharen
Browse files

[510] modify interface for enumerating zone names in CounterDictionary

parent a5c94063
......@@ -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());
......
......@@ -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<ConstIterator,
const ValueType,
const std::string,
boost::forward_traversal_tag>
{
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;
};
......
......@@ -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<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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment