欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

map_view_base.hpp

Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
HPP
第 1 页 / 共 2 页
字号:
// 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_base.hpp/// \brief Helper base for the construction of the bimap views types.#ifndef BOOST_BIMAP_DETAIL_MAP_VIEW_BASE_HPP#define BOOST_BIMAP_DETAIL_MAP_VIEW_BASE_HPP#if defined(_MSC_VER) && (_MSC_VER>=1200)#pragma once#endif#include <boost/config.hpp>#include <stdexcept>#include <utility>#include <boost/type_traits/is_const.hpp>#include <boost/mpl/if.hpp>#include <boost/bimap/relation/support/get_pair_functor.hpp>#include <boost/bimap/relation/detail/to_mutable_relation_functor.hpp>#include <boost/bimap/container_adaptor/support/iterator_facade_converters.hpp>#include <boost/bimap/relation/support/data_extractor.hpp>#include <boost/bimap/relation/support/opposite_tag.hpp>#include <boost/bimap/relation/support/pair_type_by.hpp>#include <boost/bimap/support/iterator_type_by.hpp>#include <boost/bimap/support/key_type_by.hpp>#include <boost/bimap/support/data_type_by.hpp>#include <boost/bimap/support/value_type_by.hpp>#include <boost/bimap/detail/modifier_adaptor.hpp>#include <boost/bimap/detail/debug/static_error.hpp>namespace boost {namespace bimaps {namespace detail {// The next macro can be converted in a metafunctor to gain code robustness./*===========================================================================*/#define BOOST_BIMAP_MAP_VIEW_CONTAINER_ADAPTOR(                               \    CONTAINER_ADAPTOR, TAG,BIMAP, OTHER_ITER, CONST_OTHER_ITER                \)                                                                             \::boost::bimaps::container_adaptor::CONTAINER_ADAPTOR                         \<                                                                             \    BOOST_DEDUCED_TYPENAME BIMAP::core_type::                                 \        BOOST_NESTED_TEMPLATE index<TAG>::type,                               \    BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                         \        iterator_type_by<TAG,BIMAP>::type,                                    \    BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                         \        const_iterator_type_by<TAG,BIMAP>::type,                              \    BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                         \        OTHER_ITER<TAG,BIMAP>::type,                                          \    BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                         \        CONST_OTHER_ITER<TAG,BIMAP>::type,                                    \    ::boost::bimaps::container_adaptor::support::iterator_facade_to_base      \    <                                                                         \        BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                     \                  iterator_type_by<TAG,BIMAP>::type,                          \        BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                     \            const_iterator_type_by<TAG,BIMAP>::type                           \                                                                              \    >,                                                                        \    ::boost::mpl::na,                                                         \    ::boost::mpl::na,                                                         \    ::boost::bimaps::relation::detail::                                       \        pair_to_relation_functor<TAG,BOOST_DEDUCED_TYPENAME BIMAP::relation>, \    ::boost::bimaps::relation::support::                                      \        get_pair_functor<TAG, BOOST_DEDUCED_TYPENAME BIMAP::relation >        \>/*===========================================================================*/#if defined(BOOST_MSVC)/*===========================================================================*/#define BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(TYPE,TAG,BIMAP)                      \    typedef ::boost::bimaps::detail::map_view_base<                           \        TYPE<TAG,BIMAP>,TAG,BIMAP > friend_map_view_base;                     \    friend class friend_map_view_base;/*===========================================================================*/#else/*===========================================================================*/#define BOOST_BIMAP_MAP_VIEW_BASE_FRIEND(TYPE,TAG,BIMAP)                      \    friend class ::boost::bimaps::detail::map_view_base<                      \        TYPE<TAG,BIMAP>,TAG,BIMAP >;/*===========================================================================*/#endif/// \brief Common base for map views.template< class Derived, class Tag, class BimapType>class map_view_base{    typedef ::boost::bimaps::container_adaptor::support::        iterator_facade_to_base<            BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                iterator_type_by<Tag,BimapType>::type,            BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                const_iterator_type_by<Tag,BimapType>::type        > iterator_to_base_;    typedef ::boost::bimaps::relation::detail::        pair_to_relation_functor<Tag,            BOOST_DEDUCED_TYPENAME BimapType::relation>      value_to_base_;    typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                           key_type_by<Tag,BimapType>::type       key_type_;    typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                          data_type_by<Tag,BimapType>::type      data_type_;    typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::           pair_type_by<Tag,              BOOST_DEDUCED_TYPENAME BimapType::relation>::type value_type_;    typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                    iterator_type_by<Tag,BimapType>::type         iterator_;    public:    bool replace(iterator_ position, const value_type_ & x)    {        return derived().base().replace(            derived().template functor<iterator_to_base_>()(position),            derived().template functor<value_to_base_>()(x)        );    }    template< class CompatibleKey >    bool replace_key(iterator_ position, const CompatibleKey & k)    {        return derived().base().replace(            derived().template functor<iterator_to_base_>()(position),            derived().template functor<value_to_base_>()(                value_type_(k,position->second)            )        );    }    template< class CompatibleData >    bool replace_data(iterator_ position, const CompatibleData & d)    {        return derived().base().replace(            derived().template functor<iterator_to_base_>()(position),            derived().template functor<value_to_base_>()(                value_type_(position->first,d)            )        );    }    /* This function may be provided in the future    template< class Modifier >    bool modify(iterator_ position, Modifier mod)    {        return derived().base().modify(            derived().template functor<iterator_to_base_>()(position),            ::boost::bimaps::detail::relation_modifier_adaptor            <                Modifier,                BOOST_DEDUCED_TYPENAME BimapType::relation,                BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::                data_extractor                <                    Tag, BOOST_DEDUCED_TYPENAME BimapType::relation                >::type,                BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::                data_extractor                <                    BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::                        opossite_tag<Tag,BimapType>::type,                    BOOST_DEDUCED_TYPENAME BimapType::relation                >::type            >(mod)        );    }    */    template< class Modifier >    bool modify_key(iterator_ position, Modifier mod)    {        return derived().base().modify_key(            derived().template functor<iterator_to_base_>()(position), mod        );    }    template< class Modifier >    bool modify_data(iterator_ position, Modifier mod)    {        typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::        data_extractor        <            BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support::                        opossite_tag<Tag,BimapType>::type,            BOOST_DEDUCED_TYPENAME BimapType::relation        >::type data_extractor_;        return derived().base().modify(            derived().template functor<iterator_to_base_>()(position),            // this may be replaced later by            // ::boost::bind( mod, ::boost::bind(data_extractor_(),_1) )            ::boost::bimaps::detail::unary_modifier_adaptor            <                Modifier,                BOOST_DEDUCED_TYPENAME BimapType::relation,                data_extractor_            >(mod)        );    }    protected:    typedef map_view_base map_view_base_;    private:    // Curiously Recurring Template interface.    Derived& derived()    {        return *static_cast<Derived*>(this);    }    Derived const& derived() const    {        return *static_cast<Derived const*>(this);    }};template< class Derived, class Tag, class BimapType>class mutable_data_unique_map_view_access{    typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                          data_type_by<Tag,BimapType>::type      data_type_;    public:    template< class CompatibleKey >    data_type_ & at(const CompatibleKey& k)    {        typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::support::                            iterator_type_by<Tag,BimapType>::type iterator;        iterator iter = derived().find(k);        if( iter == derived().end() )        {            ::boost::throw_exception(                std::out_of_range("bimap<>: invalid key")            );        }        return iter->second;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -