Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:28

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP
0012 #define BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 #  pragma once
0020 #endif
0021 
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 
0025 #include <boost/intrusive/detail/minimal_pair_header.hpp>
0026 #include <boost/unordered_map.hpp>
0027 #include <boost/interprocess/detail/utilities.hpp>
0028 #include <boost/interprocess/allocators/private_adaptive_pool.hpp>
0029 
0030 #include <boost/intrusive/detail/minimal_pair_header.hpp>         //std::pair
0031 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>   //std::less
0032 
0033 //!\file
0034 //!Describes index adaptor of boost::unordered_map container, to use it
0035 //!as name/shared memory index
0036 
0037 namespace boost {
0038 namespace interprocess {
0039 
0040 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0041 
0042 //!Helper class to define typedefs from
0043 //!IndexTraits
0044 template <class MapConfig>
0045 struct unordered_map_index_aux
0046 {
0047    typedef typename MapConfig::key_type            key_type;
0048    typedef typename MapConfig::mapped_type         mapped_type;
0049    typedef std::equal_to<key_type>                 key_equal;
0050    typedef std::pair<const key_type, mapped_type>  value_type;
0051    typedef private_adaptive_pool
0052             <value_type,
0053                typename MapConfig::
0054                   segment_manager_base>      allocator_type;
0055     struct hasher
0056     {
0057         typedef key_type argument_type;
0058         typedef std::size_t result_type;
0059 
0060         std::size_t operator()(const key_type &val) const
0061         {
0062             typedef typename key_type::char_type    char_type;
0063             const char_type *beg = ipcdetail::to_raw_pointer(val.mp_str),
0064                             *end = beg + val.m_len;
0065             return boost::hash_range(beg, end);
0066         }
0067     };
0068    typedef unordered_map<key_type,  mapped_type, hasher,
0069                          key_equal, allocator_type>      index_t;
0070 };
0071 
0072 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0073 
0074 //!Index type based in unordered_map. Just derives from unordered_map and
0075 //!defines the interface needed by managed memory segments
0076 template <class MapConfig>
0077 class unordered_map_index
0078    //Derive class from unordered_map specialization
0079    : public unordered_map_index_aux<MapConfig>::index_t
0080 {
0081    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0082    typedef unordered_map_index_aux<MapConfig>   index_aux;
0083    typedef typename index_aux::index_t          base_type;
0084    typedef typename
0085       MapConfig::segment_manager_base     segment_manager_base;
0086    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0087 
0088    public:
0089    //!Constructor. Takes a pointer to the
0090    //!segment manager. Can throw
0091    unordered_map_index(segment_manager_base *segment_mngr)
0092       : base_type(0,
0093                   typename index_aux::hasher(),
0094                   typename index_aux::key_equal(),
0095                   segment_mngr){}
0096 
0097    //!This reserves memory to optimize the insertion of n
0098    //!elements in the index
0099    void reserve(typename segment_manager_base::size_type n)
0100    {  base_type::rehash(n);  }
0101 
0102    //!This tries to free previously allocate
0103    //!unused memory.
0104    void shrink_to_fit()
0105    {  base_type::rehash(base_type::size()); }
0106 };
0107 
0108 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0109 
0110 //!Trait class to detect if an index is a node
0111 //!index. This allows more efficient operations
0112 //!when deallocating named objects.
0113 template<class MapConfig>
0114 struct is_node_index
0115    <boost::interprocess::unordered_map_index<MapConfig> >
0116 {
0117    static const bool value = true;
0118 };
0119 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0120 
0121 }}   //namespace boost { namespace interprocess {
0122 
0123 #include <boost/interprocess/detail/config_end.hpp>
0124 
0125 #endif   //#ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP