epoc32/include/stdapis/boost/intrusive_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/intrusive_ptr.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,277 @@
     1.4 +#ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED
     1.5 +#define BOOST_INTRUSIVE_PTR_HPP_INCLUDED
     1.6 +
     1.7 +//
     1.8 +//  intrusive_ptr.hpp
     1.9 +//
    1.10 +//  Copyright (c) 2001, 2002 Peter Dimov
    1.11 +//
    1.12 +// Distributed under the Boost Software License, Version 1.0. (See
    1.13 +// accompanying file LICENSE_1_0.txt or copy at
    1.14 +// http://www.boost.org/LICENSE_1_0.txt)
    1.15 +//
    1.16 +//  See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
    1.17 +//
    1.18 +
    1.19 +#include <boost/config.hpp>
    1.20 +
    1.21 +#ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash
    1.22 +# pragma warning(push)
    1.23 +# pragma warning(disable:4284) // odd return type for operator->
    1.24 +#endif
    1.25 +
    1.26 +#include <boost/assert.hpp>
    1.27 +#include <boost/detail/workaround.hpp>
    1.28 +
    1.29 +#include <functional>           // for std::less
    1.30 +#include <iosfwd>               // for std::basic_ostream
    1.31 +
    1.32 +
    1.33 +namespace boost
    1.34 +{
    1.35 +
    1.36 +//
    1.37 +//  intrusive_ptr
    1.38 +//
    1.39 +//  A smart pointer that uses intrusive reference counting.
    1.40 +//
    1.41 +//  Relies on unqualified calls to
    1.42 +//  
    1.43 +//      void intrusive_ptr_add_ref(T * p);
    1.44 +//      void intrusive_ptr_release(T * p);
    1.45 +//
    1.46 +//          (p != 0)
    1.47 +//
    1.48 +//  The object is responsible for destroying itself.
    1.49 +//
    1.50 +
    1.51 +template<class T> class intrusive_ptr
    1.52 +{
    1.53 +private:
    1.54 +
    1.55 +    typedef intrusive_ptr this_type;
    1.56 +
    1.57 +public:
    1.58 +
    1.59 +    typedef T element_type;
    1.60 +
    1.61 +    intrusive_ptr(): p_(0)
    1.62 +    {
    1.63 +    }
    1.64 +
    1.65 +    intrusive_ptr(T * p, bool add_ref = true): p_(p)
    1.66 +    {
    1.67 +        if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_);
    1.68 +    }
    1.69 +
    1.70 +#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
    1.71 +
    1.72 +    template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get())
    1.73 +    {
    1.74 +        if(p_ != 0) intrusive_ptr_add_ref(p_);
    1.75 +    }
    1.76 +
    1.77 +#endif
    1.78 +
    1.79 +    intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_)
    1.80 +    {
    1.81 +        if(p_ != 0) intrusive_ptr_add_ref(p_);
    1.82 +    }
    1.83 +
    1.84 +    ~intrusive_ptr()
    1.85 +    {
    1.86 +        if(p_ != 0) intrusive_ptr_release(p_);
    1.87 +    }
    1.88 +
    1.89 +#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
    1.90 +
    1.91 +    template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
    1.92 +    {
    1.93 +        this_type(rhs).swap(*this);
    1.94 +        return *this;
    1.95 +    }
    1.96 +
    1.97 +#endif
    1.98 +
    1.99 +    intrusive_ptr & operator=(intrusive_ptr const & rhs)
   1.100 +    {
   1.101 +        this_type(rhs).swap(*this);
   1.102 +        return *this;
   1.103 +    }
   1.104 +
   1.105 +    intrusive_ptr & operator=(T * rhs)
   1.106 +    {
   1.107 +        this_type(rhs).swap(*this);
   1.108 +        return *this;
   1.109 +    }
   1.110 +
   1.111 +    T * get() const
   1.112 +    {
   1.113 +        return p_;
   1.114 +    }
   1.115 +
   1.116 +    T & operator*() const
   1.117 +    {
   1.118 +        return *p_;
   1.119 +    }
   1.120 +
   1.121 +    T * operator->() const
   1.122 +    {
   1.123 +        return p_;
   1.124 +    }
   1.125 +
   1.126 +#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
   1.127 +
   1.128 +    operator bool () const
   1.129 +    {
   1.130 +        return p_ != 0;
   1.131 +    }
   1.132 +
   1.133 +#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
   1.134 +    typedef T * (this_type::*unspecified_bool_type)() const;
   1.135 +    
   1.136 +    operator unspecified_bool_type() const // never throws
   1.137 +    {
   1.138 +        return p_ == 0? 0: &this_type::get;
   1.139 +    }
   1.140 +
   1.141 +#else 
   1.142 +
   1.143 +    typedef T * this_type::*unspecified_bool_type;
   1.144 +
   1.145 +    operator unspecified_bool_type () const
   1.146 +    {
   1.147 +        return p_ == 0? 0: &this_type::p_;
   1.148 +    }
   1.149 +
   1.150 +#endif
   1.151 +
   1.152 +    // operator! is a Borland-specific workaround
   1.153 +    bool operator! () const
   1.154 +    {
   1.155 +        return p_ == 0;
   1.156 +    }
   1.157 +
   1.158 +    void swap(intrusive_ptr & rhs)
   1.159 +    {
   1.160 +        T * tmp = p_;
   1.161 +        p_ = rhs.p_;
   1.162 +        rhs.p_ = tmp;
   1.163 +    }
   1.164 +
   1.165 +private:
   1.166 +
   1.167 +    T * p_;
   1.168 +};
   1.169 +
   1.170 +template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
   1.171 +{
   1.172 +    return a.get() == b.get();
   1.173 +}
   1.174 +
   1.175 +template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
   1.176 +{
   1.177 +    return a.get() != b.get();
   1.178 +}
   1.179 +
   1.180 +template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b)
   1.181 +{
   1.182 +    return a.get() == b;
   1.183 +}
   1.184 +
   1.185 +template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b)
   1.186 +{
   1.187 +    return a.get() != b;
   1.188 +}
   1.189 +
   1.190 +template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b)
   1.191 +{
   1.192 +    return a == b.get();
   1.193 +}
   1.194 +
   1.195 +template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b)
   1.196 +{
   1.197 +    return a != b.get();
   1.198 +}
   1.199 +
   1.200 +#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
   1.201 +
   1.202 +// Resolve the ambiguity between our op!= and the one in rel_ops
   1.203 +
   1.204 +template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
   1.205 +{
   1.206 +    return a.get() != b.get();
   1.207 +}
   1.208 +
   1.209 +#endif
   1.210 +
   1.211 +template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
   1.212 +{
   1.213 +    return std::less<T *>()(a.get(), b.get());
   1.214 +}
   1.215 +
   1.216 +template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs)
   1.217 +{
   1.218 +    lhs.swap(rhs);
   1.219 +}
   1.220 +
   1.221 +// mem_fn support
   1.222 +
   1.223 +template<class T> T * get_pointer(intrusive_ptr<T> const & p)
   1.224 +{
   1.225 +    return p.get();
   1.226 +}
   1.227 +
   1.228 +template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
   1.229 +{
   1.230 +    return static_cast<T *>(p.get());
   1.231 +}
   1.232 +
   1.233 +template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
   1.234 +{
   1.235 +    return const_cast<T *>(p.get());
   1.236 +}
   1.237 +
   1.238 +template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
   1.239 +{
   1.240 +    return dynamic_cast<T *>(p.get());
   1.241 +}
   1.242 +
   1.243 +// operator<<
   1.244 +
   1.245 +#if defined(__GNUC__) &&  (__GNUC__ < 3)
   1.246 +
   1.247 +template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p)
   1.248 +{
   1.249 +    os << p.get();
   1.250 +    return os;
   1.251 +}
   1.252 +
   1.253 +#else
   1.254 +
   1.255 +// in STLport's no-iostreams mode no iostream symbols can be used
   1.256 +#ifndef _STLP_NO_IOSTREAMS
   1.257 +
   1.258 +# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
   1.259 +// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
   1.260 +using std::basic_ostream;
   1.261 +template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
   1.262 +# else
   1.263 +template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
   1.264 +# endif 
   1.265 +{
   1.266 +    os << p.get();
   1.267 +    return os;
   1.268 +}
   1.269 +
   1.270 +#endif // _STLP_NO_IOSTREAMS
   1.271 +
   1.272 +#endif // __GNUC__ < 3
   1.273 +
   1.274 +} // namespace boost
   1.275 +
   1.276 +#ifdef BOOST_MSVC
   1.277 +# pragma warning(pop)
   1.278 +#endif    
   1.279 +
   1.280 +#endif  // #ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED