22 explicit inline ref_monitor(ref& m);
23 inline ~ref_monitor() {
27 next_->pprev_ = pprev_;
33 explicit operator bool()
const {
41 ref_monitor(
const ref_monitor&);
42 ref_monitor& operator=(
const ref_monitor&);
52 while (ref_monitor* w = first_) {
63 ref& operator=(
const ref&);
64 friend class ref_monitor;
67inline ref_monitor::ref_monitor(ref& m)
68 : pprev_(&m.first_), next_(m.first_) {
70 next_->pprev_ = &next_;
75template <
typename T>
class enable_ref_ptr_with_full_release;
76template <
typename T>
class ref_ptr;
77template <
typename T>
class passive_ref_ptr;
79class enable_ref_ptr {
public:
82 : _use_count(1), _weak_count(0) {
86 assert(!_use_count && !_weak_count);
94 enable_ref_ptr(
const enable_ref_ptr &);
95 enable_ref_ptr &operator=(
const enable_ref_ptr &);
97 template <
typename T>
friend class enable_ref_ptr_with_full_release;
98 template <
typename T>
friend class ref_ptr;
99 template <
typename T>
friend class passive_ref_ptr;
101 void add_ref_copy() {
107 return --_use_count == 0 && _weak_count == 0;
110 void weak_add_ref() {
114 bool weak_release() {
116 return --_weak_count == 0 && _use_count == 0;
119 uint32_t use_count()
const {
126template <
typename T>
class enable_ref_ptr_with_full_release :
public enable_ref_ptr {
public:
128 enable_ref_ptr_with_full_release() {
131 ~enable_ref_ptr_with_full_release() {
136 template <
typename U>
friend class ref_ptr;
137 template <
typename U>
friend class passive_ref_ptr;
142 static_cast<T *
>(
this)->full_release();
143 return --_use_count == 0 && _weak_count == 0;
149template <
typename T>
class ref_ptr {
public:
155 template <
typename U>
explicit ref_ptr(U* ptr)
157 assert(!_t || _t->use_count() == 1);
160 ref_ptr(
const ref_ptr<T>& x)
166 ref_ptr(ref_ptr<T>&& x)
171 template <
typename U> ref_ptr(
const ref_ptr<U>& x)
178 if (_t && _t->release())
182 ref_ptr<T>& operator=(
const ref_ptr<T>& x) {
184 x._t->add_ref_copy();
185 if (_t && _t->release())
191 ref_ptr<T>& operator=(ref_ptr<T>&& x) {
196 template <
typename U> ref_ptr<T>& operator=(
const ref_ptr<U>& x) {
198 x._t->add_ref_copy();
199 if (_t && _t->release())
205 T& operator*()
const {
209 T* operator->()
const {
217 explicit operator bool()
const {
226template <
typename T>
class passive_ref_ptr {
public:
232 template <
typename U>
explicit passive_ref_ptr(U* ptr)
238 template <
typename U>
explicit passive_ref_ptr(
const ref_ptr<U>& x)
239 : _t(x.operator->()) {
244 passive_ref_ptr(
const passive_ref_ptr<T>& x)
250 passive_ref_ptr(passive_ref_ptr<T>&& x)
255 template <
typename U> passive_ref_ptr(
const passive_ref_ptr<U>& x)
262 if (_t && _t->weak_release())
266 passive_ref_ptr<T>& operator=(
const passive_ref_ptr<T>& x) {
268 x._t->weak_add_ref();
269 if (_t && _t->weak_release())
275 passive_ref_ptr<T>& operator=(passive_ref_ptr<T>&& x) {
280 template <
typename U> passive_ref_ptr<T>& operator=(
const passive_ref_ptr<U>& x) {
282 x._t->weak_add_ref();
283 if (_t && _t->weak_release())
289 T& operator*()
const {
293 T* operator->()
const {
301 explicit operator bool()
const {
310template <
typename T,
typename U>
311inline bool operator==(
const ref_ptr<T> &a,
const ref_ptr<T> &b)
313 return a.get() == b.get();
316template <
typename T,
typename U>
317inline bool operator!=(
const ref_ptr<T> &a,
const ref_ptr<T> &b)
319 return a.get() != b.get();
322template <
typename T,
typename U>
323inline bool operator==(
const passive_ref_ptr<T> &a,
const passive_ref_ptr<T> &b)
325 return a.get() == b.get();
328template <
typename T,
typename U>
329inline bool operator!=(
const passive_ref_ptr<T> &a,
const passive_ref_ptr<T> &b)
331 return a.get() != b.get();
Namespace containing public Tamer classes and functions for the Tamer core.
Definition adapter.hh:17
bool operator!=(const fd &a, const fd &b)
Test whether two file descriptors refer to the same object.
Definition fd.hh:698
bool operator==(const fd &a, const fd &b)
Test whether two file descriptors refer to the same object.
Definition fd.hh:689