]>
Commit | Line | Data |
---|---|---|
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 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | # | |
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
22 | #include <boost/interprocess/detail/config_begin.hpp> | |
23 | #include <boost/interprocess/detail/workaround.hpp> | |
24 | ||
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> | |
31 | ||
32 | //!\file | |
33 | //!Describes index adaptor of boost::intrusive::set container, to use it | |
34 | //!as name/shared memory index | |
35 | ||
36 | namespace boost { | |
37 | namespace interprocess { | |
38 | ||
39 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
40 | ||
41 | //!Helper class to define typedefs from IndexTraits | |
42 | template <class MapConfig> | |
43 | struct iset_index_aux | |
44 | { | |
45 | typedef typename | |
46 | MapConfig::segment_manager_base segment_manager_base; | |
47 | ||
48 | typedef typename | |
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; | |
54 | ||
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 | |
59 | < value_type | |
60 | , bi::base_hook<derivation_hook> | |
61 | >::type index_t; | |
62 | }; | |
63 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
64 | ||
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> | |
69 | class iset_index | |
70 | //Derive class from map specialization | |
71 | : public iset_index_aux<MapConfig>::index_t | |
72 | { | |
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 | |
80 | ||
81 | public: | |
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; | |
86 | ||
87 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
88 | private: | |
89 | ||
90 | struct intrusive_key_value_less | |
91 | { | |
92 | bool operator()(const intrusive_compare_key_type &i, const value_type &b) const | |
93 | { | |
94 | std::size_t blen = b.name_length(); | |
95 | return (i.m_len < blen) || | |
96 | (i.m_len == blen && | |
97 | std::char_traits<char_type>::compare | |
98 | (i.mp_str, b.name(), i.m_len) < 0); | |
99 | } | |
100 | ||
101 | bool operator()(const value_type &b, const intrusive_compare_key_type &i) const | |
102 | { | |
103 | std::size_t blen = b.name_length(); | |
104 | return (blen < i.m_len) || | |
105 | (blen == i.m_len && | |
106 | std::char_traits<char_type>::compare | |
107 | (b.name(), i.mp_str, i.m_len) < 0); | |
108 | } | |
109 | }; | |
110 | ||
111 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
112 | ||
113 | public: | |
114 | ||
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()*/) | |
119 | {} | |
120 | ||
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*/ } | |
125 | ||
126 | //!This frees all unnecessary memory | |
127 | void shrink_to_fit() | |
128 | { /*Does nothing, this intrusive index does not allocate memory;*/ } | |
129 | ||
130 | iterator find(const intrusive_compare_key_type &key) | |
131 | { return index_type::find(key, intrusive_key_value_less()); } | |
132 | ||
133 | const_iterator find(const intrusive_compare_key_type &key) const | |
134 | { return index_type::find(key, intrusive_key_value_less()); } | |
135 | ||
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); } | |
139 | }; | |
140 | ||
141 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
142 | ||
143 | //!Trait class to detect if an index is an intrusive | |
144 | //!index. | |
145 | template<class MapConfig> | |
146 | struct is_intrusive_index | |
147 | <boost::interprocess::iset_index<MapConfig> > | |
148 | { | |
149 | static const bool value = true; | |
150 | }; | |
151 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
152 | ||
153 | } //namespace interprocess { | |
154 | } //namespace boost | |
155 | ||
156 | #include <boost/interprocess/detail/config_end.hpp> | |
157 | ||
158 | #endif //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP |