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_ISET_INDEX_HPP
0012 #define BOOST_INTERPROCESS_ISET_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/interprocess/detail/utilities.hpp>
0027 #include <boost/intrusive/detail/minimal_pair_header.hpp>         //std::pair
0028 #include <boost/intrusive/detail/minimal_less_equal_header.hpp>   //std::less
0029 #include <boost/container/detail/minimal_char_traits_header.hpp>  //std::char_traits
0030 #include <boost/intrusive/set.hpp>
0031 
0032 //!\file
0033 //!Describes index adaptor of boost::intrusive::set container, to use it
0034 //!as name/shared memory index
0035 
0036 namespace boost {
0037 namespace interprocess {
0038 
0039 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0040 
0041 //!Helper class to define typedefs from IndexTraits
0042 template <class MapConfig>
0043 struct iset_index_aux
0044 {
0045    typedef typename
0046       MapConfig::segment_manager_base                          segment_manager_base;
0047 
0048    typedef typename
0049       segment_manager_base::void_pointer                       void_pointer;
0050    typedef typename bi::make_set_base_hook
0051       < bi::void_pointer<void_pointer>
0052       , bi::optimize_size<true>
0053       >::type                                                  derivation_hook;
0054 
0055    typedef typename MapConfig::template
0056       intrusive_value_type<derivation_hook>::type              value_type;
0057    typedef std::less<value_type>                               value_compare;
0058    typedef typename bi::make_set
0059       < value_type
0060       , bi::base_hook<derivation_hook>
0061       >::type                                                  index_t;
0062 };
0063 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0064 
0065 //!Index type based in boost::intrusive::set.
0066 //!Just derives from boost::intrusive::set
0067 //!and defines the interface needed by managed memory segments*/
0068 template <class MapConfig>
0069 class iset_index
0070    //Derive class from map specialization
0071    :  public iset_index_aux<MapConfig>::index_t
0072 {
0073    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0074    typedef iset_index_aux<MapConfig>                     index_aux;
0075    typedef typename index_aux::index_t                   index_type;
0076    typedef typename MapConfig::
0077       intrusive_compare_key_type                         intrusive_compare_key_type;
0078    typedef typename MapConfig::char_type                 char_type;
0079    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0080 
0081    public:
0082    typedef typename index_type::iterator                 iterator;
0083    typedef typename index_type::const_iterator           const_iterator;
0084    typedef typename index_type::insert_commit_data       insert_commit_data;
0085    typedef typename index_type::value_type               value_type;
0086 
0087    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0088    private:
0089 
0090    struct intrusive_key_value_less
0091    {
0092       bool operator()(const intrusive_compare_key_type &i, const value_type &b) const
0093       {
0094          std::size_t blen = b.name_length();
0095          return (i.m_len < blen) ||
0096                   (i.m_len == blen &&
0097                   std::char_traits<char_type>::compare
0098                      (i.mp_str, b.name(), i.m_len) < 0);
0099       }
0100 
0101       bool operator()(const value_type &b, const intrusive_compare_key_type &i) const
0102       {
0103          std::size_t blen = b.name_length();
0104          return (blen < i.m_len) ||
0105                   (blen == i.m_len &&
0106                   std::char_traits<char_type>::compare
0107                      (b.name(), i.mp_str, i.m_len) < 0);
0108       }
0109    };
0110 
0111    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0112 
0113    public:
0114 
0115    //!Constructor. Takes a pointer to the
0116    //!segment manager. Can throw
0117    iset_index(typename MapConfig::segment_manager_base *)
0118       : index_type(/*typename index_aux::value_compare()*/)
0119    {}
0120 
0121    //!This reserves memory to optimize the insertion of n
0122    //!elements in the index
0123    void reserve(typename MapConfig::segment_manager_base::size_type)
0124    {  /*Does nothing, map has not reserve or rehash*/  }
0125 
0126    //!This frees all unnecessary memory
0127    void shrink_to_fit()
0128    {  /*Does nothing, this intrusive index does not allocate memory;*/   }
0129 
0130    iterator find(const intrusive_compare_key_type &key)
0131    {  return index_type::find(key, intrusive_key_value_less());  }
0132 
0133    const_iterator find(const intrusive_compare_key_type &key) const
0134    {  return index_type::find(key, intrusive_key_value_less());  }
0135 
0136    std::pair<iterator, bool>insert_check
0137       (const intrusive_compare_key_type &key, insert_commit_data &commit_data)
0138    {  return index_type::insert_check(key, intrusive_key_value_less(), commit_data); }
0139 };
0140 
0141 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0142 
0143 //!Trait class to detect if an index is an intrusive
0144 //!index.
0145 template<class MapConfig>
0146 struct is_intrusive_index
0147    <boost::interprocess::iset_index<MapConfig> >
0148 {
0149    static const bool value = true;
0150 };
0151 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0152 
0153 }  //namespace interprocess {
0154 }  //namespace boost
0155 
0156 #include <boost/interprocess/detail/config_end.hpp>
0157 
0158 #endif   //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP