1#ifndef BASE_CORE_REFCOUNT_H_
2#define BASE_CORE_REFCOUNT_H_
52 mutable std::atomic_int_fast32_t
ref_;
85 static_assert(std::is_base_of<counted_base, T>::value,
86 "T must be derived from counted_base");
89 return std::unique_ptr<T, ref_count_deleter>();
92 return std::unique_ptr<T, ref_count_deleter>(ptr);
109 if (this->get() ==
nullptr) {
110 return std::unique_ptr<T, ref_count_deleter>();
113 return std::unique_ptr<T, ref_count_deleter>(this->get());
The base class for reference-counted objects.
Definition refcount.h:14
std::atomic_int_fast32_t ref_
Definition refcount.h:52
virtual ~counted_base()
Virtual destructor.
Definition refcount.h:49
bool unref() const
Decreases the reference count by one.
Definition refcount.cpp:13
bool ref_count_is_one() const
Checks if the reference count is one.
Definition refcount.cpp:25
counted_base(const counted_base &)=delete
void operator=(const counted_base &)=delete
int_fast32_t ref_count() const
Gets the current reference count.
Definition refcount.cpp:21
void ref() const
Increases the reference count by one.
Definition refcount.cpp:9
counted_base()
Default constructor. Initializes the reference count to one.
Definition refcount.cpp:7
A smart pointer that holds a reference-counted object and releases it on destruction.
Definition refcount.h:100
std::unique_ptr< T, ref_count_deleter > get_new_ref() const
Adds a new reference to the owned object.
Definition refcount.h:108
#define T
Definition exp.cpp:237
std::unique_ptr< T, ref_count_deleter > get_new_ref(T *ptr)
Adds a new reference to a counted_base pointer.
Definition refcount.h:84
A deleter functor for creating std::unique_ptr that unrefs objects.
Definition refcount.h:60
void operator()(const counted_base *o) const
Calls unref on the object.
Definition refcount.h:65