| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkRefCnt_DEFINED | 10 #ifndef SkRefCnt_DEFINED |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 T* fObj; | 241 T* fObj; |
| 242 }; | 242 }; |
| 243 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 243 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
| 244 | 244 |
| 245 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 245 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
| 246 public: | 246 public: |
| 247 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 247 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
| 248 }; | 248 }; |
| 249 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) | 249 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) |
| 250 | 250 |
| 251 /** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to | |
| 252 a SkRefCnt (or subclass) object. | |
| 253 */ | |
| 254 template <typename T> class SkRefPtr { | |
| 255 public: | |
| 256 SkRefPtr() : fObj(NULL) {} | |
| 257 SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } | |
| 258 SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } | |
| 259 ~SkRefPtr() { SkSafeUnref(fObj); } | |
| 260 | |
| 261 SkRefPtr& operator=(const SkRefPtr& rp) { | |
| 262 SkRefCnt_SafeAssign(fObj, rp.fObj); | |
| 263 return *this; | |
| 264 } | |
| 265 SkRefPtr& operator=(T* obj) { | |
| 266 SkRefCnt_SafeAssign(fObj, obj); | |
| 267 return *this; | |
| 268 } | |
| 269 | |
| 270 T* get() const { return fObj; } | |
| 271 T& operator*() const { return *fObj; } | |
| 272 T* operator->() const { return fObj; } | |
| 273 | |
| 274 typedef T* SkRefPtr::*unspecified_bool_type; | |
| 275 operator unspecified_bool_type() const { | |
| 276 return fObj ? &SkRefPtr::fObj : NULL; | |
| 277 } | |
| 278 | |
| 279 private: | |
| 280 T* fObj; | |
| 281 }; | |
| 282 | |
| 283 #endif | 251 #endif |
| OLD | NEW |