epoc32/include/stdapis/boost/shared_ptr.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/shared_ptr.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,558 @@
     1.4 +#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
     1.5 +#define BOOST_SHARED_PTR_HPP_INCLUDED
     1.6 +
     1.7 +//
     1.8 +//  shared_ptr.hpp
     1.9 +//
    1.10 +//  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
    1.11 +//  Copyright (c) 2001-2006 Peter Dimov
    1.12 +//
    1.13 +//  Distributed under the Boost Software License, Version 1.0. (See
    1.14 +//  accompanying file LICENSE_1_0.txt or copy at
    1.15 +//  http://www.boost.org/LICENSE_1_0.txt)
    1.16 +//
    1.17 +//  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
    1.18 +//
    1.19 +
    1.20 +#include <boost/config.hpp>   // for broken compiler workarounds
    1.21 +
    1.22 +#if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
    1.23 +#include <boost/detail/shared_ptr_nmt.hpp>
    1.24 +#else
    1.25 +
    1.26 +#include <memory>               // for std::auto_ptr
    1.27 +
    1.28 +#include <boost/assert.hpp>
    1.29 +#include <boost/checked_delete.hpp>
    1.30 +#include <boost/throw_exception.hpp>
    1.31 +#include <boost/detail/shared_count.hpp>
    1.32 +#include <boost/detail/workaround.hpp>
    1.33 +
    1.34 +#include <algorithm>            // for std::swap
    1.35 +#include <functional>           // for std::less
    1.36 +#include <typeinfo>             // for std::bad_cast
    1.37 +#include <iosfwd>               // for std::basic_ostream
    1.38 +
    1.39 +#ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash
    1.40 +# pragma warning(push)
    1.41 +# pragma warning(disable:4284) // odd return type for operator->
    1.42 +#endif
    1.43 +
    1.44 +namespace boost
    1.45 +{
    1.46 +
    1.47 +template<class T> class weak_ptr;
    1.48 +template<class T> class enable_shared_from_this;
    1.49 +
    1.50 +namespace detail
    1.51 +{
    1.52 +
    1.53 +struct static_cast_tag {};
    1.54 +struct const_cast_tag {};
    1.55 +struct dynamic_cast_tag {};
    1.56 +struct polymorphic_cast_tag {};
    1.57 +
    1.58 +template<class T> struct shared_ptr_traits
    1.59 +{
    1.60 +    typedef T & reference;
    1.61 +};
    1.62 +
    1.63 +template<> struct shared_ptr_traits<void>
    1.64 +{
    1.65 +    typedef void reference;
    1.66 +};
    1.67 +
    1.68 +#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
    1.69 +
    1.70 +template<> struct shared_ptr_traits<void const>
    1.71 +{
    1.72 +    typedef void reference;
    1.73 +};
    1.74 +
    1.75 +template<> struct shared_ptr_traits<void volatile>
    1.76 +{
    1.77 +    typedef void reference;
    1.78 +};
    1.79 +
    1.80 +template<> struct shared_ptr_traits<void const volatile>
    1.81 +{
    1.82 +    typedef void reference;
    1.83 +};
    1.84 +
    1.85 +#endif
    1.86 +
    1.87 +// enable_shared_from_this support
    1.88 +
    1.89 +template<class T, class Y> void sp_enable_shared_from_this( shared_count const & pn, boost::enable_shared_from_this<T> const * pe, Y const * px )
    1.90 +{
    1.91 +    if(pe != 0) pe->_internal_weak_this._internal_assign(const_cast<Y*>(px), pn);
    1.92 +}
    1.93 +
    1.94 +#ifdef sgi
    1.95 +// Turn off: the last argument of the varargs function "sp_enable_shared_from_this" is unnamed
    1.96 +# pragma set woff 3506
    1.97 +#endif
    1.98 +
    1.99 +inline void sp_enable_shared_from_this( shared_count const & /*pn*/, ... )
   1.100 +{
   1.101 +}
   1.102 +
   1.103 +#ifdef sgi
   1.104 +# pragma reset woff 3506
   1.105 +#endif
   1.106 +
   1.107 +#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
   1.108 +
   1.109 +// rvalue auto_ptr support based on a technique by Dave Abrahams
   1.110 +
   1.111 +template< class T, class R > struct sp_enable_if_auto_ptr
   1.112 +{
   1.113 +};
   1.114 +
   1.115 +template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
   1.116 +{
   1.117 +    typedef R type;
   1.118 +}; 
   1.119 +
   1.120 +#endif
   1.121 +
   1.122 +} // namespace detail
   1.123 +
   1.124 +
   1.125 +//
   1.126 +//  shared_ptr
   1.127 +//
   1.128 +//  An enhanced relative of scoped_ptr with reference counted copy semantics.
   1.129 +//  The object pointed to is deleted when the last shared_ptr pointing to it
   1.130 +//  is destroyed or reset.
   1.131 +//
   1.132 +
   1.133 +template<class T> class shared_ptr
   1.134 +{
   1.135 +private:
   1.136 +
   1.137 +    // Borland 5.5.1 specific workaround
   1.138 +    typedef shared_ptr<T> this_type;
   1.139 +
   1.140 +public:
   1.141 +
   1.142 +    typedef T element_type;
   1.143 +    typedef T value_type;
   1.144 +    typedef T * pointer;
   1.145 +    typedef typename boost::detail::shared_ptr_traits<T>::reference reference;
   1.146 +
   1.147 +    shared_ptr(): px(0), pn() // never throws in 1.30+
   1.148 +    {
   1.149 +    }
   1.150 +
   1.151 +    template<class Y>
   1.152 +    explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
   1.153 +    {
   1.154 +        boost::detail::sp_enable_shared_from_this( pn, p, p );
   1.155 +    }
   1.156 +
   1.157 +    //
   1.158 +    // Requirements: D's copy constructor must not throw
   1.159 +    //
   1.160 +    // shared_ptr will release p by calling d(p)
   1.161 +    //
   1.162 +
   1.163 +    template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
   1.164 +    {
   1.165 +        boost::detail::sp_enable_shared_from_this( pn, p, p );
   1.166 +    }
   1.167 +
   1.168 +    // As above, but with allocator. A's copy constructor shall not throw.
   1.169 +
   1.170 +    template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
   1.171 +    {
   1.172 +        boost::detail::sp_enable_shared_from_this( pn, p, p );
   1.173 +    }
   1.174 +
   1.175 +//  generated copy constructor, assignment, destructor are fine...
   1.176 +
   1.177 +//  except that Borland C++ has a bug, and g++ with -Wsynth warns
   1.178 +#if defined(__BORLANDC__) || defined(__GNUC__)
   1.179 +
   1.180 +    shared_ptr & operator=(shared_ptr const & r) // never throws
   1.181 +    {
   1.182 +        px = r.px;
   1.183 +        pn = r.pn; // shared_count::op= doesn't throw
   1.184 +        return *this;
   1.185 +    }
   1.186 +
   1.187 +#endif
   1.188 +
   1.189 +    template<class Y>
   1.190 +    explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
   1.191 +    {
   1.192 +        // it is now safe to copy r.px, as pn(r.pn) did not throw
   1.193 +        px = r.px;
   1.194 +    }
   1.195 +
   1.196 +    template<class Y>
   1.197 +    shared_ptr(shared_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
   1.198 +    {
   1.199 +    }
   1.200 +
   1.201 +    template<class Y>
   1.202 +    shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
   1.203 +    {
   1.204 +    }
   1.205 +
   1.206 +    template<class Y>
   1.207 +    shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
   1.208 +    {
   1.209 +    }
   1.210 +
   1.211 +    template<class Y>
   1.212 +    shared_ptr(shared_ptr<Y> const & r, boost::detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
   1.213 +    {
   1.214 +        if(px == 0) // need to allocate new counter -- the cast failed
   1.215 +        {
   1.216 +            pn = boost::detail::shared_count();
   1.217 +        }
   1.218 +    }
   1.219 +
   1.220 +    template<class Y>
   1.221 +    shared_ptr(shared_ptr<Y> const & r, boost::detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
   1.222 +    {
   1.223 +        if(px == 0)
   1.224 +        {
   1.225 +            boost::throw_exception(std::bad_cast());
   1.226 +        }
   1.227 +    }
   1.228 +
   1.229 +#ifndef BOOST_NO_AUTO_PTR
   1.230 +
   1.231 +    template<class Y>
   1.232 +    explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
   1.233 +    {
   1.234 +        Y * tmp = r.get();
   1.235 +        pn = boost::detail::shared_count(r);
   1.236 +        boost::detail::sp_enable_shared_from_this( pn, tmp, tmp );
   1.237 +    }
   1.238 +
   1.239 +#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
   1.240 +
   1.241 +    template<class Ap>
   1.242 +    explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
   1.243 +    {
   1.244 +        typename Ap::element_type * tmp = r.get();
   1.245 +        pn = boost::detail::shared_count( r );
   1.246 +        boost::detail::sp_enable_shared_from_this( pn, tmp, tmp );
   1.247 +    }
   1.248 +
   1.249 +
   1.250 +#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.251 +
   1.252 +#endif // BOOST_NO_AUTO_PTR
   1.253 +
   1.254 +#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300)
   1.255 +
   1.256 +    template<class Y>
   1.257 +    shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
   1.258 +    {
   1.259 +        px = r.px;
   1.260 +        pn = r.pn; // shared_count::op= doesn't throw
   1.261 +        return *this;
   1.262 +    }
   1.263 +
   1.264 +#endif
   1.265 +
   1.266 +#ifndef BOOST_NO_AUTO_PTR
   1.267 +
   1.268 +    template<class Y>
   1.269 +    shared_ptr & operator=( std::auto_ptr<Y> & r )
   1.270 +    {
   1.271 +        this_type(r).swap(*this);
   1.272 +        return *this;
   1.273 +    }
   1.274 +
   1.275 +#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
   1.276 +
   1.277 +    template<class Ap>
   1.278 +    typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
   1.279 +    {
   1.280 +        this_type( r ).swap( *this );
   1.281 +        return *this;
   1.282 +    }
   1.283 +
   1.284 +
   1.285 +#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.286 +
   1.287 +#endif // BOOST_NO_AUTO_PTR
   1.288 +
   1.289 +    void reset() // never throws in 1.30+
   1.290 +    {
   1.291 +        this_type().swap(*this);
   1.292 +    }
   1.293 +
   1.294 +    template<class Y> void reset(Y * p) // Y must be complete
   1.295 +    {
   1.296 +        BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
   1.297 +        this_type(p).swap(*this);
   1.298 +    }
   1.299 +
   1.300 +    template<class Y, class D> void reset( Y * p, D d )
   1.301 +    {
   1.302 +        this_type( p, d ).swap( *this );
   1.303 +    }
   1.304 +
   1.305 +    template<class Y, class D, class A> void reset( Y * p, D d, A a )
   1.306 +    {
   1.307 +        this_type( p, d, a ).swap( *this );
   1.308 +    }
   1.309 +
   1.310 +    reference operator* () const // never throws
   1.311 +    {
   1.312 +        BOOST_ASSERT(px != 0);
   1.313 +        return *px;
   1.314 +    }
   1.315 +
   1.316 +    T * operator-> () const // never throws
   1.317 +    {
   1.318 +        BOOST_ASSERT(px != 0);
   1.319 +        return px;
   1.320 +    }
   1.321 +    
   1.322 +    T * get() const // never throws
   1.323 +    {
   1.324 +        return px;
   1.325 +    }
   1.326 +
   1.327 +    // implicit conversion to "bool"
   1.328 +
   1.329 +#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
   1.330 +
   1.331 +    operator bool () const
   1.332 +    {
   1.333 +        return px != 0;
   1.334 +    }
   1.335 +
   1.336 +#elif defined( _MANAGED )
   1.337 +
   1.338 +    static void unspecified_bool( this_type*** )
   1.339 +    {
   1.340 +    }
   1.341 +
   1.342 +    typedef void (*unspecified_bool_type)( this_type*** );
   1.343 +
   1.344 +    operator unspecified_bool_type() const // never throws
   1.345 +    {
   1.346 +        return px == 0? 0: unspecified_bool;
   1.347 +    }
   1.348 +
   1.349 +#elif \
   1.350 +    ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
   1.351 +    ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) )
   1.352 +
   1.353 +    typedef T * (this_type::*unspecified_bool_type)() const;
   1.354 +    
   1.355 +    operator unspecified_bool_type() const // never throws
   1.356 +    {
   1.357 +        return px == 0? 0: &this_type::get;
   1.358 +    }
   1.359 +
   1.360 +#else 
   1.361 +
   1.362 +    typedef T * this_type::*unspecified_bool_type;
   1.363 +
   1.364 +    operator unspecified_bool_type() const // never throws
   1.365 +    {
   1.366 +        return px == 0? 0: &this_type::px;
   1.367 +    }
   1.368 +
   1.369 +#endif
   1.370 +
   1.371 +    // operator! is redundant, but some compilers need it
   1.372 +
   1.373 +    bool operator! () const // never throws
   1.374 +    {
   1.375 +        return px == 0;
   1.376 +    }
   1.377 +
   1.378 +    bool unique() const // never throws
   1.379 +    {
   1.380 +        return pn.unique();
   1.381 +    }
   1.382 +
   1.383 +    long use_count() const // never throws
   1.384 +    {
   1.385 +        return pn.use_count();
   1.386 +    }
   1.387 +
   1.388 +    void swap(shared_ptr<T> & other) // never throws
   1.389 +    {
   1.390 +        std::swap(px, other.px);
   1.391 +        pn.swap(other.pn);
   1.392 +    }
   1.393 +
   1.394 +    template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
   1.395 +    {
   1.396 +        return pn < rhs.pn;
   1.397 +    }
   1.398 +
   1.399 +    void * _internal_get_deleter(std::type_info const & ti) const
   1.400 +    {
   1.401 +        return pn.get_deleter(ti);
   1.402 +    }
   1.403 +
   1.404 +// Tasteless as this may seem, making all members public allows member templates
   1.405 +// to work in the absence of member template friends. (Matthew Langston)
   1.406 +
   1.407 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
   1.408 +
   1.409 +private:
   1.410 +
   1.411 +    template<class Y> friend class shared_ptr;
   1.412 +    template<class Y> friend class weak_ptr;
   1.413 +
   1.414 +
   1.415 +#endif
   1.416 +
   1.417 +    T * px;                     // contained pointer
   1.418 +    boost::detail::shared_count pn;    // reference counter
   1.419 +
   1.420 +};  // shared_ptr
   1.421 +
   1.422 +template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
   1.423 +{
   1.424 +    return a.get() == b.get();
   1.425 +}
   1.426 +
   1.427 +template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)
   1.428 +{
   1.429 +    return a.get() != b.get();
   1.430 +}
   1.431 +
   1.432 +#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
   1.433 +
   1.434 +// Resolve the ambiguity between our op!= and the one in rel_ops
   1.435 +
   1.436 +template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)
   1.437 +{
   1.438 +    return a.get() != b.get();
   1.439 +}
   1.440 +
   1.441 +#endif
   1.442 +
   1.443 +template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
   1.444 +{
   1.445 +    return a._internal_less(b);
   1.446 +}
   1.447 +
   1.448 +template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
   1.449 +{
   1.450 +    a.swap(b);
   1.451 +}
   1.452 +
   1.453 +template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
   1.454 +{
   1.455 +    return shared_ptr<T>(r, boost::detail::static_cast_tag());
   1.456 +}
   1.457 +
   1.458 +template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
   1.459 +{
   1.460 +    return shared_ptr<T>(r, boost::detail::const_cast_tag());
   1.461 +}
   1.462 +
   1.463 +template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
   1.464 +{
   1.465 +    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
   1.466 +}
   1.467 +
   1.468 +// shared_*_cast names are deprecated. Use *_pointer_cast instead.
   1.469 +
   1.470 +template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r)
   1.471 +{
   1.472 +    return shared_ptr<T>(r, boost::detail::static_cast_tag());
   1.473 +}
   1.474 +
   1.475 +template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
   1.476 +{
   1.477 +    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
   1.478 +}
   1.479 +
   1.480 +template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)
   1.481 +{
   1.482 +    return shared_ptr<T>(r, boost::detail::polymorphic_cast_tag());
   1.483 +}
   1.484 +
   1.485 +template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
   1.486 +{
   1.487 +    BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
   1.488 +    return shared_static_cast<T>(r);
   1.489 +}
   1.490 +
   1.491 +// get_pointer() enables boost::mem_fn to recognize shared_ptr
   1.492 +
   1.493 +template<class T> inline T * get_pointer(shared_ptr<T> const & p)
   1.494 +{
   1.495 +    return p.get();
   1.496 +}
   1.497 +
   1.498 +// operator<<
   1.499 +
   1.500 +#if defined(__GNUC__) &&  (__GNUC__ < 3)
   1.501 +
   1.502 +template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
   1.503 +{
   1.504 +    os << p.get();
   1.505 +    return os;
   1.506 +}
   1.507 +
   1.508 +#else
   1.509 +
   1.510 +// in STLport's no-iostreams mode no iostream symbols can be used
   1.511 +#ifndef _STLP_NO_IOSTREAMS
   1.512 +
   1.513 +# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
   1.514 +// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
   1.515 +using std::basic_ostream;
   1.516 +template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
   1.517 +# else
   1.518 +template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
   1.519 +# endif 
   1.520 +{
   1.521 +    os << p.get();
   1.522 +    return os;
   1.523 +}
   1.524 +
   1.525 +#endif // _STLP_NO_IOSTREAMS
   1.526 +
   1.527 +#endif // __GNUC__ < 3
   1.528 +
   1.529 +// get_deleter (experimental)
   1.530 +
   1.531 +#if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
   1.532 +    ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
   1.533 +    ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
   1.534 +
   1.535 +// g++ 2.9x doesn't allow static_cast<X const *>(void *)
   1.536 +// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
   1.537 +
   1.538 +template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
   1.539 +{
   1.540 +    void const * q = p._internal_get_deleter(typeid(D));
   1.541 +    return const_cast<D *>(static_cast<D const *>(q));
   1.542 +}
   1.543 +
   1.544 +#else
   1.545 +
   1.546 +template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
   1.547 +{
   1.548 +    return static_cast<D *>(p._internal_get_deleter(typeid(D)));
   1.549 +}
   1.550 +
   1.551 +#endif
   1.552 +
   1.553 +} // namespace boost
   1.554 +
   1.555 +#ifdef BOOST_MSVC
   1.556 +# pragma warning(pop)
   1.557 +#endif    
   1.558 +
   1.559 +#endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
   1.560 +
   1.561 +#endif  // #ifndef BOOST_SHARED_PTR_HPP_INCLUDED