/Src/Dependencies/Boost/boost/interprocess/managed_external_buffer.hpp

http://hadesmem.googlecode.com/ · C++ Header · 107 lines · 63 code · 18 blank · 26 comment · 5 complexity · bc95b4bb2cc4eb03227b8c867656ae49 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_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/interprocess/detail/move.hpp>
  20. #include <boost/assert.hpp>
  21. //!\file
  22. //!Describes a named user memory allocation user class.
  23. namespace boost {
  24. namespace interprocess {
  25. //!A basic user memory named object creation class. Inherits all
  26. //!basic functionality from
  27. //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>*/
  28. template
  29. <
  30. class CharType,
  31. class AllocationAlgorithm,
  32. template<class IndexConfig> class IndexType
  33. >
  34. class basic_managed_external_buffer
  35. : public detail::basic_managed_memory_impl <CharType, AllocationAlgorithm, IndexType>
  36. {
  37. /// @cond
  38. typedef detail::basic_managed_memory_impl
  39. <CharType, AllocationAlgorithm, IndexType> base_t;
  40. BOOST_INTERPROCESS_MOVABLE_BUT_NOT_COPYABLE(basic_managed_external_buffer)
  41. /// @endcond
  42. public:
  43. //!Default constructor. Does nothing.
  44. //!Useful in combination with move semantics
  45. basic_managed_external_buffer()
  46. {}
  47. //!Creates and places the segment manager. This can throw
  48. basic_managed_external_buffer
  49. (create_only_t, void *addr, std::size_t size)
  50. {
  51. //Check if alignment is correct
  52. BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - std::size_t(1u)))));
  53. if(!base_t::create_impl(addr, size)){
  54. throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
  55. }
  56. }
  57. //!Creates and places the segment manager. This can throw
  58. basic_managed_external_buffer
  59. (open_only_t, void *addr, std::size_t size)
  60. {
  61. //Check if alignment is correct
  62. BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - std::size_t(1u)))));
  63. if(!base_t::open_impl(addr, size)){
  64. throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
  65. }
  66. }
  67. //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
  68. basic_managed_external_buffer(BOOST_INTERPROCESS_RV_REF(basic_managed_external_buffer) moved)
  69. {
  70. this->swap(moved);
  71. }
  72. //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
  73. basic_managed_external_buffer &operator=(BOOST_INTERPROCESS_RV_REF(basic_managed_external_buffer) moved)
  74. {
  75. basic_managed_external_buffer tmp(boost::interprocess::move(moved));
  76. this->swap(tmp);
  77. return *this;
  78. }
  79. void grow(std::size_t extra_bytes)
  80. { base_t::grow(extra_bytes); }
  81. //!Swaps the ownership of the managed heap memories managed by *this and other.
  82. //!Never throws.
  83. void swap(basic_managed_external_buffer &other)
  84. { base_t::swap(other); }
  85. };
  86. } //namespace interprocess {
  87. } //namespace boost {
  88. #include <boost/interprocess/detail/config_end.hpp>
  89. #endif //BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP