1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP
12 #define BOOST_INTERPROCESS_ISET_INDEX_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/intrusive/detail/minimal_pair_header.hpp>
26 #include <boost/interprocess/detail/utilities.hpp>
27 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
28 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
29 #include <boost/container/detail/minimal_char_traits_header.hpp> //std::char_traits
30 #include <boost/intrusive/set.hpp>
33 //!Describes index adaptor of boost::intrusive::set container, to use it
34 //!as name/shared memory index
37 namespace interprocess {
39 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
41 //!Helper class to define typedefs from IndexTraits
42 template <class MapConfig>
46 MapConfig::segment_manager_base segment_manager_base;
49 segment_manager_base::void_pointer void_pointer;
50 typedef typename bi::make_set_base_hook
51 < bi::void_pointer<void_pointer>
52 , bi::optimize_size<true>
53 >::type derivation_hook;
55 typedef typename MapConfig::template
56 intrusive_value_type<derivation_hook>::type value_type;
57 typedef std::less<value_type> value_compare;
58 typedef typename bi::make_set
60 , bi::base_hook<derivation_hook>
63 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
65 //!Index type based in boost::intrusive::set.
66 //!Just derives from boost::intrusive::set
67 //!and defines the interface needed by managed memory segments*/
68 template <class MapConfig>
70 //Derive class from map specialization
71 : public iset_index_aux<MapConfig>::index_t
73 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
74 typedef iset_index_aux<MapConfig> index_aux;
75 typedef typename index_aux::index_t index_type;
76 typedef typename MapConfig::
77 intrusive_compare_key_type intrusive_compare_key_type;
78 typedef typename MapConfig::char_type char_type;
79 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
82 typedef typename index_type::iterator iterator;
83 typedef typename index_type::const_iterator const_iterator;
84 typedef typename index_type::insert_commit_data insert_commit_data;
85 typedef typename index_type::value_type value_type;
87 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
90 struct intrusive_key_value_less
92 bool operator()(const intrusive_compare_key_type &i, const value_type &b) const
94 std::size_t blen = b.name_length();
95 return (i.m_len < blen) ||
97 std::char_traits<char_type>::compare
98 (i.mp_str, b.name(), i.m_len) < 0);
101 bool operator()(const value_type &b, const intrusive_compare_key_type &i) const
103 std::size_t blen = b.name_length();
104 return (blen < i.m_len) ||
106 std::char_traits<char_type>::compare
107 (b.name(), i.mp_str, i.m_len) < 0);
111 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
115 //!Constructor. Takes a pointer to the
116 //!segment manager. Can throw
117 iset_index(typename MapConfig::segment_manager_base *)
118 : index_type(/*typename index_aux::value_compare()*/)
121 //!This reserves memory to optimize the insertion of n
122 //!elements in the index
123 void reserve(typename MapConfig::segment_manager_base::size_type)
124 { /*Does nothing, map has not reserve or rehash*/ }
126 //!This frees all unnecessary memory
128 { /*Does nothing, this intrusive index does not allocate memory;*/ }
130 iterator find(const intrusive_compare_key_type &key)
131 { return index_type::find(key, intrusive_key_value_less()); }
133 const_iterator find(const intrusive_compare_key_type &key) const
134 { return index_type::find(key, intrusive_key_value_less()); }
136 std::pair<iterator, bool>insert_check
137 (const intrusive_compare_key_type &key, insert_commit_data &commit_data)
138 { return index_type::insert_check(key, intrusive_key_value_less(), commit_data); }
141 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
143 //!Trait class to detect if an index is an intrusive
145 template<class MapConfig>
146 struct is_intrusive_index
147 <boost::interprocess::iset_index<MapConfig> >
149 static const bool value = true;
151 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
153 } //namespace interprocess {
156 #include <boost/interprocess/detail/config_end.hpp>
158 #endif //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP