Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/interprocess for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP
|
Chris@16
|
12 #define BOOST_INTERPROCESS_ISET_INDEX_HPP
|
Chris@16
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17 #
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
19 # pragma once
|
Chris@101
|
20 #endif
|
Chris@101
|
21
|
Chris@16
|
22 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
24
|
Chris@101
|
25 #include <boost/intrusive/detail/minimal_pair_header.hpp>
|
Chris@16
|
26 #include <boost/interprocess/detail/utilities.hpp>
|
Chris@101
|
27 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
|
Chris@101
|
28 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
|
Chris@101
|
29 #include <boost/container/detail/minimal_char_traits_header.hpp> //std::char_traits
|
Chris@16
|
30 #include <boost/intrusive/set.hpp>
|
Chris@16
|
31
|
Chris@16
|
32 //!\file
|
Chris@16
|
33 //!Describes index adaptor of boost::intrusive::set container, to use it
|
Chris@16
|
34 //!as name/shared memory index
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost {
|
Chris@16
|
37 namespace interprocess {
|
Chris@16
|
38
|
Chris@101
|
39 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
40
|
Chris@16
|
41 //!Helper class to define typedefs from IndexTraits
|
Chris@16
|
42 template <class MapConfig>
|
Chris@16
|
43 struct iset_index_aux
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef typename
|
Chris@16
|
46 MapConfig::segment_manager_base segment_manager_base;
|
Chris@16
|
47
|
Chris@16
|
48 typedef typename
|
Chris@16
|
49 segment_manager_base::void_pointer void_pointer;
|
Chris@16
|
50 typedef typename bi::make_set_base_hook
|
Chris@16
|
51 < bi::void_pointer<void_pointer>
|
Chris@16
|
52 , bi::optimize_size<true>
|
Chris@16
|
53 >::type derivation_hook;
|
Chris@16
|
54
|
Chris@16
|
55 typedef typename MapConfig::template
|
Chris@16
|
56 intrusive_value_type<derivation_hook>::type value_type;
|
Chris@16
|
57 typedef std::less<value_type> value_compare;
|
Chris@16
|
58 typedef typename bi::make_set
|
Chris@16
|
59 < value_type
|
Chris@16
|
60 , bi::base_hook<derivation_hook>
|
Chris@16
|
61 >::type index_t;
|
Chris@16
|
62 };
|
Chris@101
|
63 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
64
|
Chris@16
|
65 //!Index type based in boost::intrusive::set.
|
Chris@16
|
66 //!Just derives from boost::intrusive::set
|
Chris@16
|
67 //!and defines the interface needed by managed memory segments*/
|
Chris@16
|
68 template <class MapConfig>
|
Chris@16
|
69 class iset_index
|
Chris@16
|
70 //Derive class from map specialization
|
Chris@16
|
71 : public iset_index_aux<MapConfig>::index_t
|
Chris@16
|
72 {
|
Chris@101
|
73 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
74 typedef iset_index_aux<MapConfig> index_aux;
|
Chris@16
|
75 typedef typename index_aux::index_t index_type;
|
Chris@16
|
76 typedef typename MapConfig::
|
Chris@16
|
77 intrusive_compare_key_type intrusive_compare_key_type;
|
Chris@16
|
78 typedef typename MapConfig::char_type char_type;
|
Chris@101
|
79 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
80
|
Chris@16
|
81 public:
|
Chris@16
|
82 typedef typename index_type::iterator iterator;
|
Chris@16
|
83 typedef typename index_type::const_iterator const_iterator;
|
Chris@16
|
84 typedef typename index_type::insert_commit_data insert_commit_data;
|
Chris@16
|
85 typedef typename index_type::value_type value_type;
|
Chris@16
|
86
|
Chris@101
|
87 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
88 private:
|
Chris@16
|
89
|
Chris@16
|
90 struct intrusive_key_value_less
|
Chris@16
|
91 {
|
Chris@16
|
92 bool operator()(const intrusive_compare_key_type &i, const value_type &b) const
|
Chris@16
|
93 {
|
Chris@16
|
94 std::size_t blen = b.name_length();
|
Chris@16
|
95 return (i.m_len < blen) ||
|
Chris@16
|
96 (i.m_len == blen &&
|
Chris@16
|
97 std::char_traits<char_type>::compare
|
Chris@16
|
98 (i.mp_str, b.name(), i.m_len) < 0);
|
Chris@16
|
99 }
|
Chris@16
|
100
|
Chris@16
|
101 bool operator()(const value_type &b, const intrusive_compare_key_type &i) const
|
Chris@16
|
102 {
|
Chris@16
|
103 std::size_t blen = b.name_length();
|
Chris@16
|
104 return (blen < i.m_len) ||
|
Chris@16
|
105 (blen == i.m_len &&
|
Chris@16
|
106 std::char_traits<char_type>::compare
|
Chris@16
|
107 (b.name(), i.mp_str, i.m_len) < 0);
|
Chris@16
|
108 }
|
Chris@16
|
109 };
|
Chris@16
|
110
|
Chris@101
|
111 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
112
|
Chris@16
|
113 public:
|
Chris@16
|
114
|
Chris@16
|
115 //!Constructor. Takes a pointer to the
|
Chris@16
|
116 //!segment manager. Can throw
|
Chris@16
|
117 iset_index(typename MapConfig::segment_manager_base *)
|
Chris@16
|
118 : index_type(/*typename index_aux::value_compare()*/)
|
Chris@16
|
119 {}
|
Chris@16
|
120
|
Chris@16
|
121 //!This reserves memory to optimize the insertion of n
|
Chris@16
|
122 //!elements in the index
|
Chris@16
|
123 void reserve(typename MapConfig::segment_manager_base::size_type)
|
Chris@16
|
124 { /*Does nothing, map has not reserve or rehash*/ }
|
Chris@16
|
125
|
Chris@16
|
126 //!This frees all unnecessary memory
|
Chris@16
|
127 void shrink_to_fit()
|
Chris@16
|
128 { /*Does nothing, this intrusive index does not allocate memory;*/ }
|
Chris@16
|
129
|
Chris@16
|
130 iterator find(const intrusive_compare_key_type &key)
|
Chris@16
|
131 { return index_type::find(key, intrusive_key_value_less()); }
|
Chris@16
|
132
|
Chris@16
|
133 const_iterator find(const intrusive_compare_key_type &key) const
|
Chris@16
|
134 { return index_type::find(key, intrusive_key_value_less()); }
|
Chris@16
|
135
|
Chris@16
|
136 std::pair<iterator, bool>insert_check
|
Chris@16
|
137 (const intrusive_compare_key_type &key, insert_commit_data &commit_data)
|
Chris@16
|
138 { return index_type::insert_check(key, intrusive_key_value_less(), commit_data); }
|
Chris@16
|
139 };
|
Chris@16
|
140
|
Chris@101
|
141 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
142
|
Chris@16
|
143 //!Trait class to detect if an index is an intrusive
|
Chris@16
|
144 //!index.
|
Chris@16
|
145 template<class MapConfig>
|
Chris@16
|
146 struct is_intrusive_index
|
Chris@16
|
147 <boost::interprocess::iset_index<MapConfig> >
|
Chris@16
|
148 {
|
Chris@16
|
149 static const bool value = true;
|
Chris@16
|
150 };
|
Chris@101
|
151 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
152
|
Chris@16
|
153 } //namespace interprocess {
|
Chris@16
|
154 } //namespace boost
|
Chris@16
|
155
|
Chris@16
|
156 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
157
|
Chris@16
|
158 #endif //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP
|