Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef NFD_CORE_MAP_VALUE_ITERATOR_H |
| 26 | #define NFD_CORE_MAP_VALUE_ITERATOR_H |
| 27 | |
| 28 | #include "common.hpp" |
| 29 | #include <boost/iterator/transform_iterator.hpp> |
| 30 | |
| 31 | namespace nfd { |
| 32 | |
| 33 | /** \class MapValueIterator |
| 34 | * \brief ForwardIterator to iterator over map values |
| 35 | */ |
| 36 | template<typename Map> |
| 37 | class MapValueIterator |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 38 | : public boost::transform_iterator< |
| 39 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 40 | typename Map::const_iterator> |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 41 | { |
| 42 | public: |
| 43 | explicit |
| 44 | MapValueIterator(typename Map::const_iterator it) |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 45 | : boost::transform_iterator< |
| 46 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 47 | typename Map::const_iterator>(it, &takeSecond) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | static const typename Map::mapped_type& |
| 53 | takeSecond(const typename Map::value_type& pair) |
| 54 | { |
| 55 | return pair.second; |
| 56 | } |
| 57 | }; |
| 58 | |
Alexander Afanasyev | 7b7dfdd | 2014-03-21 13:57:54 -0700 | [diff] [blame] | 59 | /** \class MapValueReverseIterator |
| 60 | * \brief ReverseIterator to iterator over map values |
| 61 | */ |
| 62 | template<typename Map> |
| 63 | class MapValueReverseIterator |
| 64 | : public boost::transform_iterator< |
| 65 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 66 | typename Map::const_reverse_iterator> |
| 67 | { |
| 68 | public: |
| 69 | explicit |
| 70 | MapValueReverseIterator(typename Map::const_reverse_iterator it) |
| 71 | : boost::transform_iterator< |
| 72 | function<const typename Map::mapped_type&(const typename Map::value_type&)>, |
| 73 | typename Map::const_reverse_iterator>(it, &takeSecond) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | static const typename Map::mapped_type& |
| 79 | takeSecond(const typename Map::value_type& pair) |
| 80 | { |
| 81 | return pair.second; |
| 82 | } |
| 83 | }; |
| 84 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 85 | } // namespace nfd |
| 86 | |
| 87 | #endif // NFD_CORE_MAP_VALUE_ITERATOR_H |