// Boost.Bimap // // Copyright (c) 2006-2007 Matias Capeletto // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) /// \file detail/map_view_iterator.hpp /// \brief Iterator adaptors from multi-index to bimap. #ifndef BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP #define BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP #if defined(_MSC_VER) #pragma once #endif #include // Boost #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION #include #endif // BOOST_BIMAP_DISABLE_SERIALIZATION #include #include #include // check #include #include namespace lslboost { namespace bimaps { namespace detail { /** \brief Map View Iterator adaptors from multi index to bimap. These classes are based on transform iterators from Boost.Iterator. **/ template< class Tag, class BimapCore > struct map_view_iterator ; template< class Tag, class BimapCore > struct const_map_view_iterator ; template< class Tag, class BimapCore > struct reverse_map_view_iterator ; template< class Tag, class BimapCore > struct const_reverse_map_view_iterator ; template< class Tag, class BimapCore > struct local_map_view_iterator ; template< class Tag, class BimapCore > struct const_local_map_view_iterator ; #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION /*===========================================================================*/ #define BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT \ BOOST_SERIALIZATION_SPLIT_MEMBER() \ \ friend class ::lslboost::serialization::access; \ \ template< class Archive > \ void save(Archive & ar, const unsigned int) const \ { \ ar << ::lslboost::serialization::make_nvp("mi_iterator",this->base()); \ } \ \ template< class Archive > \ void load(Archive & ar, const unsigned int) \ { \ BOOST_DEDUCED_TYPENAME base_::base_type iter; \ ar >> ::lslboost::serialization::make_nvp("mi_iterator",iter); \ this->base_reference() = iter; \ } /*===========================================================================*/ #else #define BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT // None #endif // BOOST_BIMAP_DISABLE_SERIALIZATION /*===========================================================================*/ #define BOOST_BIMAP_CORE_ITERATOR_TYPE_BY_BUILDER( METANAME, ITERATOR ) \ BOOST_BIMAP_SYMMETRIC_STATIC_ACCESS_BUILDER( METANAME, BimapCore, \ typedef BOOST_DEDUCED_TYPENAME BimapCore::core_type::BOOST_NESTED_TEMPLATE\ index \ ::type::ITERATOR type, \ typedef BOOST_DEDUCED_TYPENAME BimapCore::core_type::BOOST_NESTED_TEMPLATE\ index \ ::type::ITERATOR type \ ) /*===========================================================================*/ BOOST_BIMAP_CORE_ITERATOR_TYPE_BY_BUILDER( core_iterator_type_by , iterator ) BOOST_BIMAP_CORE_ITERATOR_TYPE_BY_BUILDER( reverse_core_iterator_type_by , reverse_iterator ) BOOST_BIMAP_CORE_ITERATOR_TYPE_BY_BUILDER( local_core_iterator_type_by , local_iterator ) // map_view_iterator template< class Tag, class BimapCore > struct map_view_iterator_adaptor { typedef iterator_adaptor< map_view_iterator, BOOST_DEDUCED_TYPENAME core_iterator_type_by::type, BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct map_view_iterator : public map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME map_view_iterator_adaptor::type base_; public: map_view_iterator() {} map_view_iterator(BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} map_view_iterator(map_view_iterator const & iter) : base_(iter.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by( *const_cast( &(*this->base()) ) ); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; template< class Tag, class BimapCore > struct const_map_view_iterator_adaptor { typedef iterator_adaptor< const_map_view_iterator, BOOST_DEDUCED_TYPENAME core_iterator_type_by::type, const BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct const_map_view_iterator : public const_map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME const_map_view_iterator_adaptor::type base_; public: const_map_view_iterator() {} const_map_view_iterator( BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} const_map_view_iterator(const_map_view_iterator const & iter) : base_(iter.base()) {} const_map_view_iterator(map_view_iterator i) : base_(i.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by(*this->base()); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; // reverse_map_view_iterator template< class Tag, class BimapCore > struct reverse_map_view_iterator_adaptor { typedef iterator_adaptor< reverse_map_view_iterator, BOOST_DEDUCED_TYPENAME reverse_core_iterator_type_by::type, BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct reverse_map_view_iterator : public reverse_map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME reverse_map_view_iterator_adaptor::type base_; public: reverse_map_view_iterator() {} reverse_map_view_iterator( BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} reverse_map_view_iterator(reverse_map_view_iterator const & iter) : base_(iter.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by( *const_cast( &(*this->base()) ) ); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; template< class Tag, class BimapCore > struct const_reverse_map_view_iterator_adaptor { typedef iterator_adaptor< const_reverse_map_view_iterator, BOOST_DEDUCED_TYPENAME reverse_core_iterator_type_by::type, const BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct const_reverse_map_view_iterator : public const_reverse_map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME const_reverse_map_view_iterator_adaptor::type base_; public: const_reverse_map_view_iterator() {} const_reverse_map_view_iterator( BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} const_reverse_map_view_iterator(const_reverse_map_view_iterator const & iter) : base_(iter.base()) {} const_reverse_map_view_iterator(reverse_map_view_iterator i) : base_(i.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by(*this->base()); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; // local_map_view_iterator template< class Tag, class BimapCore > struct local_map_view_iterator_adaptor { typedef iterator_adaptor< local_map_view_iterator, BOOST_DEDUCED_TYPENAME local_core_iterator_type_by::type, BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct local_map_view_iterator : public local_map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME local_map_view_iterator_adaptor::type base_; public: local_map_view_iterator() {} local_map_view_iterator( BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} local_map_view_iterator(local_map_view_iterator const & iter) : base_(iter.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by( *const_cast( &(*this->base()) ) ); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; template< class Tag, class BimapCore > struct const_local_map_view_iterator_adaptor { typedef iterator_adaptor< const_local_map_view_iterator, BOOST_DEDUCED_TYPENAME local_core_iterator_type_by::type, const BOOST_DEDUCED_TYPENAME ::lslboost::bimaps::support::value_type_by::type > type; }; template< class Tag, class BimapCore > struct const_local_map_view_iterator : public const_local_map_view_iterator_adaptor::type { typedef BOOST_DEDUCED_TYPENAME const_local_map_view_iterator_adaptor::type base_; public: const_local_map_view_iterator() {} const_local_map_view_iterator( BOOST_DEDUCED_TYPENAME base_::base_type const& iter) : base_(iter) {} const_local_map_view_iterator(const_local_map_view_iterator const & iter) : base_(iter.base()) {} const_local_map_view_iterator(local_map_view_iterator i) : base_(i.base()) {} BOOST_DEDUCED_TYPENAME base_::reference dereference() const { return ::lslboost::bimaps::relation::support::pair_by(*this->base()); } private: friend class iterator_core_access; BOOST_BIMAP_MAP_VIEW_ITERATOR_SERIALIZATION_SUPPORT }; #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES } // namespace detail } // namespace bimaps } // namespace lslboost #endif // BOOST_BIMAP_DETAIL_MAP_VIEW_ITERATOR_HPP