1
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
2
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
4
// MS compatible compilers support #pragma once
6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
11
// detail/sp_counted_impl.hpp
13
// Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
14
// Copyright 2004-2005 Peter Dimov
16
// Distributed under the Boost Software License, Version 1.0. (See
17
// accompanying file LICENSE_1_0.txt or copy at
18
// http://www.boost.org/LICENSE_1_0.txt)
21
#include <boost/config.hpp>
23
#if defined(BOOST_SP_USE_STD_ALLOCATOR) && defined(BOOST_SP_USE_QUICK_ALLOCATOR)
24
# error BOOST_SP_USE_STD_ALLOCATOR and BOOST_SP_USE_QUICK_ALLOCATOR are incompatible.
27
#include <boost/checked_delete.hpp>
28
#include <boost/smart_ptr/detail/sp_counted_base.hpp>
30
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
31
#include <boost/smart_ptr/detail/quick_allocator.hpp>
34
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
35
#include <memory> // std::allocator
38
#include <cstddef> // std::size_t
43
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
45
void sp_scalar_constructor_hook( void * px, std::size_t size, void * pn );
46
void sp_scalar_destructor_hook( void * px, std::size_t size, void * pn );
53
template<class X> class sp_counted_impl_p: public sp_counted_base
59
sp_counted_impl_p( sp_counted_impl_p const & );
60
sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
62
typedef sp_counted_impl_p<X> this_type;
66
explicit sp_counted_impl_p( X * px ): px_( px )
68
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
69
boost::sp_scalar_constructor_hook( px, sizeof(X), this );
73
virtual void dispose() // nothrow
75
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
76
boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
78
boost::checked_delete( px_ );
81
virtual void * get_deleter( detail::sp_typeinfo const & )
86
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
88
void * operator new( std::size_t )
90
return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
93
void operator delete( void * p )
95
std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
100
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
102
void * operator new( std::size_t )
104
return quick_allocator<this_type>::alloc();
107
void operator delete( void * p )
109
quick_allocator<this_type>::dealloc( p );
116
// Borland's Codeguard trips up over the -Vx- option here:
119
# pragma option push -Vx-
122
template<class P, class D> class sp_counted_impl_pd: public sp_counted_base
126
P ptr; // copy constructor must not throw
127
D del; // copy constructor must not throw
129
sp_counted_impl_pd( sp_counted_impl_pd const & );
130
sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
132
typedef sp_counted_impl_pd<P, D> this_type;
136
// pre: d(p) must not throw
138
sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
142
virtual void dispose() // nothrow
147
virtual void * get_deleter( detail::sp_typeinfo const & ti )
149
return ti == BOOST_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
152
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
154
void * operator new( std::size_t )
156
return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
159
void operator delete( void * p )
161
std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
166
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
168
void * operator new( std::size_t )
170
return quick_allocator<this_type>::alloc();
173
void operator delete( void * p )
175
quick_allocator<this_type>::dealloc( p );
181
template<class P, class D, class A> class sp_counted_impl_pda: public sp_counted_base
185
P p_; // copy constructor must not throw
186
D d_; // copy constructor must not throw
187
A a_; // copy constructor must not throw
189
sp_counted_impl_pda( sp_counted_impl_pda const & );
190
sp_counted_impl_pda & operator= ( sp_counted_impl_pda const & );
192
typedef sp_counted_impl_pda<P, D, A> this_type;
196
// pre: d( p ) must not throw
198
sp_counted_impl_pda( P p, D d, A a ): p_( p ), d_( d ), a_( a )
202
virtual void dispose() // nothrow
207
virtual void destroy() // nothrow
209
typedef typename A::template rebind< this_type >::other A2;
214
a2.deallocate( this, 1 );
217
virtual void * get_deleter( detail::sp_typeinfo const & ti )
219
return ti == BOOST_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
227
} // namespace detail
231
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED