1 ///////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP
12 #define BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP
14 #if defined (_MSC_VER)
18 #include <boost/interprocess/detail/config_begin.hpp>
19 #include <boost/interprocess/detail/workaround.hpp>
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>
29 //!Describes an allocator to test expand capabilities
32 namespace interprocess {
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.
39 class dummy_test_allocator
42 typedef dummy_test_allocator<T> self_t;
43 typedef void * aux_pointer_t;
44 typedef const void * cvoid_ptr;
47 dummy_test_allocator& operator=(const dummy_test_allocator<T2>&);
49 dummy_test_allocator& operator=(const dummy_test_allocator&);
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;
62 // typedef boost::interprocess::version_type<dummy_test_allocator, 2> version;
66 { typedef dummy_test_allocator<T2> other; };
68 //!Default constructor. Never throws
69 dummy_test_allocator()
72 //!Constructor from other dummy_test_allocator. Never throws
73 dummy_test_allocator(const dummy_test_allocator &)
76 //!Constructor from related dummy_test_allocator. Never throws
78 dummy_test_allocator(const dummy_test_allocator<T2> &)
81 pointer address(reference value)
82 { return pointer(addressof(value)); }
84 const_pointer address(const_reference value) const
85 { return const_pointer(addressof(value)); }
87 pointer allocate(size_type, cvoid_ptr = 0)
90 void deallocate(const pointer &, size_type)
93 template<class Convertible>
94 void construct(pointer, const Convertible &)
100 size_type max_size() const
103 friend void swap(self_t &, self_t &)
106 //Experimental version 2 dummy_test_allocator functions
108 pointer allocation_command(boost::interprocess::allocation_type,
109 size_type, size_type &, pointer &)
110 { return pointer(); }
112 //!Returns maximum the number of objects the previously allocated memory
113 //!pointed by p can hold.
114 size_type size(const pointer &) const
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(); }
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 &)
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> &)
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> &)
143 } //namespace interprocess {
144 } //namespace boost {
146 #include <boost/interprocess/detail/config_end.hpp>
148 #endif //BOOST_INTERPROCESS_DUMMY_TEST_ALLOCATOR_HPP