epoc32/include/stdapis/boost/detail/sp_counted_impl.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/detail/sp_counted_impl.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,232 @@
     1.4 +#ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
     1.5 +#define BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
     1.6 +
     1.7 +// MS compatible compilers support #pragma once
     1.8 +
     1.9 +#if defined(_MSC_VER) && (_MSC_VER >= 1020)
    1.10 +# pragma once
    1.11 +#endif
    1.12 +
    1.13 +//
    1.14 +//  detail/sp_counted_impl.hpp
    1.15 +//
    1.16 +//  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
    1.17 +//  Copyright 2004-2005 Peter Dimov
    1.18 +//
    1.19 +// Distributed under the Boost Software License, Version 1.0. (See
    1.20 +// accompanying file LICENSE_1_0.txt or copy at
    1.21 +// http://www.boost.org/LICENSE_1_0.txt)
    1.22 +//
    1.23 +
    1.24 +#include <boost/config.hpp>
    1.25 +
    1.26 +#if defined(BOOST_SP_USE_STD_ALLOCATOR) && defined(BOOST_SP_USE_QUICK_ALLOCATOR)
    1.27 +# error BOOST_SP_USE_STD_ALLOCATOR and BOOST_SP_USE_QUICK_ALLOCATOR are incompatible.
    1.28 +#endif
    1.29 +
    1.30 +#include <boost/checked_delete.hpp>
    1.31 +#include <boost/detail/sp_counted_base.hpp>
    1.32 +
    1.33 +#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
    1.34 +#include <boost/detail/quick_allocator.hpp>
    1.35 +#endif
    1.36 +
    1.37 +#if defined(BOOST_SP_USE_STD_ALLOCATOR)
    1.38 +#include <memory>           // std::allocator
    1.39 +#endif
    1.40 +
    1.41 +#include <typeinfo>         // std::type_info in get_deleter
    1.42 +#include <cstddef>          // std::size_t
    1.43 +
    1.44 +namespace boost
    1.45 +{
    1.46 +
    1.47 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
    1.48 +
    1.49 +void sp_scalar_constructor_hook( void * px, std::size_t size, void * pn );
    1.50 +void sp_scalar_destructor_hook( void * px, std::size_t size, void * pn );
    1.51 +
    1.52 +#endif
    1.53 +
    1.54 +namespace detail
    1.55 +{
    1.56 +
    1.57 +template<class X> class sp_counted_impl_p: public sp_counted_base
    1.58 +{
    1.59 +private:
    1.60 +
    1.61 +    X * px_;
    1.62 +
    1.63 +    sp_counted_impl_p( sp_counted_impl_p const & );
    1.64 +    sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
    1.65 +
    1.66 +    typedef sp_counted_impl_p<X> this_type;
    1.67 +
    1.68 +public:
    1.69 +
    1.70 +    explicit sp_counted_impl_p( X * px ): px_( px )
    1.71 +    {
    1.72 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
    1.73 +        boost::sp_scalar_constructor_hook( px, sizeof(X), this );
    1.74 +#endif
    1.75 +    }
    1.76 +
    1.77 +    virtual void dispose() // nothrow
    1.78 +    {
    1.79 +#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
    1.80 +        boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
    1.81 +#endif
    1.82 +        boost::checked_delete( px_ );
    1.83 +    }
    1.84 +
    1.85 +    virtual void * get_deleter( std::type_info const & )
    1.86 +    {
    1.87 +        return 0;
    1.88 +    }
    1.89 +
    1.90 +#if defined(BOOST_SP_USE_STD_ALLOCATOR)
    1.91 +
    1.92 +    void * operator new( std::size_t )
    1.93 +    {
    1.94 +        return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
    1.95 +    }
    1.96 +
    1.97 +    void operator delete( void * p )
    1.98 +    {
    1.99 +        std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
   1.100 +    }
   1.101 +
   1.102 +#endif
   1.103 +
   1.104 +#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
   1.105 +
   1.106 +    void * operator new( std::size_t )
   1.107 +    {
   1.108 +        return quick_allocator<this_type>::alloc();
   1.109 +    }
   1.110 +
   1.111 +    void operator delete( void * p )
   1.112 +    {
   1.113 +        quick_allocator<this_type>::dealloc( p );
   1.114 +    }
   1.115 +
   1.116 +#endif
   1.117 +};
   1.118 +
   1.119 +//
   1.120 +// Borland's Codeguard trips up over the -Vx- option here:
   1.121 +//
   1.122 +#ifdef __CODEGUARD__
   1.123 +# pragma option push -Vx-
   1.124 +#endif
   1.125 +
   1.126 +template<class P, class D> class sp_counted_impl_pd: public sp_counted_base
   1.127 +{
   1.128 +private:
   1.129 +
   1.130 +    P ptr; // copy constructor must not throw
   1.131 +    D del; // copy constructor must not throw
   1.132 +
   1.133 +    sp_counted_impl_pd( sp_counted_impl_pd const & );
   1.134 +    sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
   1.135 +
   1.136 +    typedef sp_counted_impl_pd<P, D> this_type;
   1.137 +
   1.138 +public:
   1.139 +
   1.140 +    // pre: d(p) must not throw
   1.141 +
   1.142 +    sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
   1.143 +    {
   1.144 +    }
   1.145 +
   1.146 +    virtual void dispose() // nothrow
   1.147 +    {
   1.148 +        del( ptr );
   1.149 +    }
   1.150 +
   1.151 +    virtual void * get_deleter( std::type_info const & ti )
   1.152 +    {
   1.153 +        return ti == typeid(D)? &del: 0;
   1.154 +    }
   1.155 +
   1.156 +#if defined(BOOST_SP_USE_STD_ALLOCATOR)
   1.157 +
   1.158 +    void * operator new( std::size_t )
   1.159 +    {
   1.160 +        return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
   1.161 +    }
   1.162 +
   1.163 +    void operator delete( void * p )
   1.164 +    {
   1.165 +        std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
   1.166 +    }
   1.167 +
   1.168 +#endif
   1.169 +
   1.170 +#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
   1.171 +
   1.172 +    void * operator new( std::size_t )
   1.173 +    {
   1.174 +        return quick_allocator<this_type>::alloc();
   1.175 +    }
   1.176 +
   1.177 +    void operator delete( void * p )
   1.178 +    {
   1.179 +        quick_allocator<this_type>::dealloc( p );
   1.180 +    }
   1.181 +
   1.182 +#endif
   1.183 +};
   1.184 +
   1.185 +template<class P, class D, class A> class sp_counted_impl_pda: public sp_counted_base
   1.186 +{
   1.187 +private:
   1.188 +
   1.189 +    P p_; // copy constructor must not throw
   1.190 +    D d_; // copy constructor must not throw
   1.191 +    A a_; // copy constructor must not throw
   1.192 +
   1.193 +    sp_counted_impl_pda( sp_counted_impl_pda const & );
   1.194 +    sp_counted_impl_pda & operator= ( sp_counted_impl_pda const & );
   1.195 +
   1.196 +    typedef sp_counted_impl_pda<P, D, A> this_type;
   1.197 +
   1.198 +public:
   1.199 +
   1.200 +    // pre: d( p ) must not throw
   1.201 +
   1.202 +    sp_counted_impl_pda( P p, D d, A a ): p_( p ), d_( d ), a_( a )
   1.203 +    {
   1.204 +    }
   1.205 +
   1.206 +    virtual void dispose() // nothrow
   1.207 +    {
   1.208 +        d_( p_ );
   1.209 +    }
   1.210 +
   1.211 +    virtual void destroy() // nothrow
   1.212 +    {
   1.213 +        typedef typename A::template rebind< this_type >::other A2;
   1.214 +
   1.215 +        A2 a2( a_ );
   1.216 +
   1.217 +        this->~this_type();
   1.218 +        a2.deallocate( this, 1 );
   1.219 +    }
   1.220 +
   1.221 +    virtual void * get_deleter( std::type_info const & ti )
   1.222 +    {
   1.223 +        return ti == typeid( D )? &d_: 0;
   1.224 +    }
   1.225 +};
   1.226 +
   1.227 +#ifdef __CODEGUARD__
   1.228 +# pragma option pop
   1.229 +#endif
   1.230 +
   1.231 +} // namespace detail
   1.232 +
   1.233 +} // namespace boost
   1.234 +
   1.235 +#endif  // #ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED