PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ Header | 78 lines | 44 code | 11 blank | 23 comment | 0 complexity | 1cbc875b5d5bfcf2168d2f57d35cde94 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#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
11#define BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP
12
13#include <boost/interprocess/detail/config_begin.hpp>
14#include <boost/interprocess/detail/workaround.hpp>
15
16#include <functional>
17#include <utility>
18#include <boost/interprocess/containers/flat_map.hpp>
19#include <boost/interprocess/allocators/allocator.hpp>
20
21//!\file
22//!Describes index adaptor of boost::map container, to use it
23//!as name/shared memory index
24
25//[flat_map_index
26namespace boost { namespace interprocess {
27
28//!Helper class to define typedefs from IndexTraits
29template <class MapConfig>
30struct flat_map_index_aux
31{
32   typedef typename MapConfig::key_type            key_type;
33   typedef typename MapConfig::mapped_type         mapped_type;
34   typedef typename MapConfig::
35      segment_manager_base                   segment_manager_base;
36   typedef std::less<key_type>                     key_less;
37   typedef std::pair<key_type, mapped_type>        value_type;
38   typedef allocator<value_type
39                    ,segment_manager_base>   allocator_type;
40   typedef flat_map<key_type,  mapped_type,
41                    key_less, allocator_type>      index_t;
42};
43
44//!Index type based in flat_map. Just derives from flat_map and
45//!defines the interface needed by managed memory segments.
46template <class MapConfig>
47class flat_map_index
48   //Derive class from flat_map specialization
49   : public flat_map_index_aux<MapConfig>::index_t
50{
51   /// @cond
52   typedef flat_map_index_aux<MapConfig>  index_aux;
53   typedef typename index_aux::index_t    base_type;
54   typedef typename index_aux::
55      segment_manager_base          segment_manager_base;
56   /// @endcond
57
58   public:
59   //!Constructor. Takes a pointer to the segment manager. Can throw
60   flat_map_index(segment_manager_base *segment_mngr)
61      : base_type(typename index_aux::key_less(),
62                  typename index_aux::allocator_type(segment_mngr))
63   {}
64
65   //!This reserves memory to optimize the insertion of n elements in the index
66   void reserve(std::size_t n)
67   {  base_type::reserve(n);  }
68
69   //!This frees all unnecessary memory
70   void shrink_to_fit()
71   {  base_type::shrink_to_fit();   }
72};
73
74}}   //namespace boost { namespace interprocess
75//]
76#include <boost/interprocess/detail/config_end.hpp>
77
78#endif   //#ifndef BOOST_INTERPROCESS_FLAT_MAP_INDEX_HPP