Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | /** \class MapValueIterator |
| 16 | * \brief ForwardIterator to iterator over map values |
| 17 | */ |
| 18 | template<typename Map> |
| 19 | class MapValueIterator |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 20 | : public boost::transform_iterator< |
| 21 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 22 | typename Map::const_iterator> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 23 | { |
| 24 | public: |
| 25 | explicit |
| 26 | MapValueIterator(typename Map::const_iterator it) |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 27 | : boost::transform_iterator< |
| 28 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 29 | typename Map::const_iterator>(it, &takeSecond) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | private: |
| 34 | static const typename Map::mapped_type& |
| 35 | takeSecond(const typename Map::value_type& pair) |
| 36 | { |
| 37 | return pair.second; |
| 38 | } |
| 39 | }; |
| 40 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 41 | /** \class MapValueReverseIterator |
| 42 | * \brief ReverseIterator to iterator over map values |
| 43 | */ |
| 44 | template<typename Map> |
| 45 | class 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 | { |
| 50 | public: |
| 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 | |
| 59 | private: |
| 60 | static const typename Map::mapped_type& |
| 61 | takeSecond(const typename Map::value_type& pair) |
| 62 | { |
| 63 | return pair.second; |
| 64 | } |
| 65 | }; |
| 66 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 67 | } // namespace nfd |
| 68 | |
| 69 | #endif // NFD_CORE_MAP_VALUE_ITERATOR_H |