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_MAP_INDEX_HPP 12 #define BOOST_INTERPROCESS_MAP_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/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 30 31 //!\file 32 //!Describes index adaptor of boost::map container, to use it 33 //!as name/shared memory index 34 35 namespace boost { 36 namespace interprocess { 37 namespace ipcdetail{ 38 39 //!Helper class to define typedefs from IndexTraits 40 template <class MapConfig> 41 struct map_index_aux 42 { 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; 47 48 typedef private_adaptive_pool 49 <value_type, 50 typename MapConfig:: 51 segment_manager_base> allocator_type; 52 53 typedef boost::interprocess::map 54 <key_type, mapped_type, 55 key_less, allocator_type> index_t; 56 }; 57 58 } //namespace ipcdetail { 59 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> 63 class map_index 64 //Derive class from map specialization 65 : public ipcdetail::map_index_aux<MapConfig>::index_t 66 { 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 73 74 public: 75 //!Constructor. Takes a pointer to the 76 //!segment manager. Can throw map_index(segment_manager_base * segment_mngr)77 map_index(segment_manager_base *segment_mngr) 78 : base_type(typename index_aux::key_less(), 79 segment_mngr){} 80 81 //!This reserves memory to optimize the insertion of n 82 //!elements in the index reserve(typename segment_manager_base::size_type)83 void reserve(typename segment_manager_base::size_type) 84 { /*Does nothing, map has not reserve or rehash*/ } 85 86 //!This tries to free previously allocate 87 //!unused memory. shrink_to_fit()88 void shrink_to_fit() 89 { base_type::get_stored_allocator().deallocate_free_blocks(); } 90 }; 91 92 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) 93 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> 98 struct is_node_index 99 <boost::interprocess::map_index<MapConfig> > 100 { 101 static const bool value = true; 102 }; 103 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED 104 105 }} //namespace boost { namespace interprocess { 106 107 #include <boost/interprocess/detail/config_end.hpp> 108 109 #endif //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP 110