epoc32/include/stdapis/boost/detail/sp_counted_impl.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
#ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
williamr@2
     2
#define BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
williamr@2
     3
williamr@2
     4
// MS compatible compilers support #pragma once
williamr@2
     5
williamr@2
     6
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
williamr@2
     7
# pragma once
williamr@2
     8
#endif
williamr@2
     9
williamr@2
    10
//
williamr@2
    11
//  detail/sp_counted_impl.hpp
williamr@2
    12
//
williamr@2
    13
//  Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
williamr@2
    14
//  Copyright 2004-2005 Peter Dimov
williamr@2
    15
//
williamr@2
    16
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
    17
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
    18
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
    19
//
williamr@2
    20
williamr@2
    21
#include <boost/config.hpp>
williamr@2
    22
williamr@2
    23
#if defined(BOOST_SP_USE_STD_ALLOCATOR) && defined(BOOST_SP_USE_QUICK_ALLOCATOR)
williamr@2
    24
# error BOOST_SP_USE_STD_ALLOCATOR and BOOST_SP_USE_QUICK_ALLOCATOR are incompatible.
williamr@2
    25
#endif
williamr@2
    26
williamr@2
    27
#include <boost/checked_delete.hpp>
williamr@2
    28
#include <boost/detail/sp_counted_base.hpp>
williamr@2
    29
williamr@2
    30
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
williamr@2
    31
#include <boost/detail/quick_allocator.hpp>
williamr@2
    32
#endif
williamr@2
    33
williamr@2
    34
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
williamr@2
    35
#include <memory>           // std::allocator
williamr@2
    36
#endif
williamr@2
    37
williamr@2
    38
#include <typeinfo>         // std::type_info in get_deleter
williamr@2
    39
#include <cstddef>          // std::size_t
williamr@2
    40
williamr@2
    41
namespace boost
williamr@2
    42
{
williamr@2
    43
williamr@2
    44
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
williamr@2
    45
williamr@2
    46
void sp_scalar_constructor_hook( void * px, std::size_t size, void * pn );
williamr@2
    47
void sp_scalar_destructor_hook( void * px, std::size_t size, void * pn );
williamr@2
    48
williamr@2
    49
#endif
williamr@2
    50
williamr@2
    51
namespace detail
williamr@2
    52
{
williamr@2
    53
williamr@2
    54
template<class X> class sp_counted_impl_p: public sp_counted_base
williamr@2
    55
{
williamr@2
    56
private:
williamr@2
    57
williamr@2
    58
    X * px_;
williamr@2
    59
williamr@2
    60
    sp_counted_impl_p( sp_counted_impl_p const & );
williamr@2
    61
    sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
williamr@2
    62
williamr@2
    63
    typedef sp_counted_impl_p<X> this_type;
williamr@2
    64
williamr@2
    65
public:
williamr@2
    66
williamr@2
    67
    explicit sp_counted_impl_p( X * px ): px_( px )
williamr@2
    68
    {
williamr@2
    69
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
williamr@2
    70
        boost::sp_scalar_constructor_hook( px, sizeof(X), this );
williamr@2
    71
#endif
williamr@2
    72
    }
williamr@2
    73
williamr@2
    74
    virtual void dispose() // nothrow
williamr@2
    75
    {
williamr@2
    76
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
williamr@2
    77
        boost::sp_scalar_destructor_hook( px_, sizeof(X), this );
williamr@2
    78
#endif
williamr@2
    79
        boost::checked_delete( px_ );
williamr@2
    80
    }
williamr@2
    81
williamr@2
    82
    virtual void * get_deleter( std::type_info const & )
williamr@2
    83
    {
williamr@2
    84
        return 0;
williamr@2
    85
    }
williamr@2
    86
williamr@2
    87
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
williamr@2
    88
williamr@2
    89
    void * operator new( std::size_t )
williamr@2
    90
    {
williamr@2
    91
        return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
williamr@2
    92
    }
williamr@2
    93
williamr@2
    94
    void operator delete( void * p )
williamr@2
    95
    {
williamr@2
    96
        std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
williamr@2
    97
    }
williamr@2
    98
williamr@2
    99
#endif
williamr@2
   100
williamr@2
   101
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
williamr@2
   102
williamr@2
   103
    void * operator new( std::size_t )
williamr@2
   104
    {
williamr@2
   105
        return quick_allocator<this_type>::alloc();
williamr@2
   106
    }
williamr@2
   107
williamr@2
   108
    void operator delete( void * p )
williamr@2
   109
    {
williamr@2
   110
        quick_allocator<this_type>::dealloc( p );
williamr@2
   111
    }
williamr@2
   112
williamr@2
   113
#endif
williamr@2
   114
};
williamr@2
   115
williamr@2
   116
//
williamr@2
   117
// Borland's Codeguard trips up over the -Vx- option here:
williamr@2
   118
//
williamr@2
   119
#ifdef __CODEGUARD__
williamr@2
   120
# pragma option push -Vx-
williamr@2
   121
#endif
williamr@2
   122
williamr@2
   123
template<class P, class D> class sp_counted_impl_pd: public sp_counted_base
williamr@2
   124
{
williamr@2
   125
private:
williamr@2
   126
williamr@2
   127
    P ptr; // copy constructor must not throw
williamr@2
   128
    D del; // copy constructor must not throw
williamr@2
   129
williamr@2
   130
    sp_counted_impl_pd( sp_counted_impl_pd const & );
williamr@2
   131
    sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
williamr@2
   132
williamr@2
   133
    typedef sp_counted_impl_pd<P, D> this_type;
williamr@2
   134
williamr@2
   135
public:
williamr@2
   136
williamr@2
   137
    // pre: d(p) must not throw
williamr@2
   138
williamr@2
   139
    sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
williamr@2
   140
    {
williamr@2
   141
    }
williamr@2
   142
williamr@2
   143
    virtual void dispose() // nothrow
williamr@2
   144
    {
williamr@2
   145
        del( ptr );
williamr@2
   146
    }
williamr@2
   147
williamr@2
   148
    virtual void * get_deleter( std::type_info const & ti )
williamr@2
   149
    {
williamr@2
   150
        return ti == typeid(D)? &del: 0;
williamr@2
   151
    }
williamr@2
   152
williamr@2
   153
#if defined(BOOST_SP_USE_STD_ALLOCATOR)
williamr@2
   154
williamr@2
   155
    void * operator new( std::size_t )
williamr@2
   156
    {
williamr@2
   157
        return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
williamr@2
   158
    }
williamr@2
   159
williamr@2
   160
    void operator delete( void * p )
williamr@2
   161
    {
williamr@2
   162
        std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
williamr@2
   163
    }
williamr@2
   164
williamr@2
   165
#endif
williamr@2
   166
williamr@2
   167
#if defined(BOOST_SP_USE_QUICK_ALLOCATOR)
williamr@2
   168
williamr@2
   169
    void * operator new( std::size_t )
williamr@2
   170
    {
williamr@2
   171
        return quick_allocator<this_type>::alloc();
williamr@2
   172
    }
williamr@2
   173
williamr@2
   174
    void operator delete( void * p )
williamr@2
   175
    {
williamr@2
   176
        quick_allocator<this_type>::dealloc( p );
williamr@2
   177
    }
williamr@2
   178
williamr@2
   179
#endif
williamr@2
   180
};
williamr@2
   181
williamr@2
   182
template<class P, class D, class A> class sp_counted_impl_pda: public sp_counted_base
williamr@2
   183
{
williamr@2
   184
private:
williamr@2
   185
williamr@2
   186
    P p_; // copy constructor must not throw
williamr@2
   187
    D d_; // copy constructor must not throw
williamr@2
   188
    A a_; // copy constructor must not throw
williamr@2
   189
williamr@2
   190
    sp_counted_impl_pda( sp_counted_impl_pda const & );
williamr@2
   191
    sp_counted_impl_pda & operator= ( sp_counted_impl_pda const & );
williamr@2
   192
williamr@2
   193
    typedef sp_counted_impl_pda<P, D, A> this_type;
williamr@2
   194
williamr@2
   195
public:
williamr@2
   196
williamr@2
   197
    // pre: d( p ) must not throw
williamr@2
   198
williamr@2
   199
    sp_counted_impl_pda( P p, D d, A a ): p_( p ), d_( d ), a_( a )
williamr@2
   200
    {
williamr@2
   201
    }
williamr@2
   202
williamr@2
   203
    virtual void dispose() // nothrow
williamr@2
   204
    {
williamr@2
   205
        d_( p_ );
williamr@2
   206
    }
williamr@2
   207
williamr@2
   208
    virtual void destroy() // nothrow
williamr@2
   209
    {
williamr@2
   210
        typedef typename A::template rebind< this_type >::other A2;
williamr@2
   211
williamr@2
   212
        A2 a2( a_ );
williamr@2
   213
williamr@2
   214
        this->~this_type();
williamr@2
   215
        a2.deallocate( this, 1 );
williamr@2
   216
    }
williamr@2
   217
williamr@2
   218
    virtual void * get_deleter( std::type_info const & ti )
williamr@2
   219
    {
williamr@2
   220
        return ti == typeid( D )? &d_: 0;
williamr@2
   221
    }
williamr@2
   222
};
williamr@2
   223
williamr@2
   224
#ifdef __CODEGUARD__
williamr@2
   225
# pragma option pop
williamr@2
   226
#endif
williamr@2
   227
williamr@2
   228
} // namespace detail
williamr@2
   229
williamr@2
   230
} // namespace boost
williamr@2
   231
williamr@2
   232
#endif  // #ifndef BOOST_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED