19 #ifndef GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H
20 #define GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H
24 #include <type_traits>
48 value_ = other.value_;
49 other.value_ =
nullptr;
53 value_ =
static_cast<T*
>(other.value_);
54 other.value_ =
nullptr;
60 other.value_ =
nullptr;
66 other.value_ =
nullptr;
72 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
73 value_ = other.value_;
77 static_assert(std::has_virtual_destructor<T>::value,
78 "T does not have a virtual dtor");
79 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
80 value_ =
static_cast<T*
>(other.value_);
87 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
93 static_assert(std::has_virtual_destructor<T>::value,
94 "T does not have a virtual dtor");
97 if (other.value_ !=
nullptr) other.value_->IncrementRefCount();
103 if (value_ !=
nullptr) value_->Unref();
110 if (value_ !=
nullptr) value_->Unref();
114 T* value =
nullptr) {
115 if (value_ !=
nullptr) value_->Unref(location, reason);
118 template <
typename Y>
120 static_assert(std::has_virtual_destructor<T>::value,
121 "T does not have a virtual dtor");
122 if (value_ !=
nullptr) value_->Unref();
123 value_ =
static_cast<T*
>(value);
125 template <
typename Y>
127 Y* value =
nullptr) {
128 static_assert(std::has_virtual_destructor<T>::value,
129 "T does not have a virtual dtor");
130 if (value_ !=
nullptr) value_->Unref(location, reason);
131 value_ =
static_cast<T*
>(value);
144 T*
get()
const {
return value_; }
149 template <
typename Y>
151 return value_ == other.value_;
154 template <
typename Y>
156 return value_ == other;
159 bool operator==(std::nullptr_t)
const {
return value_ ==
nullptr; }
161 template <
typename Y>
163 return value_ != other.value_;
166 template <
typename Y>
168 return value_ != other;
171 bool operator!=(std::nullptr_t)
const {
return value_ !=
nullptr; }
174 template <
typename Y>
180 template <
typename T,
typename... Args>
Definition: debug_location.h:31
Definition: ref_counted_ptr.h:35
bool operator!=(std::nullptr_t) const
Definition: ref_counted_ptr.h:171
RefCountedPtr & operator=(const RefCountedPtr &other)
Definition: ref_counted_ptr.h:84
bool operator==(const Y *other) const
Definition: ref_counted_ptr.h:155
RefCountedPtr(RefCountedPtr &&other)
Definition: ref_counted_ptr.h:47
bool operator==(const RefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:150
bool operator!=(const RefCountedPtr< Y > &other) const
Definition: ref_counted_ptr.h:162
bool operator!=(const Y *other) const
Definition: ref_counted_ptr.h:167
void reset(Y *value=nullptr)
Definition: ref_counted_ptr.h:119
T * get() const
Definition: ref_counted_ptr.h:144
T * operator->() const
Definition: ref_counted_ptr.h:147
void reset(const DebugLocation &location, const char *reason, Y *value=nullptr)
Definition: ref_counted_ptr.h:126
RefCountedPtr & operator=(const RefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:92
RefCountedPtr & operator=(RefCountedPtr &&other)
Definition: ref_counted_ptr.h:58
T * release()
Definition: ref_counted_ptr.h:138
~RefCountedPtr()
Definition: ref_counted_ptr.h:102
RefCountedPtr(const RefCountedPtr< Y > &other)
Definition: ref_counted_ptr.h:76
bool operator==(std::nullptr_t) const
Definition: ref_counted_ptr.h:159
void swap(RefCountedPtr &other)
Definition: ref_counted_ptr.h:106
RefCountedPtr(RefCountedPtr< Y > &&other)
Definition: ref_counted_ptr.h:52
RefCountedPtr(std::nullptr_t)
Definition: ref_counted_ptr.h:38
RefCountedPtr(Y *value)
Definition: ref_counted_ptr.h:42
RefCountedPtr()
Definition: ref_counted_ptr.h:37
T & operator*() const
Definition: ref_counted_ptr.h:146
void reset(const DebugLocation &location, const char *reason, T *value=nullptr)
Definition: ref_counted_ptr.h:113
RefCountedPtr & operator=(RefCountedPtr< Y > &&other)
Definition: ref_counted_ptr.h:64
void reset(T *value=nullptr)
Definition: ref_counted_ptr.h:109
RefCountedPtr(const RefCountedPtr &other)
Definition: ref_counted_ptr.h:71
Internal thread interface.
Definition: backoff.h:26
RefCountedPtr< T > MakeRefCounted(Args &&... args)
Definition: ref_counted_ptr.h:181