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