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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 /** Check if the argument is non-null, and if so, call obj->unref() | 155 /** Check if the argument is non-null, and if so, call obj->unref() |
156 */ | 156 */ |
157 template <typename T> static inline void SkSafeUnref(T* obj) { | 157 template <typename T> static inline void SkSafeUnref(T* obj) { |
158 if (obj) { | 158 if (obj) { |
159 obj->unref(); | 159 obj->unref(); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
| 163 template<typename T> static inline void SkSafeSetNull(T*& obj) { |
| 164 if (NULL != obj) { |
| 165 obj->unref(); |
| 166 obj = NULL; |
| 167 } |
| 168 } |
| 169 |
163 /////////////////////////////////////////////////////////////////////////////// | 170 /////////////////////////////////////////////////////////////////////////////// |
164 | 171 |
165 /** | 172 /** |
166 * Utility class that simply unref's its argument in the destructor. | 173 * Utility class that simply unref's its argument in the destructor. |
167 */ | 174 */ |
168 template <typename T> class SkAutoTUnref : SkNoncopyable { | 175 template <typename T> class SkAutoTUnref : SkNoncopyable { |
169 public: | 176 public: |
170 explicit SkAutoTUnref(T* obj = NULL) : fObj(obj) {} | 177 explicit SkAutoTUnref(T* obj = NULL) : fObj(obj) {} |
171 ~SkAutoTUnref() { SkSafeUnref(fObj); } | 178 ~SkAutoTUnref() { SkSafeUnref(fObj); } |
172 | 179 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 typedef T* SkRefPtr::*unspecified_bool_type; | 272 typedef T* SkRefPtr::*unspecified_bool_type; |
266 operator unspecified_bool_type() const { | 273 operator unspecified_bool_type() const { |
267 return fObj ? &SkRefPtr::fObj : NULL; | 274 return fObj ? &SkRefPtr::fObj : NULL; |
268 } | 275 } |
269 | 276 |
270 private: | 277 private: |
271 T* fObj; | 278 T* fObj; |
272 }; | 279 }; |
273 | 280 |
274 #endif | 281 #endif |
OLD | NEW |