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 #ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|
Chris@16
|
11 #define BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|
Chris@16
|
12
|
Chris@101
|
13 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
14 # include <boost/config.hpp>
|
Chris@101
|
15 #endif
|
Chris@101
|
16 #
|
Chris@101
|
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
18 # pragma once
|
Chris@101
|
19 #endif
|
Chris@101
|
20
|
Chris@16
|
21 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
22 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
23
|
Chris@101
|
24 // interprocess
|
Chris@16
|
25 #include <boost/interprocess/containers/flat_map.hpp>
|
Chris@16
|
26 #include <boost/interprocess/allocators/allocator.hpp>
|
Chris@101
|
27 // intrusive/detail
|
Chris@101
|
28 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
|
Chris@101
|
29 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
|
Chris@101
|
30
|
Chris@16
|
31
|
Chris@16
|
32 //!\file
|
Chris@16
|
33 //!Describes index adaptor of boost::map container, to use it
|
Chris@16
|
34 //!as name/shared memory index
|
Chris@16
|
35
|
Chris@16
|
36 //[flat_map_index
|
Chris@16
|
37 namespace boost { namespace interprocess {
|
Chris@16
|
38
|
Chris@101
|
39 #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@101
|
40
|
Chris@16
|
41 //!Helper class to define typedefs from IndexTraits
|
Chris@16
|
42 template <class MapConfig>
|
Chris@16
|
43 struct flat_map_index_aux
|
Chris@16
|
44 {
|
Chris@16
|
45 typedef typename MapConfig::key_type key_type;
|
Chris@16
|
46 typedef typename MapConfig::mapped_type mapped_type;
|
Chris@16
|
47 typedef typename MapConfig::
|
Chris@16
|
48 segment_manager_base segment_manager_base;
|
Chris@16
|
49 typedef std::less<key_type> key_less;
|
Chris@16
|
50 typedef std::pair<key_type, mapped_type> value_type;
|
Chris@16
|
51 typedef allocator<value_type
|
Chris@16
|
52 ,segment_manager_base> allocator_type;
|
Chris@16
|
53 typedef flat_map<key_type, mapped_type,
|
Chris@16
|
54 key_less, allocator_type> index_t;
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@101
|
57 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@101
|
58
|
Chris@16
|
59 //!Index type based in flat_map. Just derives from flat_map and
|
Chris@16
|
60 //!defines the interface needed by managed memory segments.
|
Chris@16
|
61 template <class MapConfig>
|
Chris@16
|
62 class flat_map_index
|
Chris@16
|
63 //Derive class from flat_map specialization
|
Chris@16
|
64 : public flat_map_index_aux<MapConfig>::index_t
|
Chris@16
|
65 {
|
Chris@101
|
66 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
67 typedef flat_map_index_aux<MapConfig> index_aux;
|
Chris@16
|
68 typedef typename index_aux::index_t base_type;
|
Chris@16
|
69 typedef typename index_aux::
|
Chris@16
|
70 segment_manager_base segment_manager_base;
|
Chris@101
|
71 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
72
|
Chris@16
|
73 public:
|
Chris@16
|
74 //!Constructor. Takes a pointer to the segment manager. Can throw
|
Chris@16
|
75 flat_map_index(segment_manager_base *segment_mngr)
|
Chris@16
|
76 : base_type(typename index_aux::key_less(),
|
Chris@16
|
77 typename index_aux::allocator_type(segment_mngr))
|
Chris@16
|
78 {}
|
Chris@16
|
79
|
Chris@16
|
80 //!This reserves memory to optimize the insertion of n elements in the index
|
Chris@16
|
81 void reserve(typename segment_manager_base::size_type n)
|
Chris@16
|
82 { base_type::reserve(n); }
|
Chris@16
|
83
|
Chris@16
|
84 //!This frees all unnecessary memory
|
Chris@16
|
85 void shrink_to_fit()
|
Chris@16
|
86 { base_type::shrink_to_fit(); }
|
Chris@16
|
87 };
|
Chris@16
|
88
|
Chris@16
|
89 }} //namespace boost { namespace interprocess
|
Chris@16
|
90 //]
|
Chris@16
|
91 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
92
|
Chris@16
|
93 #endif //#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
|