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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 * skAutoTUnrefInstance->ref() and skAutoTUnrefInstance->unref(). | 230 * skAutoTUnrefInstance->ref() and skAutoTUnrefInstance->unref(). |
231 */ | 231 */ |
232 BlockRefType *operator->() const { | 232 BlockRefType *operator->() const { |
233 return static_cast<BlockRefType*>(fObj); | 233 return static_cast<BlockRefType*>(fObj); |
234 } | 234 } |
235 operator T*() { return fObj; } | 235 operator T*() { return fObj; } |
236 | 236 |
237 private: | 237 private: |
238 T* fObj; | 238 T* fObj; |
239 }; | 239 }; |
| 240 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
240 | 241 |
241 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 242 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
242 public: | 243 public: |
243 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 244 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
244 }; | 245 }; |
| 246 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) |
245 | 247 |
246 class SkAutoRef : SkNoncopyable { | 248 class SkAutoRef : SkNoncopyable { |
247 public: | 249 public: |
248 SkAutoRef(SkRefCnt* obj) : fObj(obj) { SkSafeRef(obj); } | 250 SkAutoRef(SkRefCnt* obj) : fObj(obj) { SkSafeRef(obj); } |
249 ~SkAutoRef() { SkSafeUnref(fObj); } | 251 ~SkAutoRef() { SkSafeUnref(fObj); } |
250 private: | 252 private: |
251 SkRefCnt* fObj; | 253 SkRefCnt* fObj; |
252 }; | 254 }; |
| 255 #define SkAutoRef(...) SK_REQUIRE_LOCAL_VAR(SkAutoRef) |
253 | 256 |
254 /** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to | 257 /** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to |
255 a SkRefCnt (or subclass) object. | 258 a SkRefCnt (or subclass) object. |
256 */ | 259 */ |
257 template <typename T> class SkRefPtr { | 260 template <typename T> class SkRefPtr { |
258 public: | 261 public: |
259 SkRefPtr() : fObj(NULL) {} | 262 SkRefPtr() : fObj(NULL) {} |
260 SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } | 263 SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } |
261 SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } | 264 SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } |
262 ~SkRefPtr() { SkSafeUnref(fObj); } | 265 ~SkRefPtr() { SkSafeUnref(fObj); } |
(...skipping 14 matching lines...) Expand all Loading... |
277 typedef T* SkRefPtr::*unspecified_bool_type; | 280 typedef T* SkRefPtr::*unspecified_bool_type; |
278 operator unspecified_bool_type() const { | 281 operator unspecified_bool_type() const { |
279 return fObj ? &SkRefPtr::fObj : NULL; | 282 return fObj ? &SkRefPtr::fObj : NULL; |
280 } | 283 } |
281 | 284 |
282 private: | 285 private: |
283 T* fObj; | 286 T* fObj; |
284 }; | 287 }; |
285 | 288 |
286 #endif | 289 #endif |
OLD | NEW |