| 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 | |
| 11 | #ifndef BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP |
| 12 | #define BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP |
| 13 | |
| 14 | #if defined (_MSC_VER) |
| 15 | # pragma once |
| 16 | #endif |
| 17 | |
| 18 | #include <boost/interprocess/detail/config_begin.hpp> |
| 19 | #include <boost/interprocess/detail/workaround.hpp> |
| 20 | |
| 21 | #include <boost/interprocess/interprocess_fwd.hpp> |
| 22 | #include <boost/interprocess/containers/allocation_type.hpp> |
| 23 | #include <boost/interprocess/detail/utilities.hpp> |
| 24 | #include <boost/interprocess/containers/version_type.hpp> |
| 25 | #include <boost/interprocess/exceptions.hpp> |
| 26 | #include <cstddef> |
| 27 | |
| 28 | //!\file |
| 29 | //!Describes an allocator to test expand capabilities |
| 30 | |
| 31 | namespace boost { |
| 32 | namespace interprocess { |
| 33 | namespace test { |
| 34 | |
| 35 | //This allocator just allows two allocations. The first one will return |
| 36 | //mp_buffer + m_offset configured in the constructor. The second one |
| 37 | //will return mp_buffer. |
| 38 | template<class T> |
| 39 | class dummy_test_allocator |
| 40 | { |
| 41 | private: |
| 42 | typedef dummy_test_allocator<T> self_t; |
| 43 | typedef void * aux_pointer_t; |
| 44 | typedef const void * cvoid_ptr; |
| 45 | |
| 46 | template<class T2> |
| 47 | dummy_test_allocator& operator=(const dummy_test_allocator<T2>&); |
| 48 | |
| 49 | dummy_test_allocator& operator=(const dummy_test_allocator&); |
| 50 | |
| 51 | public: |
| 52 | typedef T value_type; |
| 53 | typedef T * pointer; |
| 54 | typedef const T * const_pointer; |
| 55 | typedef typename ipcdetail::add_reference |
| 56 | <value_type>::type reference; |
| 57 | typedef typename ipcdetail::add_reference |
| 58 | <const value_type>::type const_reference; |
| 59 | typedef std::size_t size_type; |
| 60 | typedef std::ptrdiff_t difference_type; |
| 61 | |
| 62 | // typedef boost::interprocess::version_type<dummy_test_allocator, 2> version; |
| 63 | |
| 64 | template<class T2> |
| 65 | struct rebind |
| 66 | { typedef dummy_test_allocator<T2> other; }; |
| 67 | |
| 68 | //!Default constructor. Never throws |
| 69 | dummy_test_allocator() |
| 70 | {} |
| 71 | |
| 72 | //!Constructor from other dummy_test_allocator. Never throws |
| 73 | dummy_test_allocator(const dummy_test_allocator &) |
| 74 | {} |
| 75 | |
| 76 | //!Constructor from related dummy_test_allocator. Never throws |
| 77 | template<class T2> |
| 78 | dummy_test_allocator(const dummy_test_allocator<T2> &) |
| 79 | {} |
| 80 | |
| 81 | pointer address(reference value) |
| 82 | { return pointer(addressof(value)); } |
| 83 | |
| 84 | const_pointer address(const_reference value) const |
| 85 | { return const_pointer(addressof(value)); } |
| 86 | |
| 87 | pointer allocate(size_type, cvoid_ptr = 0) |
| 88 | { return 0; } |
| 89 | |
| 90 | void deallocate(const pointer &, size_type) |
| 91 | { } |
| 92 | |
| 93 | template<class Convertible> |
| 94 | void construct(pointer, const Convertible &) |
| 95 | {} |
| 96 | |
| 97 | void destroy(pointer) |
| 98 | {} |
| 99 | |
| 100 | size_type max_size() const |
| 101 | { return 0; } |
| 102 | |
| 103 | friend void swap(self_t &, self_t &) |
| 104 | {} |
| 105 | |
| 106 | //Experimental version 2 dummy_test_allocator functions |
| 107 | |
| 108 | pointer allocation_command(boost::interprocess::allocation_type, |
| 109 | size_type, size_type &, pointer &) |
| 110 | { return pointer(); } |
| 111 | |
| 112 | //!Returns maximum the number of objects the previously allocated memory |
| 113 | //!pointed by p can hold. |
| 114 | size_type size(const pointer &) const |
| 115 | { return 0; } |
| 116 | |
| 117 | //!Allocates just one object. Memory allocated with this function |
| 118 | //!must be deallocated only with deallocate_one(). |
| 119 | //!Throws boost::interprocess::bad_alloc if there is no enough memory |
| 120 | pointer allocate_one() |
| 121 | { return pointer(); } |
| 122 | |
| 123 | //!Deallocates memory previously allocated with allocate_one(). |
| 124 | //!You should never use deallocate_one to deallocate memory allocated |
| 125 | //!with other functions different from allocate_one(). Never throws |
| 126 | void deallocate_one(const pointer &) |
| 127 | {} |
| 128 | }; |
| 129 | |
| 130 | //!Equality test for same type of dummy_test_allocator |
| 131 | template<class T> inline |
| 132 | bool operator==(const dummy_test_allocator<T> &, |
| 133 | const dummy_test_allocator<T> &) |
| 134 | { return false; } |
| 135 | |
| 136 | //!Inequality test for same type of dummy_test_allocator |
| 137 | template<class T> inline |
| 138 | bool operator!=(const dummy_test_allocator<T> &, |
| 139 | const dummy_test_allocator<T> &) |
| 140 | { return true; } |
| 141 | |
| 142 | } //namespace test { |
| 143 | } //namespace interprocess { |
| 144 | } //namespace boost { |
| 145 | |
| 146 | #include <boost/interprocess/detail/config_end.hpp> |
| 147 | |
| 148 | #endif //BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP |
| 149 | |
| 150 | |