Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/interprocess for documentation. Chris@16: // Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP Chris@16: #define BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP Chris@16: Chris@101: #ifndef BOOST_CONFIG_HPP Chris@101: # include Chris@101: #endif Chris@101: # Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@101: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #include //std::pair Chris@101: #include //std::less Chris@101: Chris@16: //!\file Chris@16: //!Describes index adaptor of boost::unordered_map container, to use it Chris@16: //!as name/shared memory index Chris@16: Chris@16: namespace boost { Chris@16: namespace interprocess { Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: Chris@16: //!Helper class to define typedefs from Chris@16: //!IndexTraits Chris@16: template Chris@16: struct unordered_map_index_aux Chris@16: { Chris@16: typedef typename MapConfig::key_type key_type; Chris@16: typedef typename MapConfig::mapped_type mapped_type; Chris@16: typedef std::equal_to key_equal; Chris@16: typedef std::pair value_type; Chris@16: typedef private_adaptive_pool Chris@16: allocator_type; Chris@16: struct hasher Chris@16: : std::unary_function Chris@16: { Chris@16: std::size_t operator()(const key_type &val) const Chris@16: { Chris@16: typedef typename key_type::char_type char_type; Chris@16: const char_type *beg = ipcdetail::to_raw_pointer(val.mp_str), Chris@16: *end = beg + val.m_len; Chris@16: return boost::hash_range(beg, end); Chris@16: } Chris@16: }; Chris@16: typedef unordered_map index_t; Chris@16: }; Chris@16: Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: //!Index type based in unordered_map. Just derives from unordered_map and Chris@16: //!defines the interface needed by managed memory segments Chris@16: template Chris@16: class unordered_map_index Chris@16: //Derive class from unordered_map specialization Chris@16: : public unordered_map_index_aux::index_t Chris@16: { Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: typedef unordered_map_index_aux index_aux; Chris@16: typedef typename index_aux::index_t base_type; Chris@16: typedef typename Chris@16: MapConfig::segment_manager_base segment_manager_base; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: public: Chris@16: //!Constructor. Takes a pointer to the Chris@16: //!segment manager. Can throw Chris@16: unordered_map_index(segment_manager_base *segment_mngr) Chris@16: : base_type(0, Chris@16: typename index_aux::hasher(), Chris@16: typename index_aux::key_equal(), Chris@16: segment_mngr){} Chris@16: Chris@16: //!This reserves memory to optimize the insertion of n Chris@16: //!elements in the index Chris@16: void reserve(typename segment_manager_base::size_type n) Chris@16: { base_type::rehash(n); } Chris@16: Chris@16: //!This tries to free previously allocate Chris@16: //!unused memory. Chris@16: void shrink_to_fit() Chris@16: { base_type::rehash(base_type::size()); } Chris@16: }; Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: Chris@16: //!Trait class to detect if an index is a node Chris@16: //!index. This allows more efficient operations Chris@16: //!when deallocating named objects. Chris@16: template Chris@16: struct is_node_index Chris@16: > Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: }} //namespace boost { namespace interprocess { Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //#ifndef BOOST_INTERPROCESS_UNORDERED_MAP_INDEX_HPP