Chris@102
|
1 /*
|
Chris@102
|
2 * Copyright (c) 2014 Glen Joseph Fernandes
|
Chris@102
|
3 * glenfe at live dot com
|
Chris@102
|
4 *
|
Chris@102
|
5 * Distributed under the Boost Software License,
|
Chris@102
|
6 * Version 1.0. (See accompanying file LICENSE_1_0.txt
|
Chris@102
|
7 * or copy at http://boost.org/LICENSE_1_0.txt)
|
Chris@102
|
8 */
|
Chris@102
|
9 #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_COUNT_IMPL_HPP
|
Chris@102
|
10 #define BOOST_SMART_PTR_DETAIL_ARRAY_COUNT_IMPL_HPP
|
Chris@102
|
11
|
Chris@102
|
12 #include <boost/smart_ptr/detail/array_allocator.hpp>
|
Chris@102
|
13 #include <boost/smart_ptr/detail/sp_counted_impl.hpp>
|
Chris@102
|
14
|
Chris@102
|
15 namespace boost {
|
Chris@102
|
16 namespace detail {
|
Chris@102
|
17 template<class P, class A>
|
Chris@102
|
18 class sp_counted_impl_pda<P, ms_in_allocator_tag, A>
|
Chris@102
|
19 : public sp_counted_base {
|
Chris@102
|
20 typedef ms_in_allocator_tag D;
|
Chris@102
|
21 typedef sp_counted_impl_pda<P, D, A> Y;
|
Chris@102
|
22 public:
|
Chris@102
|
23 sp_counted_impl_pda(P, D, const A& allocator_)
|
Chris@102
|
24 : allocator(allocator_) {
|
Chris@102
|
25 }
|
Chris@102
|
26
|
Chris@102
|
27 virtual void dispose() {
|
Chris@102
|
28 allocator();
|
Chris@102
|
29 }
|
Chris@102
|
30
|
Chris@102
|
31 virtual void destroy() {
|
Chris@102
|
32 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
Chris@102
|
33 typedef typename std::allocator_traits<A>::
|
Chris@102
|
34 template rebind_alloc<Y> YA;
|
Chris@102
|
35 typedef typename std::allocator_traits<A>::
|
Chris@102
|
36 template rebind_traits<Y> YT;
|
Chris@102
|
37 #else
|
Chris@102
|
38 typedef typename A::template rebind<Y>::other YA;
|
Chris@102
|
39 #endif
|
Chris@102
|
40 YA a1(allocator);
|
Chris@102
|
41 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
Chris@102
|
42 YT::destroy(a1, this);
|
Chris@102
|
43 YT::deallocate(a1, this, 1);
|
Chris@102
|
44 #else
|
Chris@102
|
45 this->~Y();
|
Chris@102
|
46 a1.deallocate(this, 1);
|
Chris@102
|
47 #endif
|
Chris@102
|
48 }
|
Chris@102
|
49
|
Chris@102
|
50 virtual void* get_deleter(const sp_typeinfo&) {
|
Chris@102
|
51 return &reinterpret_cast<char&>(allocator);
|
Chris@102
|
52 }
|
Chris@102
|
53
|
Chris@102
|
54 virtual void* get_untyped_deleter() {
|
Chris@102
|
55 return &reinterpret_cast<char&>(allocator);
|
Chris@102
|
56 }
|
Chris@102
|
57
|
Chris@102
|
58 private:
|
Chris@102
|
59 sp_counted_impl_pda(const sp_counted_impl_pda&);
|
Chris@102
|
60 sp_counted_impl_pda& operator=(const sp_counted_impl_pda&);
|
Chris@102
|
61
|
Chris@102
|
62 A allocator;
|
Chris@102
|
63 };
|
Chris@102
|
64 }
|
Chris@102
|
65 }
|
Chris@102
|
66
|
Chris@102
|
67 #endif
|