Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
b1486679
Commit
b1486679
authored
Dec 13, 2011
by
Yoshitaka Aharen
Browse files
[510] modify interface for enumerating zone names in CounterDictionary
parent
a5c94063
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/statistics/counter_dict.cc
View file @
b1486679
...
...
@@ -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
::
V
alue
T
ype
const
CounterDictionary
::
ConstIterator
::
v
alue
_t
ype
&
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
::
V
alue
T
ype
const
CounterDictionary
::
ConstIterator
::
v
alue
_t
ype
&
CounterDictionary
::
ConstIterator
::
dereference
()
const
{
return
(
impl_
->
dereference
());
...
...
src/lib/statistics/counter_dict.h
View file @
b1486679
...
...
@@ -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 element
s stored in CounterDictionary.
/// interface for
enumerating name of zone
s 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
;
};
...
...
src/lib/statistics/tests/counter_dict_unittest.cc
View file @
b1486679
...
...
@@ -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
.
nam
e
==
"sub.test"
&&
EXPECT_EQ
(
counters
[
zone
]
.
get
(
ITEM1
),
1
);
EXPECT_EQ
(
counters
[
zone
]
.
get
(
ITEM2
),
0
);
}
else
if
(
zon
e
==
"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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment