annotate DEPENDENCIES/generic/include/boost/interprocess/indexes/unordered_map_index.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
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_UNORDERED_MAP_INDEX_HPP
Chris@16 12 #define BOOST_INTERPROCESS_UNORDERED_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@16 25 #include <functional>
Chris@101 26 #include <boost/intrusive/detail/minimal_pair_header.hpp>
Chris@16 27 #include <boost/unordered_map.hpp>
Chris@16 28 #include <boost/interprocess/detail/utilities.hpp>
Chris@16 29 #include <boost/interprocess/allocators/private_adaptive_pool.hpp>
Chris@16 30
Chris@101 31 #include <boost/intrusive/detail/minimal_pair_header.hpp> //std::pair
Chris@101 32 #include <boost/intrusive/detail/minimal_less_equal_header.hpp> //std::less
Chris@101 33
Chris@16 34 //!\file
Chris@16 35 //!Describes index adaptor of boost::unordered_map container, to use it
Chris@16 36 //!as name/shared memory index
Chris@16 37
Chris@16 38 namespace boost {
Chris@16 39 namespace interprocess {
Chris@16 40
Chris@101 41 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 42
Chris@16 43 //!Helper class to define typedefs from
Chris@16 44 //!IndexTraits
Chris@16 45 template <class MapConfig>
Chris@16 46 struct unordered_map_index_aux
Chris@16 47 {
Chris@16 48 typedef typename MapConfig::key_type key_type;
Chris@16 49 typedef typename MapConfig::mapped_type mapped_type;
Chris@16 50 typedef std::equal_to<key_type> key_equal;
Chris@16 51 typedef std::pair<const key_type, mapped_type> value_type;
Chris@16 52 typedef private_adaptive_pool
Chris@16 53 <value_type,
Chris@16 54 typename MapConfig::
Chris@16 55 segment_manager_base> allocator_type;
Chris@16 56 struct hasher
Chris@16 57 : std::unary_function<key_type, std::size_t>
Chris@16 58 {
Chris@16 59 std::size_t operator()(const key_type &val) const
Chris@16 60 {
Chris@16 61 typedef typename key_type::char_type char_type;
Chris@16 62 const char_type *beg = ipcdetail::to_raw_pointer(val.mp_str),
Chris@16 63 *end = beg + val.m_len;
Chris@16 64 return boost::hash_range(beg, end);
Chris@16 65 }
Chris@16 66 };
Chris@16 67 typedef unordered_map<key_type, mapped_type, hasher,
Chris@16 68 key_equal, allocator_type> index_t;
Chris@16 69 };
Chris@16 70
Chris@101 71 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 72
Chris@16 73 //!Index type based in unordered_map. Just derives from unordered_map and
Chris@16 74 //!defines the interface needed by managed memory segments
Chris@16 75 template <class MapConfig>
Chris@16 76 class unordered_map_index
Chris@16 77 //Derive class from unordered_map specialization
Chris@16 78 : public unordered_map_index_aux<MapConfig>::index_t
Chris@16 79 {
Chris@101 80 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 81 typedef unordered_map_index_aux<MapConfig> index_aux;
Chris@16 82 typedef typename index_aux::index_t base_type;
Chris@16 83 typedef typename
Chris@16 84 MapConfig::segment_manager_base segment_manager_base;
Chris@101 85 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 86
Chris@16 87 public:
Chris@16 88 //!Constructor. Takes a pointer to the
Chris@16 89 //!segment manager. Can throw
Chris@16 90 unordered_map_index(segment_manager_base *segment_mngr)
Chris@16 91 : base_type(0,
Chris@16 92 typename index_aux::hasher(),
Chris@16 93 typename index_aux::key_equal(),
Chris@16 94 segment_mngr){}
Chris@16 95
Chris@16 96 //!This reserves memory to optimize the insertion of n
Chris@16 97 //!elements in the index
Chris@16 98 void reserve(typename segment_manager_base::size_type n)
Chris@16 99 { base_type::rehash(n); }
Chris@16 100
Chris@16 101 //!This tries to free previously allocate
Chris@16 102 //!unused memory.
Chris@16 103 void shrink_to_fit()
Chris@16 104 { base_type::rehash(base_type::size()); }
Chris@16 105 };
Chris@16 106
Chris@101 107 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 108
Chris@16 109 //!Trait class to detect if an index is a node
Chris@16 110 //!index. This allows more efficient operations
Chris@16 111 //!when deallocating named objects.
Chris@16 112 template<class MapConfig>
Chris@16 113 struct is_node_index
Chris@16 114 <boost::interprocess::unordered_map_index<MapConfig> >
Chris@16 115 {
Chris@16 116 static const bool value = true;
Chris@16 117 };
Chris@101 118 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 119
Chris@16 120 }} //namespace boost { namespace interprocess {
Chris@16 121
Chris@16 122 #include <boost/interprocess/detail/config_end.hpp>
Chris@16 123
Chris@16 124 #endif //#ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP