blob: 6d80887d4d0a56cadd29f01cfb39a621292b85c7 [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_CORE_MAP_VALUE_ITERATOR_H
8#define NFD_CORE_MAP_VALUE_ITERATOR_H
9
10#include "common.hpp"
11#include <boost/iterator/transform_iterator.hpp>
12
13namespace nfd {
14
15/** \class MapValueIterator
16 * \brief ForwardIterator to iterator over map values
17 */
18template<typename Map>
19class MapValueIterator
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070020 : public boost::transform_iterator<
21 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
22 typename Map::const_iterator>
Junxiao Shia4f2be82014-03-02 22:56:41 -070023{
24public:
25 explicit
26 MapValueIterator(typename Map::const_iterator it)
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070027 : boost::transform_iterator<
28 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
Junxiao Shia4f2be82014-03-02 22:56:41 -070029 typename Map::const_iterator>(it, &takeSecond)
30 {
31 }
32
33private:
34 static const typename Map::mapped_type&
35 takeSecond(const typename Map::value_type& pair)
36 {
37 return pair.second;
38 }
39};
40
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070041/** \class MapValueReverseIterator
42 * \brief ReverseIterator to iterator over map values
43 */
44template<typename Map>
45class MapValueReverseIterator
46 : public boost::transform_iterator<
47 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
48 typename Map::const_reverse_iterator>
49{
50public:
51 explicit
52 MapValueReverseIterator(typename Map::const_reverse_iterator it)
53 : boost::transform_iterator<
54 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
55 typename Map::const_reverse_iterator>(it, &takeSecond)
56 {
57 }
58
59private:
60 static const typename Map::mapped_type&
61 takeSecond(const typename Map::value_type& pair)
62 {
63 return pair.second;
64 }
65};
66
Junxiao Shia4f2be82014-03-02 22:56:41 -070067} // namespace nfd
68
69#endif // NFD_CORE_MAP_VALUE_ITERATOR_H