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_MAP_INDEX_HPP
|
Chris@16
|
12 #define BOOST_INTERPROCESS_MAP_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/containers/map.hpp>
|
Chris@16
|
27 #include <boost/interprocess/allocators/private_adaptive_pool.hpp>
|
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@16
|
30
|
Chris@16
|
31 //!\file
|
Chris@16
|
32 //!Describes index adaptor of boost::map container, to use it
|
Chris@16
|
33 //!as name/shared memory index
|
Chris@16
|
34
|
Chris@16
|
35 namespace boost {
|
Chris@16
|
36 namespace interprocess {
|
Chris@16
|
37 namespace ipcdetail{
|
Chris@16
|
38
|
Chris@16
|
39 //!Helper class to define typedefs from IndexTraits
|
Chris@16
|
40 template <class MapConfig>
|
Chris@16
|
41 struct map_index_aux
|
Chris@16
|
42 {
|
Chris@16
|
43 typedef typename MapConfig::key_type key_type;
|
Chris@16
|
44 typedef typename MapConfig::mapped_type mapped_type;
|
Chris@16
|
45 typedef std::less<key_type> key_less;
|
Chris@16
|
46 typedef std::pair<const key_type, mapped_type> value_type;
|
Chris@16
|
47
|
Chris@16
|
48 typedef private_adaptive_pool
|
Chris@16
|
49 <value_type,
|
Chris@16
|
50 typename MapConfig::
|
Chris@16
|
51 segment_manager_base> allocator_type;
|
Chris@16
|
52
|
Chris@16
|
53 typedef boost::interprocess::map
|
Chris@16
|
54 <key_type, mapped_type,
|
Chris@16
|
55 key_less, allocator_type> index_t;
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 } //namespace ipcdetail {
|
Chris@16
|
59
|
Chris@16
|
60 //!Index type based in boost::interprocess::map. Just derives from boost::interprocess::map
|
Chris@16
|
61 //!and defines the interface needed by managed memory segments
|
Chris@16
|
62 template <class MapConfig>
|
Chris@16
|
63 class map_index
|
Chris@16
|
64 //Derive class from map specialization
|
Chris@16
|
65 : public ipcdetail::map_index_aux<MapConfig>::index_t
|
Chris@16
|
66 {
|
Chris@101
|
67 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
68 typedef ipcdetail::map_index_aux<MapConfig> index_aux;
|
Chris@16
|
69 typedef typename index_aux::index_t base_type;
|
Chris@16
|
70 typedef typename MapConfig::
|
Chris@16
|
71 segment_manager_base segment_manager_base;
|
Chris@101
|
72 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
73
|
Chris@16
|
74 public:
|
Chris@16
|
75 //!Constructor. Takes a pointer to the
|
Chris@16
|
76 //!segment manager. Can throw
|
Chris@16
|
77 map_index(segment_manager_base *segment_mngr)
|
Chris@16
|
78 : base_type(typename index_aux::key_less(),
|
Chris@16
|
79 segment_mngr){}
|
Chris@16
|
80
|
Chris@16
|
81 //!This reserves memory to optimize the insertion of n
|
Chris@16
|
82 //!elements in the index
|
Chris@16
|
83 void reserve(typename segment_manager_base::size_type)
|
Chris@16
|
84 { /*Does nothing, map has not reserve or rehash*/ }
|
Chris@16
|
85
|
Chris@16
|
86 //!This tries to free previously allocate
|
Chris@16
|
87 //!unused memory.
|
Chris@16
|
88 void shrink_to_fit()
|
Chris@16
|
89 { base_type::get_stored_allocator().deallocate_free_blocks(); }
|
Chris@16
|
90 };
|
Chris@16
|
91
|
Chris@101
|
92 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
93
|
Chris@16
|
94 //!Trait class to detect if an index is a node
|
Chris@16
|
95 //!index. This allows more efficient operations
|
Chris@16
|
96 //!when deallocating named objects.
|
Chris@16
|
97 template<class MapConfig>
|
Chris@16
|
98 struct is_node_index
|
Chris@16
|
99 <boost::interprocess::map_index<MapConfig> >
|
Chris@16
|
100 {
|
Chris@16
|
101 static const bool value = true;
|
Chris@16
|
102 };
|
Chris@101
|
103 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
104
|
Chris@16
|
105 }} //namespace boost { namespace interprocess {
|
Chris@16
|
106
|
Chris@16
|
107 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
108
|
Chris@16
|
109 #endif //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP
|