flat_map_index.hpp 3.2 KB

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