Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-22 08:09:38

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 #ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
0011 #define BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
0012 
0013 #ifndef BOOST_CONFIG_HPP
0014 #  include <boost/config.hpp>
0015 #endif
0016 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 // interprocess
0026 #include <boost/container/flat_map.hpp>
0027 #include <boost/interprocess/allocators/allocator.hpp>
0028 // intrusive/detail
0029 #include <boost/intrusive/detail/minimal_pair_header.hpp>         //std::pair
0030 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>   //std::less
0031 
0032 
0033 //!\file
0034 //!Describes index adaptor of boost::map container, to use it
0035 //!as name/shared memory index
0036 
0037 //[flat_map_index
0038 namespace boost { namespace interprocess {
0039 
0040 #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0041 
0042 //!Helper class to define typedefs from IndexTraits
0043 template <class MapConfig>
0044 struct flat_map_index_aux
0045 {
0046    typedef typename MapConfig::key_type            key_type;
0047    typedef typename MapConfig::mapped_type         mapped_type;
0048    typedef typename MapConfig::
0049       segment_manager_base                   segment_manager_base;
0050    typedef std::less<key_type>                     key_less;
0051    typedef std::pair<key_type, mapped_type>        value_type;
0052    typedef allocator<value_type
0053                     ,segment_manager_base>   allocator_type;
0054    typedef boost::container::flat_map<key_type,  mapped_type,
0055                                       key_less, allocator_type>      index_t;
0056 };
0057 
0058 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0059 
0060 //!Index type based in flat_map. Just derives from flat_map and
0061 //!defines the interface needed by managed memory segments.
0062 template <class MapConfig>
0063 class flat_map_index
0064    //Derive class from flat_map specialization
0065    : private flat_map_index_aux<MapConfig>::index_t
0066 {
0067    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0068    typedef flat_map_index_aux<MapConfig>  index_aux;
0069    typedef typename index_aux::index_t    base_type;
0070    typedef typename index_aux::
0071       segment_manager_base                   segment_manager_base;
0072    typedef typename base_type::key_type      key_type;
0073    typedef typename base_type::mapped_type   mapped_type;
0074    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0075 
0076    public:
0077    using base_type::begin;
0078    using base_type::end;
0079    using base_type::size;
0080    using base_type::erase;
0081    using base_type::shrink_to_fit;
0082    using base_type::reserve;
0083    typedef typename base_type::iterator         iterator;
0084    typedef typename base_type::const_iterator   const_iterator;
0085    typedef typename base_type::value_type       value_type;
0086    typedef typename MapConfig::compare_key_type compare_key_type;
0087    typedef iterator                             insert_commit_data;
0088    typedef iterator                             index_data_t;
0089 
0090    //!Constructor. Takes a pointer to the segment manager. Can throw
0091    flat_map_index(segment_manager_base *segment_mngr)
0092       : base_type(typename index_aux::key_less(),
0093                   typename index_aux::allocator_type(segment_mngr))
0094    {}
0095 
0096    std::pair<iterator, bool> insert_check
0097       (const compare_key_type& key, insert_commit_data&)
0098    {
0099       std::pair<iterator, bool> r;
0100       r.first = this->base_type::find(key_type(key.str(), key.len()));
0101       r.second = r.first == this->base_type::end();
0102       return r;
0103    }
0104 
0105    iterator insert_commit
0106       (const compare_key_type &k, void *context, index_data_t&, insert_commit_data& )
0107    {
0108       //Now commit the insertion using previous context data
0109       return this->base_type::insert(value_type(key_type(k.str(), k.len()), mapped_type(context))).first;
0110    }
0111 
0112    iterator find(const compare_key_type& k)
0113    {  return this->base_type::find(key_type(k.str(), k.len()));   }
0114 };
0115 
0116 }}   //namespace boost { namespace interprocess
0117 //]
0118 #include <boost/interprocess/detail/config_end.hpp>
0119 
0120 #endif   //#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP