1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP
12 #define BOOST_INTERPROCESS_MAP_INDEX_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/intrusive/detail/minimal_pair_header.hpp>
26 #include <boost/interprocess/containers/map.hpp>
27 #include <boost/interprocess/allocators/private_adaptive_pool.hpp>
28 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
29 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
32 //!Describes index adaptor of boost::map container, to use it
33 //!as name/shared memory index
36 namespace interprocess {
39 //!Helper class to define typedefs from IndexTraits
40 template <class MapConfig>
43 typedef typename MapConfig::key_type key_type;
44 typedef typename MapConfig::mapped_type mapped_type;
45 typedef std::less<key_type> key_less;
46 typedef std::pair<const key_type, mapped_type> value_type;
48 typedef private_adaptive_pool
51 segment_manager_base> allocator_type;
53 typedef boost::interprocess::map
54 <key_type, mapped_type,
55 key_less, allocator_type> index_t;
58 } //namespace ipcdetail {
60 //!Index type based in boost::interprocess::map. Just derives from boost::interprocess::map
61 //!and defines the interface needed by managed memory segments
62 template <class MapConfig>
64 //Derive class from map specialization
65 : public ipcdetail::map_index_aux<MapConfig>::index_t
67 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
68 typedef ipcdetail::map_index_aux<MapConfig> index_aux;
69 typedef typename index_aux::index_t base_type;
70 typedef typename MapConfig::
71 segment_manager_base segment_manager_base;
72 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
75 //!Constructor. Takes a pointer to the
76 //!segment manager. Can throw
77 map_index(segment_manager_base *segment_mngr)
78 : base_type(typename index_aux::key_less(),
81 //!This reserves memory to optimize the insertion of n
82 //!elements in the index
83 void reserve(typename segment_manager_base::size_type)
84 { /*Does nothing, map has not reserve or rehash*/ }
86 //!This tries to free previously allocate
89 { base_type::get_stored_allocator().deallocate_free_blocks(); }
92 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
94 //!Trait class to detect if an index is a node
95 //!index. This allows more efficient operations
96 //!when deallocating named objects.
97 template<class MapConfig>
99 <boost::interprocess::map_index<MapConfig> >
101 static const bool value = true;
103 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
105 }} //namespace boost { namespace interprocess {
107 #include <boost/interprocess/detail/config_end.hpp>
109 #endif //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP