Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:34:08

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_MAP_INDEX_HPP
0012 #define BOOST_INTERPROCESS_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/container/map.hpp>
0027 #include <boost/interprocess/allocators/private_adaptive_pool.hpp>
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 //!\file
0032 //!Describes index adaptor of boost::map container, to use it
0033 //!as name/shared memory index
0034 
0035 namespace boost {
0036 namespace interprocess {
0037 namespace ipcdetail{
0038 
0039 //!Helper class to define typedefs from IndexTraits
0040 template <class MapConfig>
0041 struct map_index_aux
0042 {
0043    typedef typename MapConfig::key_type            key_type;
0044    typedef typename MapConfig::mapped_type         mapped_type;
0045    typedef std::less<key_type>                     key_less;
0046    typedef std::pair<const key_type, mapped_type>  value_type;
0047 
0048    typedef private_adaptive_pool
0049             <value_type,
0050                typename MapConfig::
0051          segment_manager_base>                     allocator_type;
0052 
0053    typedef boost::container::map
0054       <key_type,  mapped_type,
0055        key_less, allocator_type>                   index_t;
0056 };
0057 
0058 }  //namespace ipcdetail {
0059 
0060 //!Index type based in boost::interprocess::map. Just derives from boost::interprocess::map
0061 //!and defines the interface needed by managed memory segments
0062 template <class MapConfig>
0063 class map_index
0064    //Derive class from map specialization
0065    : private ipcdetail::map_index_aux<MapConfig>::index_t
0066 {
0067    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0068    typedef ipcdetail::map_index_aux<MapConfig>     index_aux;
0069    typedef typename index_aux::index_t             base_type;
0070    typedef typename MapConfig::
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 
0075    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0076 
0077    public:
0078    using base_type::begin;
0079    using base_type::end;
0080    using base_type::size;
0081    using base_type::erase;
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
0090    //!segment manager. Can throw
0091    map_index(segment_manager_base *segment_mngr)
0092       : base_type(typename index_aux::key_less(),
0093                   segment_mngr){}
0094 
0095    //!This reserves memory to optimize the insertion of n
0096    //!elements in the index
0097    void reserve(typename segment_manager_base::size_type)
0098       {  /*Does nothing, map has not reserve or rehash*/  }
0099 
0100    //!This tries to free previously allocate
0101    //!unused memory.
0102    void shrink_to_fit()
0103    {  base_type::get_stored_allocator().deallocate_free_blocks(); }
0104 
0105    std::pair<iterator, bool> insert_check
0106       (const compare_key_type& key, insert_commit_data& )
0107    {
0108       std::pair<iterator, bool> r;
0109       r.first = this->base_type::find(key_type(key.str(), key.len()));
0110       r.second = r.first == this->base_type::end();
0111       return r;
0112    }
0113 
0114    iterator insert_commit
0115       (const compare_key_type &k, void *context, index_data_t &index_data, insert_commit_data& )
0116    {
0117       //Now commit the insertion using previous context data
0118       iterator it = this->base_type::insert(value_type(key_type(k.str(), k.len()), mapped_type(context))).first;
0119       return (index_data = it);
0120    }
0121 
0122    iterator find(const compare_key_type& k)
0123    {  return this->base_type::find(key_type(k.str(), k.len()));   }
0124 };
0125 
0126 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0127 
0128 //!Trait class to detect if an index is a node
0129 //!index. This allows more efficient operations
0130 //!when deallocating named objects.
0131 template<class MapConfig>
0132 struct is_node_index
0133    <boost::interprocess::map_index<MapConfig> >
0134 {
0135    static const bool value = true;
0136 };
0137 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0138 
0139 }}   //namespace boost { namespace interprocess {
0140 
0141 #include <boost/interprocess/detail/config_end.hpp>
0142 
0143 #endif   //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP