managed_external_buffer.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_MANAGED_EXTERNAL_BUFFER_HPP
  11. #define BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
  12. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #include <boost/interprocess/detail/workaround.hpp>
  17. #include <boost/interprocess/creation_tags.hpp>
  18. #include <boost/interprocess/detail/managed_memory_impl.hpp>
  19. #include <boost/move/move.hpp>
  20. #include <boost/assert.hpp>
  21. //These includes needed to fulfill default template parameters of
  22. //predeclarations in interprocess_fwd.hpp
  23. #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
  24. #include <boost/interprocess/sync/mutex_family.hpp>
  25. #include <boost/interprocess/indexes/iset_index.hpp>
  26. //!\file
  27. //!Describes a named user memory allocation user class.
  28. namespace boost {
  29. namespace interprocess {
  30. //!A basic user memory named object creation class. Inherits all
  31. //!basic functionality from
  32. //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>*/
  33. template
  34. <
  35. class CharType,
  36. class AllocationAlgorithm,
  37. template<class IndexConfig> class IndexType
  38. >
  39. class basic_managed_external_buffer
  40. : public ipcdetail::basic_managed_memory_impl <CharType, AllocationAlgorithm, IndexType>
  41. {
  42. /// @cond
  43. typedef ipcdetail::basic_managed_memory_impl
  44. <CharType, AllocationAlgorithm, IndexType> base_t;
  45. BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_external_buffer)
  46. /// @endcond
  47. public:
  48. typedef typename base_t::size_type size_type;
  49. //!Default constructor. Does nothing.
  50. //!Useful in combination with move semantics
  51. basic_managed_external_buffer()
  52. {}
  53. //!Creates and places the segment manager. This can throw
  54. basic_managed_external_buffer
  55. (create_only_t, void *addr, size_type size)
  56. {
  57. //Check if alignment is correct
  58. BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
  59. if(!base_t::create_impl(addr, size)){
  60. throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
  61. }
  62. }
  63. //!Creates and places the segment manager. This can throw
  64. basic_managed_external_buffer
  65. (open_only_t, void *addr, size_type size)
  66. {
  67. //Check if alignment is correct
  68. BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
  69. if(!base_t::open_impl(addr, size)){
  70. throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
  71. }
  72. }
  73. //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
  74. basic_managed_external_buffer(BOOST_RV_REF(basic_managed_external_buffer) moved)
  75. {
  76. this->swap(moved);
  77. }
  78. //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
  79. basic_managed_external_buffer &operator=(BOOST_RV_REF(basic_managed_external_buffer) moved)
  80. {
  81. basic_managed_external_buffer tmp(boost::move(moved));
  82. this->swap(tmp);
  83. return *this;
  84. }
  85. void grow(size_type extra_bytes)
  86. { base_t::grow(extra_bytes); }
  87. //!Swaps the ownership of the managed heap memories managed by *this and other.
  88. //!Never throws.
  89. void swap(basic_managed_external_buffer &other)
  90. { base_t::swap(other); }
  91. };
  92. } //namespace interprocess {
  93. } //namespace boost {
  94. #include <boost/interprocess/detail/config_end.hpp>
  95. #endif //BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP