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