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