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