blob: 1dfdd5c1b68e7feb21bd80f0f3c70e57cccbe9f1 [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 Shia4f2be82014-03-02 22:56:41 -070024
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
31namespace nfd {
32
33/** \class MapValueIterator
34 * \brief ForwardIterator to iterator over map values
35 */
36template<typename Map>
37class MapValueIterator
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070038 : public boost::transform_iterator<
39 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
40 typename Map::const_iterator>
Junxiao Shia4f2be82014-03-02 22:56:41 -070041{
42public:
43 explicit
44 MapValueIterator(typename Map::const_iterator it)
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070045 : boost::transform_iterator<
46 function<const typename Map::mapped_type&(const typename Map::value_type&)>,
Junxiao Shia4f2be82014-03-02 22:56:41 -070047 typename Map::const_iterator>(it, &takeSecond)
48 {
49 }
50
51private:
52 static const typename Map::mapped_type&
53 takeSecond(const typename Map::value_type& pair)
54 {
55 return pair.second;
56 }
57};
58
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070059/** \class MapValueReverseIterator
60 * \brief ReverseIterator to iterator over map values
61 */
62template<typename Map>
63class 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{
68public:
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
77private:
78 static const typename Map::mapped_type&
79 takeSecond(const typename Map::value_type& pair)
80 {
81 return pair.second;
82 }
83};
84
Junxiao Shia4f2be82014-03-02 22:56:41 -070085} // namespace nfd
86
87#endif // NFD_CORE_MAP_VALUE_ITERATOR_H