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 class SkAutoRef : SkNoncopyable { | |
252 public: | |
253 SkAutoRef(SkRefCnt* obj) : fObj(obj) { SkSafeRef(obj); } | |
254 ~SkAutoRef() { SkSafeUnref(fObj); } | |
255 private: | |
256 SkRefCnt* fObj; | |
257 }; | |
258 #define SkAutoRef(...) SK_REQUIRE_LOCAL_VAR(SkAutoRef) | |
259 | |
260 /** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to | 251 /** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to |
261 a SkRefCnt (or subclass) object. | 252 a SkRefCnt (or subclass) object. |
262 */ | 253 */ |
263 template <typename T> class SkRefPtr { | 254 template <typename T> class SkRefPtr { |
264 public: | 255 public: |
265 SkRefPtr() : fObj(NULL) {} | 256 SkRefPtr() : fObj(NULL) {} |
266 SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } | 257 SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); } |
267 SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } | 258 SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); } |
268 ~SkRefPtr() { SkSafeUnref(fObj); } | 259 ~SkRefPtr() { SkSafeUnref(fObj); } |
269 | 260 |
(...skipping 13 matching lines...) Expand all Loading... |
283 typedef T* SkRefPtr::*unspecified_bool_type; | 274 typedef T* SkRefPtr::*unspecified_bool_type; |
284 operator unspecified_bool_type() const { | 275 operator unspecified_bool_type() const { |
285 return fObj ? &SkRefPtr::fObj : NULL; | 276 return fObj ? &SkRefPtr::fObj : NULL; |
286 } | 277 } |
287 | 278 |
288 private: | 279 private: |
289 T* fObj; | 280 T* fObj; |
290 }; | 281 }; |
291 | 282 |
292 #endif | 283 #endif |
OLD | NEW |