Also in this commit: implementing const_reverse_iterator in FaceTable. It also would be good to have reverse iterator in Fib, but not strictly necessary. Change-Id: Ie9cf849b718f5db76db2957b4452790f9ae68fd3 Refs: #1378
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (C) 2014 Named Data Networking Project
|
|
* See COPYING for copyright and distribution information.
|
|
*/
|
|
|
|
#ifndef NFD_CORE_MAP_VALUE_ITERATOR_H
|
|
#define NFD_CORE_MAP_VALUE_ITERATOR_H
|
|
|
|
#include "common.hpp"
|
|
#include <boost/iterator/transform_iterator.hpp>
|
|
|
|
namespace nfd {
|
|
|
|
/** \class MapValueIterator
|
|
* \brief ForwardIterator to iterator over map values
|
|
*/
|
|
template<typename Map>
|
|
class MapValueIterator
|
|
: public boost::transform_iterator<
|
|
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
|
typename Map::const_iterator>
|
|
{
|
|
public:
|
|
explicit
|
|
MapValueIterator(typename Map::const_iterator it)
|
|
: boost::transform_iterator<
|
|
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
|
typename Map::const_iterator>(it, &takeSecond)
|
|
{
|
|
}
|
|
|
|
private:
|
|
static const typename Map::mapped_type&
|
|
takeSecond(const typename Map::value_type& pair)
|
|
{
|
|
return pair.second;
|
|
}
|
|
};
|
|
|
|
/** \class MapValueReverseIterator
|
|
* \brief ReverseIterator to iterator over map values
|
|
*/
|
|
template<typename Map>
|
|
class MapValueReverseIterator
|
|
: public boost::transform_iterator<
|
|
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
|
typename Map::const_reverse_iterator>
|
|
{
|
|
public:
|
|
explicit
|
|
MapValueReverseIterator(typename Map::const_reverse_iterator it)
|
|
: boost::transform_iterator<
|
|
function<const typename Map::mapped_type&(const typename Map::value_type&)>,
|
|
typename Map::const_reverse_iterator>(it, &takeSecond)
|
|
{
|
|
}
|
|
|
|
private:
|
|
static const typename Map::mapped_type&
|
|
takeSecond(const typename Map::value_type& pair)
|
|
{
|
|
return pair.second;
|
|
}
|
|
};
|
|
|
|
} // namespace nfd
|
|
|
|
#endif // NFD_CORE_MAP_VALUE_ITERATOR_H
|