derived_from_memory_resource.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015. 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/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP
  11. #define BOOST_CONTAINER_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP
  12. #include <boost/container/pmr/memory_resource.hpp>
  13. class derived_from_memory_resource
  14. : public boost::container::pmr::memory_resource
  15. {
  16. public:
  17. explicit derived_from_memory_resource(unsigned i = 0u)
  18. : id(i)
  19. {}
  20. virtual ~derived_from_memory_resource()
  21. { destructor_called = true; }
  22. virtual void* do_allocate(std::size_t bytes, std::size_t alignment)
  23. {
  24. do_allocate_called = true;
  25. do_allocate_bytes = bytes;
  26. do_allocate_alignment = alignment;
  27. return do_allocate_return;
  28. }
  29. virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment)
  30. {
  31. do_deallocate_called = true;
  32. do_deallocate_p = p;
  33. do_deallocate_bytes = bytes;
  34. do_deallocate_alignment = alignment;
  35. }
  36. virtual bool do_is_equal(const boost::container::pmr::memory_resource& other) const BOOST_NOEXCEPT
  37. {
  38. do_is_equal_called = true;
  39. do_is_equal_other = &other;
  40. return static_cast<const derived_from_memory_resource&>(other).id == this->id;
  41. }
  42. void reset()
  43. {
  44. destructor_called = false;
  45. do_allocate_return = 0;
  46. do_allocate_called = false;
  47. do_allocate_bytes = 0u;
  48. do_allocate_alignment = 0u;
  49. do_deallocate_called = false;
  50. do_deallocate_p = 0;
  51. do_deallocate_bytes = 0u;
  52. do_deallocate_alignment = 0u;
  53. do_is_equal_called = false;
  54. do_is_equal_other = 0;
  55. }
  56. //checkers
  57. static bool destructor_called;
  58. unsigned id;
  59. void *do_allocate_return;
  60. mutable bool do_allocate_called;
  61. mutable std::size_t do_allocate_bytes;
  62. mutable std::size_t do_allocate_alignment;
  63. mutable bool do_deallocate_called;
  64. mutable void *do_deallocate_p;
  65. mutable std::size_t do_deallocate_bytes;
  66. mutable std::size_t do_deallocate_alignment;
  67. mutable bool do_is_equal_called;
  68. mutable const boost::container::pmr::memory_resource *do_is_equal_other;
  69. };
  70. bool derived_from_memory_resource::destructor_called = false;
  71. #endif //#ifndef BOOST_CONTAINER_TEST_DERIVED_FROM_MEMORY_RESOURCE_HPP