1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2009.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/container for documentation.
11 //////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_CONTAINERS_DESTROYERS_HPP
14 #define BOOST_CONTAINERS_DESTROYERS_HPP
16 #if (defined _MSC_VER) && (_MSC_VER >= 1200)
20 #include <boost/interprocess/containers/container/detail/config_begin.hpp>
21 #include <boost/interprocess/containers/container/detail/workaround.hpp>
22 #include <boost/interprocess/containers/container/detail/version_type.hpp>
23 #include <boost/interprocess/containers/container/detail/utilities.hpp>
26 namespace interprocess_container
{
27 namespace containers_detail
{
29 //!A deleter for scoped_ptr that deallocates the memory
30 //!allocated for an array of objects using a STL allocator.
31 template <class Allocator
>
32 struct scoped_array_deallocator
34 typedef typename
Allocator::pointer pointer
;
35 typedef typename
Allocator::size_type size_type
;
37 scoped_array_deallocator(pointer p
, Allocator
& a
, size_type length
)
38 : m_ptr(p
), m_alloc(a
), m_length(length
) {}
40 ~scoped_array_deallocator()
41 { if (m_ptr
) m_alloc
.deallocate(m_ptr
, m_length
); }
52 template <class Allocator
>
53 struct null_scoped_array_deallocator
55 typedef typename
Allocator::pointer pointer
;
56 typedef typename
Allocator::size_type size_type
;
58 null_scoped_array_deallocator(pointer
, Allocator
&, size_type
)
66 //!A deleter for scoped_ptr that destroys
67 //!an object using a STL allocator.
68 template <class Allocator
>
69 struct scoped_destructor_n
71 typedef typename
Allocator::pointer pointer
;
72 typedef typename
Allocator::value_type value_type
;
73 typedef typename
Allocator::size_type size_type
;
78 scoped_destructor_n(pointer p
, size_type n
)
85 void increment_size(size_type inc
)
88 ~scoped_destructor_n()
91 value_type
*raw_ptr
= containers_detail::get_pointer(m_p
);
92 for(std::size_t i
= 0; i
< m_n
; ++i
, ++raw_ptr
)
93 raw_ptr
->~value_type();
97 //!A deleter for scoped_ptr that destroys
98 //!an object using a STL allocator.
99 template <class Allocator
>
100 struct null_scoped_destructor_n
102 typedef typename
Allocator::pointer pointer
;
103 typedef typename
Allocator::size_type size_type
;
105 null_scoped_destructor_n(pointer
, size_type
)
108 void increment_size(size_type
)
116 class allocator_destroyer
118 typedef typename
A::value_type value_type
;
119 typedef containers_detail::integral_constant
<unsigned,
120 boost::interprocess_container::containers_detail::
121 version
<A
>::value
> alloc_version
;
122 typedef containers_detail::integral_constant
<unsigned, 1> allocator_v1
;
123 typedef containers_detail::integral_constant
<unsigned, 2> allocator_v2
;
129 void priv_deallocate(const typename
A::pointer
&p
, allocator_v1
)
130 { a_
.deallocate(p
, 1); }
132 void priv_deallocate(const typename
A::pointer
&p
, allocator_v2
)
133 { a_
.deallocate_one(p
); }
136 allocator_destroyer(A
&a
)
140 void operator()(const typename
A::pointer
&p
)
142 containers_detail::get_pointer(p
)->~value_type();
143 priv_deallocate(p
, alloc_version());
148 } //namespace containers_detail {
149 } //namespace interprocess_container {
150 } //namespace boost {
152 #include <boost/interprocess/containers/container/detail/config_end.hpp>
154 #endif //#ifndef BOOST_CONTAINERS_DESTROYERS_HPP