1 #ifndef BOOSTER_SMART_PTR_SHARED_PTR_HPP_INCLUDED 2 #define BOOSTER_SMART_PTR_SHARED_PTR_HPP_INCLUDED 17 #include <booster/config.h> 19 #include <booster/auto_ptr_inc.h> 21 #include <booster/backtrace.h> 22 #include <booster/checked_delete.h> 23 #include <booster/smart_ptr/shared_count.h> 24 #include <booster/smart_ptr/sp_convertible.h> 32 #ifdef BOOSTER_MSVC // moved here to work around VC++ compiler crash 33 # pragma warning(push) 34 # pragma warning(disable:4284) // odd return type for operator-> 40 template<
class T>
class shared_ptr;
41 template<
class T>
class weak_ptr;
42 template<
class T>
class enable_shared_from_this;
55 typedef T & reference;
60 typedef void reference;
65 typedef void reference;
70 typedef void reference;
75 typedef void reference;
84 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
92 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
96 inline void sp_enable_shared_from_this( ... )
132 typedef T element_type;
133 typedef T value_type;
135 typedef typename booster::detail::shared_ptr_traits<T>::reference reference;
142 explicit shared_ptr( Y * p ): px( p ), pn( p )
144 booster::detail::sp_enable_shared_from_this(
this, p, p );
153 template<
class Y,
class D>
shared_ptr(Y * p, D d): px(p), pn(p, d)
155 booster::detail::sp_enable_shared_from_this(
this, p, p );
160 template<
class Y,
class D,
class A>
shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
162 booster::detail::sp_enable_shared_from_this(
this, p, p );
185 : px( r.px ), pn( r.pn )
224 explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
228 booster::detail::sp_enable_shared_from_this(
this, tmp, tmp );
234 typename Ap::element_type * tmp = r.get();
236 booster::detail::sp_enable_shared_from_this(
this, tmp, tmp );
244 this_type(r).swap(*
this);
251 this_type(r).swap(*
this);
257 shared_ptr & operator=( std::auto_ptr<Y> & r )
259 this_type(r).swap(*
this);
266 this_type( r ).swap( *
this );
274 this_type().swap(*
this);
277 template<
class Y>
void reset(Y * p)
279 assert(p == 0 || p != px);
280 this_type(p).swap(*
this);
283 template<
class Y,
class D>
void reset( Y * p, D d )
285 this_type( p, d ).swap( *
this );
288 template<
class Y,
class D,
class A>
void reset( Y * p, D d, A a )
290 this_type( p, d, a ).swap( *
this );
293 template<
class Y>
void reset(
shared_ptr<Y> const & r, T * p )
295 this_type( r, p ).swap( *
this );
298 reference operator* ()
const 304 T * operator-> ()
const 316 #include <booster/smart_ptr/operator_bool.h> 323 long use_count()
const 325 return pn.use_count();
330 std::swap(px, other.px);
334 template<
class Y>
bool _internal_less(
shared_ptr<Y> const & rhs)
const 339 void * _internal_get_deleter( detail::sp_typeinfo
const & ti )
const 341 return pn.get_deleter( ti );
344 bool _internal_equiv(
shared_ptr const & r )
const 346 return px == r.px && pn == r.pn;
355 template<
class Y>
friend class weak_ptr;
364 return a.get() == b.get();
369 return a.get() != b.get();
372 template<
class T,
class U>
inline bool operator<(shared_ptr<T>
const & a,
shared_ptr<U> const & b)
374 return a._internal_less(b);
416 assert(dynamic_cast<T *>(r.get()) == r.get());
417 return shared_static_cast<T>(r);
422 template<
class T>
inline T * get_pointer(
shared_ptr<T> const & p)
429 template<
class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y>
const & p)
437 template<
class D,
class T> D * get_deleter(
shared_ptr<T> const & p)
439 return static_cast<D *
>(p._internal_get_deleter(BOOSTER_SP_TYPEID(D)));
445 # pragma warning(pop) 448 #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED Definition: shared_ptr.h:50
Definition: shared_count.h:37
Definition: sp_convertible.h:32
Definition: shared_ptr.h:51
Definition: sp_convertible.h:47
Definition: shared_ptr.h:43
Definition: shared_ptr.h:103
Definition: shared_ptr.h:49
Same as std::bad_cast but records stack trace.
Definition: backtrace.h:151
This class is borrowed from boost.
Definition: enable_shared_from_this.h:30
Definition: shared_count.h:33
Definition: shared_ptr.h:53
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
Definition: shared_ptr.h:48