PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/interprocess/indexes/map_index.hpp

http://hadesmem.googlecode.com/
C++ Header | 100 lines | 53 code | 18 blank | 29 comment | 0 complexity | 9443e070ed677b60db3f200f8090f8c6 MD5 | raw file
  1//////////////////////////////////////////////////////////////////////////////
  2//
  3// (C) Copyright Ion Gaztanaga 2005-2009. 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#include <boost/interprocess/detail/config_begin.hpp>
 15#include <boost/interprocess/detail/workaround.hpp>
 16
 17#include <functional>
 18#include <utility>
 19#include <boost/interprocess/containers/map.hpp>
 20#include <boost/interprocess/allocators/private_adaptive_pool.hpp>
 21
 22//!\file
 23//!Describes index adaptor of boost::map container, to use it
 24//!as name/shared memory index
 25
 26namespace boost {
 27namespace interprocess {
 28namespace detail{
 29
 30//!Helper class to define typedefs from IndexTraits
 31template <class MapConfig>
 32struct map_index_aux
 33{
 34   typedef typename MapConfig::key_type            key_type;
 35   typedef typename MapConfig::mapped_type         mapped_type;
 36   typedef std::less<key_type>                     key_less;
 37   typedef std::pair<const key_type, mapped_type>  value_type;
 38
 39   typedef private_adaptive_pool
 40            <value_type,
 41               typename MapConfig::
 42         segment_manager_base>                     allocator_type;
 43
 44   typedef boost::interprocess::map
 45      <key_type,  mapped_type,
 46       key_less, allocator_type>                   index_t;
 47};
 48
 49}  //namespace detail {
 50
 51//!Index type based in boost::interprocess::map. Just derives from boost::interprocess::map 
 52//!and defines the interface needed by managed memory segments
 53template <class MapConfig>
 54class map_index
 55   //Derive class from map specialization
 56   : public detail::map_index_aux<MapConfig>::index_t
 57{
 58   /// @cond
 59   typedef detail::map_index_aux<MapConfig>  index_aux;
 60   typedef typename index_aux::index_t       base_type;
 61   typedef typename MapConfig::
 62      segment_manager_base          segment_manager_base;
 63   /// @endcond
 64
 65   public:
 66   //!Constructor. Takes a pointer to the
 67   //!segment manager. Can throw
 68   map_index(segment_manager_base *segment_mngr)
 69      : base_type(typename index_aux::key_less(),
 70                  segment_mngr){}
 71
 72   //!This reserves memory to optimize the insertion of n
 73   //!elements in the index
 74   void reserve(std::size_t)
 75      {  /*Does nothing, map has not reserve or rehash*/  }
 76
 77   //!This tries to free previously allocate
 78   //!unused memory.
 79   void shrink_to_fit()
 80   {  base_type::get_stored_allocator().deallocate_free_blocks(); }
 81};
 82
 83/// @cond
 84
 85//!Trait class to detect if an index is a node
 86//!index. This allows more efficient operations
 87//!when deallocating named objects.
 88template<class MapConfig>
 89struct is_node_index
 90   <boost::interprocess::map_index<MapConfig> >
 91{
 92   enum {   value = true };
 93};
 94/// @endcond
 95
 96}}   //namespace boost { namespace interprocess {
 97
 98#include <boost/interprocess/detail/config_end.hpp>
 99
100#endif   //#ifndef BOOST_INTERPROCESS_MAP_INDEX_HPP