Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:36

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    typedef typename MapConfig::char_type                       char_type;
0055    typedef typename MapConfig::template
0056       intrusive_value_type<derivation_hook>::type              value_type;
0057 
0058    typedef typename MapConfig::compare_key_type                compare_key_type;
0059 
0060    struct less_function
0061    {
0062       bool operator()(const compare_key_type&i, const value_type &b) const
0063       {
0064          std::size_t blen = b.name_length();
0065          return (i.m_len < blen) ||
0066                   (i.m_len == blen &&
0067                   std::char_traits<char_type>::compare
0068                      (i.mp_str, b.name(), i.m_len) < 0);
0069       }
0070 
0071       bool operator()(const value_type &b, const compare_key_type&i) const
0072       {
0073          std::size_t blen = b.name_length();
0074          return (blen < i.m_len) ||
0075                   (blen == i.m_len &&
0076                   std::char_traits<char_type>::compare
0077                      (b.name(), i.mp_str, i.m_len) < 0);
0078       }
0079 
0080       bool operator()(const value_type& a, const value_type& b) const
0081       {
0082          std::size_t alen = a.name_length();
0083          std::size_t blen = b.name_length();
0084          return (alen < blen) ||
0085             (alen == blen &&
0086                std::char_traits<char_type>::compare
0087                (a.name(), b.name(), alen) < 0);
0088       }
0089    };
0090 
0091    typedef std::less<value_type>                               value_compare;
0092    typedef typename bi::make_set
0093       < value_type
0094       , bi::base_hook<derivation_hook>
0095       , bi::compare<less_function>
0096       >::type                                                  index_t;
0097 };
0098 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0099 
0100 //!Index type based in boost::intrusive::set.
0101 //!Just derives from boost::intrusive::set
0102 //!and defines the interface needed by managed memory segments*/
0103 template <class MapConfig>
0104 class iset_index
0105    //Derive class from map specialization
0106    :  private iset_index_aux<MapConfig>::index_t
0107 {
0108    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0109    typedef iset_index_aux<MapConfig>                     index_aux;
0110    typedef typename index_aux::index_t                   index_type;
0111    typedef typename MapConfig::char_type                 char_type;
0112    typedef typename index_aux::less_function             less_function;
0113    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0114 
0115    public:
0116    typedef typename index_type::iterator                 iterator;
0117    typedef typename index_type::const_iterator           const_iterator;
0118    typedef typename index_type::insert_commit_data       insert_commit_data;
0119    typedef typename index_type::value_type               value_type;
0120    typedef typename MapConfig::compare_key_type          compare_key_type;
0121    typedef value_type                                    index_data_t;
0122 
0123    public:
0124 
0125    using index_type::begin;
0126    using index_type::end;
0127    using index_type::size;
0128    using index_type::erase;
0129 
0130    //!Constructor. Takes a pointer to the
0131    //!segment manager. Can throw
0132    iset_index(typename MapConfig::segment_manager_base *)
0133       : index_type(/*typename index_aux::value_compare()*/)
0134    {}
0135 
0136    //!This reserves memory to optimize the insertion of n
0137    //!elements in the index
0138    void reserve(typename MapConfig::segment_manager_base::size_type)
0139    {  /*Does nothing, map has not reserve or rehash*/  }
0140 
0141    //!This frees all unnecessary memory
0142    void shrink_to_fit()
0143    {  /*Does nothing, this intrusive index does not allocate memory;*/   }
0144 
0145    iterator find(const compare_key_type&key)
0146    {  return index_type::find(key, less_function());  }
0147 
0148    const_iterator find(const compare_key_type&key) const
0149    {  return index_type::find(key, less_function());  }
0150 
0151    std::pair<iterator, bool>insert_check
0152       (const compare_key_type &key, insert_commit_data &commit_data)
0153    {  return index_type::insert_check(key, less_function(), commit_data); }
0154 
0155    iterator insert_commit
0156       (const compare_key_type &, void*, index_data_t&v, insert_commit_data& commit_data)
0157    {  return index_type::insert_commit(v, commit_data);  }
0158 };
0159 
0160 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0161 
0162 //!Trait class to detect if an index is an intrusive
0163 //!index.
0164 template<class MapConfig>
0165 struct is_intrusive_index
0166    <boost::interprocess::iset_index<MapConfig> >
0167 {
0168    static const bool value = true;
0169 };
0170 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0171 
0172 }  //namespace interprocess {
0173 }  //namespace boost
0174 
0175 #include <boost/interprocess/detail/config_end.hpp>
0176 
0177 #endif   //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP