46 typedef long CounterT_default;
51 typedef void result_type;
52 typedef T* argument_type;
54 void operator() (argument_type p)
const {
delete p; }
57 template<
typename CounterT>
60 typedef CounterT Counter_Type;
69 virtual void dispose() = 0;
74 virtual void* get_deleter(
const std::type_info&) = 0;
76 void add_ref_copy() { ++m_shcount; }
78 void add_ref_lock() { ++m_shcount; }
87 void weak_add_ref() { ++m_wkcount; }
94 Counter_Type use_count()
const {
return m_shcount; }
101 Counter_Type m_shcount;
102 Counter_Type m_wkcount;
105 template<
typename PtrT,
typename DeleterT,
typename CounterT>
117 virtual void* get_deleter(
const std::type_info& ti) {
118 return (ti ==
typeid(DeleterT)) ? &m_del : NULL;
132 template<
typename CounterT>
135 typedef typename CountedBase<CounterT>::Counter_Type Counter_Type;
141 template<
typename PtrT,
typename DeleterT>
166 m_pi->add_ref_copy();
175 _tmp->add_ref_copy();
190 Counter_Type use_count()
const 192 return m_pi ? m_pi->use_count() : CountedBase<CounterT>::Counter_Type(0);
195 bool unique()
const {
return use_count() == 1;}
199 return a.m_pi == b.m_pi;
204 return a.m_pi < b.m_pi;
207 void* get_deleter(
const std::type_info& ti)
const {
208 return m_pi ? m_pi->get_deleter(ti) : NULL;
215 template<
typename CounterT>
218 typedef typename CountedBase<CounterT>::Counter_Type Counter_Type;
228 m_pi->weak_add_ref();
235 m_pi->weak_add_ref();
240 m_pi->weak_release();
248 _tmp->weak_add_ref();
250 m_pi->weak_release();
261 _tmp->weak_add_ref();
263 m_pi->weak_release();
276 Counter_Type use_count()
const 278 return m_pi ? m_pi->use_count() : Counter_Type(0);
283 return a.m_pi == b.m_pi;
288 return a.m_pi < b.m_pi;
291 void* get_deleter(
const std::type_info& ti)
const {
292 return m_pi ? m_pi->get_deleter(ti) : NULL;
299 template<
typename CounterT>
305 m_pi->add_ref_lock();
313 typedef T& reference;
318 typedef void reference;
323 typedef void reference;
328 typedef void reference;
333 typedef void reference;
344 template<
typename T,
typename CounterT = CounterT_default>
347 typedef typename internals::SharedPointerTraits<T>::reference _Reference;
349 typedef T element_type;
350 typedef typename internals::SharedCount<CounterT>::Counter_Type Counter_Type;
363 template<
typename U,
typename DeleterT>
374 m_count(other.m_count)
381 m_count(other.m_count)
393 m_ptr(static_cast<element_type*>(other.m_ptr)),
394 m_count(other.m_count)
399 m_ptr(const_cast<element_type*>(other.m_ptr)),
400 m_count(other.m_count)
405 m_ptr(dynamic_cast<element_type*>(other.m_ptr)),
406 m_count(other.m_count)
417 m_count = other.m_count;
442 template<
typename U,
typename UDeleterT>
443 void reset(U* p, UDeleterT d)
449 _Reference operator*()
const {
return *m_ptr; }
450 element_type* operator->()
const {
return m_ptr; }
451 element_type*
get()
const {
return m_ptr; }
457 operator BooleanType()
const 459 return m_ptr ? &SharedPointer::m_ptr : NULL;
462 bool unique()
const {
return m_count.unique(); }
464 Counter_Type use_count()
const {
return m_count.use_count(); }
468 std::swap(m_ptr, other.m_ptr);
469 m_count.swap(other.m_count);
473 void* _M_get_deleter(
const std::type_info& ti)
const 475 return m_count.get_deleter(ti);
482 return m_count < rhs.m_count;
486 template<
typename U,
typename UCounterT>
friend class SharedPointer;
488 template<
typename U,
typename UCounterT>
friend class WeakPointer;
493 return a.get() == b.get();
499 return a.get() != b.get();
503 friend inline bool operator<(const SharedPointer& a, const SharedPointer<U>& b)
513 template<
typename T,
typename CounterT>
519 template<
typename T,
typename U,
typename CounterT>
525 template<
typename T,
typename U,
typename CounterT>
531 template<
typename T,
typename U,
typename CounterT>
537 template<
typename CharT,
typename TraitsT,
typename T,
typename CounterT>
538 std::basic_ostream<CharT, TraitsT>&
541 return os << p.get();
544 template<
typename DeleterT,
typename T,
typename CounterT>
547 return static_cast<DeleterT*
>(p._M_get_deleter(
typeid(DeleterT)));
550 template<
typename T,
typename CounterT =
long>
554 typedef T element_type;
555 typedef typename internals::SharedCount<CounterT>::Counter_Type Counter_Type;
568 m_count(other.m_count)
570 m_ptr = other.lock().get();
576 m_count(other.m_count)
583 m_ptr = other.lock().get();
584 m_count = other.m_count;
592 m_count = other.m_count;
602 Counter_Type use_count()
const {
return m_count.use_count(); }
604 bool expired()
const {
return m_count.use_count() == 0; }
610 std::swap(m_ptr, other.m_ptr);
611 m_count.swap(other.m_count);
618 return m_count < rhs.m_count;
622 template<
typename U,
typename UCounterT>
friend class SharedPointer;
624 template<
typename U,
typename UCounterT>
friend class WeakPointer;
627 friend inline bool operator<(const WeakPointer& a, const WeakPointer<U>& b)
636 template<
typename T,
typename CounterT>
647 template<
typename T,
typename CounterT>
653 template<
typename T,
typename CounterT>
virtual void dispose()
called when m_shcount goes to 0
Definition: shared_pointer.h:115
Definition: shared_pointer.h:336
virtual void destroy()
called when m_wkcount goes to 0
Definition: shared_pointer.h:72
Definition: shared_pointer.h:133
Definition: shared_pointer.h:106
Definition: shared_pointer.h:646
Definition: shared_pointer.h:337
Definition: shared_pointer.h:339
Definition: shared_pointer.h:130
Definition: shared_pointer.h:50
Definition: shared_pointer.h:345
Definition: shared_pointer.h:311
Definition: shared_pointer.h:58
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator!=(const strided_iterator< T > it1, const strided_iterator< T > it2)
Definition: strided_iterator.h:150
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: shared_pointer.h:342
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator==(const strided_iterator< T > it1, const strided_iterator< T > it2)
Definition: strided_iterator.h:142
Definition: shared_pointer.h:338