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