1 #ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
2 #define BOOST_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/detail/sp_counted_base.hpp>
30 #if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
31 #include <boost/detail/quick_allocator.hpp>
34 #include <memory> // std::allocator
35 #include <typeinfo> // std::type_info in get_deleter
36 #include <cstddef> // std::size_t
41 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
43 void sp_scalar_constructor_hook( void * px, std::size_t size, void * pn );
44 void sp_scalar_destructor_hook( void * px, std::size_t size, void * pn );
51 template<class X> class sp_counted_impl_p: public sp_counted_base
57 sp_counted_impl_p( sp_counted_impl_p const & );
58 sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
60 typedef sp_counted_impl_p<X> this_type;
64 explicit sp_counted_impl_p( X * px ): px_( px )
66 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
67 boost::sp_scalar_constructor_hook( px, sizeof(X), this );
71 virtual void dispose() // nothrow
73 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
74 boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
76 boost::checked_delete( px_ );
79 virtual void * get_deleter( std::type_info const & )
84 #if defined(BOOST_SP_USE_STD_ALLOCATOR)
86 void * operator new( std::size_t )
88 return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
91 void operator delete( void * p )
93 std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
98 #if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
100 void * operator new( std::size_t )
102 return quick_allocator<this_type>::alloc();
105 void operator delete( void * p )
107 quick_allocator<this_type>::dealloc( p );
114 // Borland's Codeguard trips up over the -Vx- option here:
117 # pragma option push -Vx-
120 template<class P, class D> class sp_counted_impl_pd: public sp_counted_base
124 P ptr; // copy constructor must not throw
125 D del; // copy constructor must not throw
127 sp_counted_impl_pd( sp_counted_impl_pd const & );
128 sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
130 typedef sp_counted_impl_pd<P, D> this_type;
134 // pre: d(p) must not throw
136 sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
140 virtual void dispose() // nothrow
145 virtual void * get_deleter( std::type_info const & ti )
147 return ti == typeid(D)? &del: 0;
150 #if defined(BOOST_SP_USE_STD_ALLOCATOR)
152 void * operator new( std::size_t )
154 return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
157 void operator delete( void * p )
159 std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
164 #if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
166 void * operator new( std::size_t )
168 return quick_allocator<this_type>::alloc();
171 void operator delete( void * p )
173 quick_allocator<this_type>::dealloc( p );
183 } // namespace detail
187 #endif // #ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED