Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:46:54

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