13 #if __cplusplus<201103L
14 # error c++11 required
21 #include <pv/epicsException.h>
27 #define HAVE_SHOW_REFS
33 class shared_ptr_base;
54 void show_refs(
std::ostream&,
bool self=
true,
bool weak=
false)
const;
67 #ifndef EXCEPT_USE_NONE
68 :m_stack(), m_depth(0)
72 #ifndef EXCEPT_USE_NONE
73 ,m_stack(), m_depth(0)
81 void track_new(
const void* ptr);
88 #ifndef EXCEPT_USE_NONE
89 void *m_stack[EXCEPT_DEPTH];
106 template<
typename Store,
typename Actual>
118 typedef ::std::shared_ptr<T> real_type;
133 typedef weak_ptr<T> weak_type;
136 shared_ptr() noexcept {}
138 shared_ptr(
const shared_ptr& o) :shared_ptr_base(o.track), real(o.real) {track_new();}
141 shared_ptr(
const shared_ptr<A>& o) :shared_ptr_base(o.track), real(o.real) {track_new();}
144 template<
typename A,
class ... Args>
145 explicit shared_ptr(A* a, Args ... args) : shared_ptr_base(), real(a, args...) {
147 do_enable_shared_from_this(*
this, a);
152 shared_ptr(
const weak_ptr<A>& o) :shared_ptr_base(o.track), real(o.real) {track_new();}
160 shared_ptr&
operator=(
const shared_ptr& o) {
168 shared_ptr&
operator=(
const shared_ptr<A>& o) {
176 void reset() noexcept { real.reset(); track_clear(); }
177 template<
typename A,
class ... Args>
178 void reset(A* a, Args ... args)
180 real.reset(a, args...);
182 do_enable_shared_from_this(*
this, a);
184 void swap(shared_ptr &o) noexcept
194 T*
get()
const noexcept {
return real.get(); }
196 T* operator->() const noexcept {
return real.get(); }
197 long use_count() const noexcept {
return real.use_count(); }
198 bool unique() const noexcept {
return real.unique(); }
199 explicit operator bool() const noexcept {
return bool(real); }
201 bool operator==(
const shared_ptr<T>& o)
const {
return real==o.real; }
202 bool operator!=(
const shared_ptr<T>& o)
const {
return real!=o.real; }
203 bool operator<(const shared_ptr<T>& o)
const {
return real<o.real; }
206 bool owner_before(
const shared_ptr<A>& o) {
return real.owner_before(o); }
208 bool owner_before(
const weak_ptr<A>& o) {
return real.owner_before(o); }
210 template<
typename TO,
typename FROM>
213 template<
typename TO,
typename FROM>
216 template<
typename TO,
typename FROM>
219 template<
typename Store,
typename Actual>
221 do_enable_shared_from_this(
const shared_ptr<Store>& dest,
222 enable_shared_from_this<Actual>*
self
226 template<
typename TO,
typename FROM>
231 template<
typename TO,
typename FROM>
236 template<
typename TO,
typename FROM>
242 class weak_ptr :
public weak_ptr_base {
243 typedef ::std::weak_ptr<T> real_type;
248 friend class shared_ptr;
250 friend class weak_ptr;
253 typedef typename real_type::element_type element_type;
254 typedef weak_ptr<T> weak_type;
257 weak_ptr() noexcept {}
259 weak_ptr(
const weak_ptr& o) :weak_ptr_base(o.track), real(o.real) {}
262 weak_ptr(
const weak_ptr<A>& o) :weak_ptr_base(o.track), real(o.real) {}
266 weak_ptr(
const shared_ptr<A>& o) :weak_ptr_base(o.track), real(o.real) {}
278 weak_ptr&
operator=(
const shared_ptr<A>& o) {
284 shared_ptr<T>
lock() const noexcept {
return shared_ptr<T>(real.lock(), track); }
285 void reset() noexcept { track.reset(); real.reset(); }
287 long use_count() const noexcept {
return real.use_count(); }
288 bool unique() const noexcept {
return real.unique(); }
289 bool expired() const noexcept {
return real.expired(); }
293 class enable_shared_from_this {
294 mutable weak_ptr<Base> xxInternalSelf;
296 template<
typename Store,
typename Actual>
299 do_enable_shared_from_this(
const shared_ptr<Store>& dest,
300 enable_shared_from_this<Actual>*
self
303 shared_ptr<Base> shared_from_this()
const {
304 return shared_ptr<Base>(xxInternalSelf);
308 template<
typename Store,
typename Actual>
310 do_enable_shared_from_this(
const shared_ptr<Store>& dest,
311 enable_shared_from_this<Actual>*
self
314 shared_ptr<Actual> actual(dynamic_pointer_cast<Actual>(dest));
317 self->xxInternalSelf = actual;
321 inline std::ostream& operator<<(std::ostream& strm, const shared_ptr<T>& ptr)
__shared_ptr< _Tp, _Lp > dynamic_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
__shared_ptr< _Tp, _Lp > const_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
shared_ptr< _Tp > const_pointer_cast(const shared_ptr< _Up > &__r) noexcept
void swap(shared_ptr< _Tp > &__a, shared_ptr< _Tp > &__b) noexcept
__shared_ptr< _Tp, _Lp > static_pointer_cast(const __shared_ptr< _Tp1, _Lp > &__r) noexcept
constexpr complex< _Tp > & operator=(const _Tp &)
constexpr _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last)
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
typename __shared_ptr< _Tp >::element_type element_type
shared_ptr< _Tp > static_pointer_cast(const shared_ptr< _Up > &__r) noexcept
void swap(any &__x, any &__y) noexcept
shared_ptr< _Tp > dynamic_pointer_cast(const shared_ptr< _Up > &__r) noexcept
constexpr bool operator==(const allocator< _T1 > &, const allocator< _T2 > &) noexcept
void swap(packaged_task< _Res(_ArgTypes...)> &__x, packaged_task< _Res(_ArgTypes...)> &__y) noexcept
bool operator!=(const std::bernoulli_distribution &__d1, const std::bernoulli_distribution &__d2)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)