comparison DEPENDENCIES/generic/include/boost/interprocess/indexes/iset_index.hpp @ 16:2665513ce2d3

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