31 #ifndef PAGESPEED_KERNEL_UTIL_REF_COUNTED_PTR_H_
32 #define PAGESPEED_KERNEL_UTIL_REF_COUNTED_PTR_H_
34 #include "base/logging.h"
38 namespace net_instaweb {
48 delete static_cast<T*
>(
this);
57 return (ref_count_.
value() == 1);
87 : ptr_(static_cast<T*>(src.ptr_)) {
101 if (other.ptr_ != NULL) {
102 other.ptr_->AddRef();
113 if (other.ptr_ != NULL) {
114 other.ptr_->AddRef();
119 ptr_ =
static_cast<T*
>(other.ptr_);
123 T* operator->()
const {
return ptr_; }
124 T*
get()
const {
return ptr_; }
129 bool unique()
const {
return !this->ptr_ || this->ptr_->HasOneRef(); }
137 *
this = RefCountedPtr();
140 *
this = RefCountedPtr(ptr);
142 void reset(
const RefCountedPtr& src) {
147 template <
class U>
friend class RefCountedPtr;
148 operator void*()
const;
170 bool unique()
const {
return data_ptr_.unique(); }
172 T*
get() {
return &data_ptr_->value; }
173 const T*
get()
const {
return &data_ptr_->value; }
174 T* operator->() {
return &data_ptr_->value; }
175 const T* operator->()
const {
return &data_ptr_->value; }
176 T& operator*() {
return data_ptr_->value; }
177 const T& operator*()
const {
return data_ptr_->value; }
182 void reset(
const T& val) { data_ptr_.reset(
new Data(val)); }
187 explicit Data(
const T& val) : value(val) {}
194 operator void*()
const;
209 #define REFCOUNT_FRIEND_DECLARATION(class_name) \
210 friend class net_instaweb::RefCounted<class_name>
int32 BarrierIncrement(int32 amount)
Definition: atomic_int32.h:101
Definition: atomic_int32.h:72
Definition: ref_counted_ptr.h:41
Definition: ref_counted_ptr.h:185
bool unique() const
Definition: ref_counted_ptr.h:129
Definition: ref_counted_ptr.h:69
RefCountedPtr< T > & operator=(const RefCountedPtr< T > &other)
Definition: ref_counted_ptr.h:99
bool unique() const
Definition: ref_counted_ptr.h:170
void reset(const T &val)
Definition: ref_counted_ptr.h:182
int32 NoBarrierIncrement(int32 amount)
Definition: atomic_int32.h:95
int32 value() const
Return the value currently stored. Has acquire semantics (see above).
Definition: atomic_int32.h:83
Definition: ref_counted_ptr.h:162