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_ISET_INDEX_HPP Chris@16: #define BOOST_INTERPROCESS_ISET_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@101: #include Chris@16: #include Chris@101: #include //std::pair Chris@101: #include //std::less Chris@101: #include //std::char_traits Chris@16: #include Chris@16: Chris@16: //!\file Chris@16: //!Describes index adaptor of boost::intrusive::set 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 IndexTraits Chris@16: template Chris@16: struct iset_index_aux Chris@16: { Chris@16: typedef typename Chris@16: MapConfig::segment_manager_base segment_manager_base; Chris@16: Chris@16: typedef typename Chris@16: segment_manager_base::void_pointer void_pointer; Chris@16: typedef typename bi::make_set_base_hook Chris@16: < bi::void_pointer Chris@16: , bi::optimize_size Chris@16: >::type derivation_hook; Chris@16: Chris@16: typedef typename MapConfig::template Chris@16: intrusive_value_type::type value_type; Chris@16: typedef std::less value_compare; Chris@16: typedef typename bi::make_set Chris@16: < value_type Chris@16: , bi::base_hook Chris@16: >::type index_t; Chris@16: }; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: //!Index type based in boost::intrusive::set. Chris@16: //!Just derives from boost::intrusive::set Chris@16: //!and defines the interface needed by managed memory segments*/ Chris@16: template Chris@16: class iset_index Chris@16: //Derive class from map specialization Chris@16: : public iset_index_aux::index_t Chris@16: { Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: typedef iset_index_aux index_aux; Chris@16: typedef typename index_aux::index_t index_type; Chris@16: typedef typename MapConfig:: Chris@16: intrusive_compare_key_type intrusive_compare_key_type; Chris@16: typedef typename MapConfig::char_type char_type; Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: public: Chris@16: typedef typename index_type::iterator iterator; Chris@16: typedef typename index_type::const_iterator const_iterator; Chris@16: typedef typename index_type::insert_commit_data insert_commit_data; Chris@16: typedef typename index_type::value_type value_type; Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: private: Chris@16: Chris@16: struct intrusive_key_value_less Chris@16: { Chris@16: bool operator()(const intrusive_compare_key_type &i, const value_type &b) const Chris@16: { Chris@16: std::size_t blen = b.name_length(); Chris@16: return (i.m_len < blen) || Chris@16: (i.m_len == blen && Chris@16: std::char_traits::compare Chris@16: (i.mp_str, b.name(), i.m_len) < 0); Chris@16: } Chris@16: Chris@16: bool operator()(const value_type &b, const intrusive_compare_key_type &i) const Chris@16: { Chris@16: std::size_t blen = b.name_length(); Chris@16: return (blen < i.m_len) || Chris@16: (blen == i.m_len && Chris@16: std::char_traits::compare Chris@16: (b.name(), i.mp_str, i.m_len) < 0); Chris@16: } Chris@16: }; Chris@16: Chris@101: #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED Chris@16: Chris@16: public: Chris@16: Chris@16: //!Constructor. Takes a pointer to the Chris@16: //!segment manager. Can throw Chris@16: iset_index(typename MapConfig::segment_manager_base *) Chris@16: : index_type(/*typename index_aux::value_compare()*/) Chris@16: {} Chris@16: Chris@16: //!This reserves memory to optimize the insertion of n Chris@16: //!elements in the index Chris@16: void reserve(typename MapConfig::segment_manager_base::size_type) Chris@16: { /*Does nothing, map has not reserve or rehash*/ } Chris@16: Chris@16: //!This frees all unnecessary memory Chris@16: void shrink_to_fit() Chris@16: { /*Does nothing, this intrusive index does not allocate memory;*/ } Chris@16: Chris@16: iterator find(const intrusive_compare_key_type &key) Chris@16: { return index_type::find(key, intrusive_key_value_less()); } Chris@16: Chris@16: const_iterator find(const intrusive_compare_key_type &key) const Chris@16: { return index_type::find(key, intrusive_key_value_less()); } Chris@16: Chris@16: std::pairinsert_check Chris@16: (const intrusive_compare_key_type &key, insert_commit_data &commit_data) Chris@16: { return index_type::insert_check(key, intrusive_key_value_less(), commit_data); } Chris@16: }; Chris@16: Chris@101: #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) Chris@16: Chris@16: //!Trait class to detect if an index is an intrusive Chris@16: //!index. Chris@16: template Chris@16: struct is_intrusive_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 interprocess { Chris@16: } //namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //#ifndef BOOST_INTERPROCESS_ISET_INDEX_HPP