1 #ifndef MADNESS_SHARED_PTR_BITS_H
2 #define MADNESS_SHARED_PTR_BITS_H
32 template <
class T>
struct Hash;
48 typedef char (&
yes)[1];
49 typedef char (&
no)[2];
55 value =
sizeof((
f)(static_cast<Y*>(0))) ==
sizeof(
yes)
85 template <
class X,
class Y,
class T>
91 template <
class X,
class Y,
class T>
125 virtual void dispose() = 0;
134 virtual void *
get_deleter( std::type_info
const & ti ) = 0;
144 throw "shared_ptr::add_ref_lock - not supported";
185 virtual void *
get_deleter( std::type_info
const & ) {
return 0; }
188 template<
class Y,
class D>
211 return ti ==
typeid(D)? &reinterpret_cast<char&>( del ): 0;
280 bool unique()
const {
return use_count() == 1; }
282 bool empty()
const {
return pi_ == 0; }
285 return a.pi_ == b.pi_;
289 return std::less<sp_counted_base *>()( a.pi_, b.pi_ );
351 bool empty()
const {
return pi_ == 0; }
354 return a.pi_ == b.pi_;
358 return std::less<sp_counted_base *>()(a.pi_, b.pi_);
436 px(static_cast<element_type *>(r.px)), pn(r.pn)
441 px(const_cast<element_type *>(r.px)), pn(r.pn)
446 px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
455 this_type(r).
swap(*
this);
459 void reset() { this_type().swap(*
this); }
463 MADNESS_ASSERT(p == 0 || p != px);
464 this_type(p).swap(*
this);
467 template <
class Y,
class D>
468 void reset(Y * p, D d) { this_type(p, d).swap(*
this); }
472 this_type(r, p).swap(*
this);
476 MADNESS_ASSERT(px != 0);
481 MADNESS_ASSERT(px != 0);
485 T *
get()
const {
return px; }
487 operator bool()
const {
return px != NULL; }
511 return px == r.px && pn == r.pn;
527 return a.
get() == b.
get();
532 return a.
get() != b.
get();
535 template <
class T,
class U>
inline bool operator<(shared_ptr<T>
const &
a,
537 return a._internal_less(
b);
564 std::ostream & operator<<(std::ostream & os, shared_ptr<Y>
const & p) {
571 template <
class D,
class T>
584 typedef weak_ptr<T> this_type;
614 : px(r.
lock().get()), pn(r.pn)
619 : px( r.px ), pn( r.pn )
628 void reset() { this_type().swap(*
this); }
655 template<
class T,
class U>
657 return a._internal_less(
b);
666 class enable_shared_from_this {
682 MADNESS_ASSERT( p.
get() == this );
688 MADNESS_ASSERT( p.
get() == this );
695 template <
class X,
class Y>
697 if( weak_this_.expired() )
723 MADNESS_ASSERT( deleter_.
use_count() <= 1 );
731 class enable_shared_from_this2 {
741 MADNESS_ASSERT( shared_this_.use_count() <= 1 );
763 void init_weak_once()
const {
764 if( weak_this_._empty() ) {
766 weak_this_ = shared_this_;
773 template<
class X,
class Y>
775 MADNESS_ASSERT( ppx != 0 );
777 if( weak_this_.use_count() == 0 ) {
779 }
else if( shared_this_.
use_count() != 0 ) {
780 MADNESS_ASSERT( ppx->
unique() );
783 MADNESS_ASSERT( pd != 0 );
785 pd->set_deleter( *ppx );
787 ppx->
reset( shared_this_, ppx->
get() );
788 shared_this_.
reset();
shared_count(Y *p)
Definition: shared_ptr_bits.h:229
bool unique() const
Definition: shared_ptr_bits.h:493
void swap(this_type &other)
Definition: shared_ptr_bits.h:630
virtual void destroy()
Definition: shared_ptr_bits.h:129
Definition: shared_ptr_bits.h:38
reference operator*() const
Definition: shared_ptr_bits.h:475
void _internal_assign(T *px2, detail::shared_count const &pn2)
Definition: shared_ptr_bits.h:635
shared_count(Y *p, D d)
Definition: shared_ptr_bits.h:239
virtual void * get_deleter(std::type_info const &ti)=0
~weak_count()
Definition: shared_ptr_bits.h:317
D * get_deleter(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:572
Definition: shared_ptr_bits.h:71
Definition: shared_ptr_bits.h:100
char(& yes)[1]
Definition: shared_ptr_bits.h:48
void reset(Y *p, D d)
Definition: shared_ptr_bits.h:468
T & reference
Definition: shared_ptr_bits.h:78
weak_ptr(shared_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:618
bool expired() const
Definition: shared_ptr_bits.h:626
bool add_ref_lock()
Definition: shared_ptr_bits.h:141
_vt
Definition: shared_ptr_bits.h:54
bool _internal_less(shared_ptr< Y > const &rhs) const
Definition: shared_ptr_bits.h:502
shared_ptr< T > shared_from_this()
Definition: shared_ptr_bits.h:680
Definition: shared_ptr_bits.h:55
void release()
Definition: shared_ptr_bits.h:147
Definition: shared_ptr_bits.h:75
void * _internal_get_deleter(std::type_info const &ti) const
Definition: shared_ptr_bits.h:506
~enable_shared_from_this()
Definition: shared_ptr_bits.h:676
Definition: shared_ptr_bits.h:61
void operator()(T *)
Definition: shared_ptr_bits.h:722
Definition: shared_ptr_bits.h:708
shared_ptr(Y *p)
Definition: shared_ptr_bits.h:393
friend bool operator==(shared_count const &a, shared_count const &b)
Definition: shared_ptr_bits.h:284
void _internal_accept_owner(shared_ptr< X > const *ppx, Y *py) const
Definition: shared_ptr_bits.h:696
enable_shared_from_this(enable_shared_from_this const &)
Definition: shared_ptr_bits.h:671
void reset(shared_ptr< Y > const &r, T *p)
Definition: shared_ptr_bits.h:471
bool operator!() const
Definition: shared_ptr_bits.h:491
sp_counted_impl_pd(Y *p, D d)
Definition: shared_ptr_bits.h:204
bool operator!=(shared_ptr< T > const &a, shared_ptr< U > const &b)
Definition: shared_ptr_bits.h:530
detail::shared_ptr_traits< T >::reference reference
Definition: shared_ptr_bits.h:386
void sp_enable_shared_from_this(shared_ptr< X > const *ppx, Y const *py, enable_shared_from_this< T > const *pe)
Definition: shared_ptr_bits.h:86
shared_ptr(shared_ptr< Y > const &r, detail::const_cast_tag)
Definition: shared_ptr_bits.h:440
void reset(Y *p)
Definition: shared_ptr_bits.h:462
void swap(shared_ptr< T > &other)
Definition: shared_ptr_bits.h:497
void swap(weak_count &r)
Definition: shared_ptr_bits.h:343
bool dec_and_test()
Decrements the counter and returns true if the new value is zero.
Definition: atomicint.h:178
~shared_count()
Definition: shared_ptr_bits.h:249
Definition: shared_ptr_bits.h:169
Definition: shared_ptr_bits.h:41
Definition: shared_ptr_bits.h:298
enable_shared_from_this()
Definition: shared_ptr_bits.h:669
Definition: shared_ptr_bits.h:59
enable_shared_from_this2()
Definition: shared_ptr_bits.h:734
shared_ptr< T const > shared_from_this() const
Definition: shared_ptr_bits.h:756
shared_ptr(shared_ptr< Y > const &r, detail::dynamic_cast_tag)
Definition: shared_ptr_bits.h:445
shared_ptr(shared_ptr< Y > const &r, detail::static_cast_tag)
Definition: shared_ptr_bits.h:435
char(& no)[2]
Definition: shared_ptr_bits.h:49
void reference
Definition: shared_ptr_bits.h:79
shared_ptr< T > lock() const
Definition: shared_ptr_bits.h:622
Definition: shared_ptr_bits.h:47
void reset()
Definition: shared_ptr_bits.h:628
weak_count(shared_count const &r)
Definition: shared_ptr_bits.h:309
T * get() const
Definition: shared_ptr_bits.h:485
bool empty() const
Definition: shared_ptr_bits.h:282
void reference
Definition: shared_ptr_bits.h:81
weak_ptr()
Definition: shared_ptr_bits.h:590
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
shared_ptr(weak_ptr< Y > const &r)
Definition: shared_ptr_bits.h:414
void reference
Definition: shared_ptr_bits.h:80
sp_counted_impl_pd(Y *p)
Definition: shared_ptr_bits.h:206
weak_ptr(weak_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:613
shared_count()
Definition: shared_ptr_bits.h:227
void _internal_accept_owner(shared_ptr< X > *ppx, Y *py) const
Definition: shared_ptr_bits.h:774
void add_ref_copy()
Definition: shared_ptr_bits.h:136
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
friend bool operator<(weak_count const &a, weak_count const &b)
Definition: shared_ptr_bits.h:357
T * pointer
Definition: shared_ptr_bits.h:385
T element_type
Definition: shared_ptr_bits.h:588
weak_count(weak_count const &r)
Definition: shared_ptr_bits.h:313
T * get_pointer(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:559
sp_empty type
Definition: shared_ptr_bits.h:63
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:544
friend bool operator<(shared_count const &a, shared_count const &b)
Definition: shared_ptr_bits.h:288
Definition: shared_ptr_bits.h:72
void * get_deleter(std::type_info const &ti) const
Definition: shared_ptr_bits.h:292
long use_count() const
Definition: shared_ptr_bits.h:278
void reference
Definition: shared_ptr_bits.h:82
An integer with atomic set, get, read+inc, read+dec, dec+test operations.
Definition: atomicint.h:73
Definition: shared_ptr_bits.h:39
virtual void dispose()
Definition: shared_ptr_bits.h:183
friend bool operator==(weak_count const &a, weak_count const &b)
Definition: shared_ptr_bits.h:353
sp_counted_base()
Definition: shared_ptr_bits.h:112
void checked_delete(T *p)
Checked pointer delete function.
Definition: boost_checked_delete_bits.h:15
enable_shared_from_this & operator=(enable_shared_from_this const &)
Definition: shared_ptr_bits.h:674
virtual void * get_deleter(std::type_info const &)
Definition: shared_ptr_bits.h:185
void swap(shared_ptr< T > &a, shared_ptr< T > &b)
Definition: shared_ptr_bits.h:540
esft2_deleter_wrapper()
Definition: shared_ptr_bits.h:716
shared_ptr< T > const_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:548
long use_count() const
Definition: shared_ptr_bits.h:495
Definition: shared_ptr_bits.h:217
void reset()
Definition: shared_ptr_bits.h:459
bool operator==(shared_ptr< T > const &a, shared_ptr< U > const &b)
Definition: shared_ptr_bits.h:525
shared_ptr(Y *p, D d)
Definition: shared_ptr_bits.h:405
void weak_add_ref()
Definition: shared_ptr_bits.h:157
bool _internal_less(weak_ptr< Y > const &rhs) const
Definition: shared_ptr_bits.h:640
virtual void * get_deleter(std::type_info const &ti)
Definition: shared_ptr_bits.h:210
shared_count(shared_count const &r)
Definition: shared_ptr_bits.h:253
bool unique() const
Definition: shared_ptr_bits.h:280
T element_type
Definition: shared_ptr_bits.h:383
virtual void dispose()
Definition: shared_ptr_bits.h:208
shared_ptr & operator=(shared_ptr const &r)
Definition: shared_ptr_bits.h:454
T * operator->() const
Definition: shared_ptr_bits.h:480
Implements MadnessException.
shared_ptr()
Definition: shared_ptr_bits.h:388
enable_shared_from_this2 & operator=(enable_shared_from_this2 const &)
Definition: shared_ptr_bits.h:738
enable_shared_from_this2(enable_shared_from_this2 const &)
Definition: shared_ptr_bits.h:736
weak_count()
Definition: shared_ptr_bits.h:307
shared_ptr< T > shared_from_this()
Definition: shared_ptr_bits.h:751
long use_count() const
Definition: shared_ptr_bits.h:349
shared_ptr(shared_ptr< Y > const &r, T *p)
Definition: shared_ptr_bits.h:430
std::size_t hash_value(shared_ptr< T > const &p)
Definition: shared_ptr_bits.h:576
Definition: shared_ptr_bits.h:73
void weak_release()
Definition: shared_ptr_bits.h:159
Definition: shared_ptr_bits.h:40
shared_ptr< T const > shared_from_this() const
Definition: shared_ptr_bits.h:686
virtual ~sp_counted_base()
Definition: shared_ptr_bits.h:118
~enable_shared_from_this2()
Definition: shared_ptr_bits.h:740
T value_type
Definition: shared_ptr_bits.h:384
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Definition: shared_ptr_bits.h:43
long use_count() const
Definition: shared_ptr_bits.h:624
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
void swap(shared_count &r)
Definition: shared_ptr_bits.h:272
shared_ptr(shared_ptr< Y > const &r, typename detail::enable_if_convertible< Y, T >::type=detail::sp_empty())
Definition: shared_ptr_bits.h:422
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition: mpreal.h:3069
Hash functor.
Definition: shared_ptr_bits.h:32
Definition: shared_ptr_bits.h:189
sp_counted_impl_p(X *px)
Definition: shared_ptr_bits.h:181
bool _internal_equiv(shared_ptr const &r) const
Definition: shared_ptr_bits.h:510
Definition: shared_ptr_bits.h:78
void set_deleter(shared_ptr< T > const &deleter)
Definition: shared_ptr_bits.h:719
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr_bits.h:552
Definition: shared_ptr_bits.h:67
long use_count() const
Definition: shared_ptr_bits.h:165
bool empty() const
Definition: shared_ptr_bits.h:351