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 SkTemplates_DEFINED | 10 #ifndef SkTemplates_DEFINED |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 * Transfer ownership of the object to the caller, setting the internal | 136 * Transfer ownership of the object to the caller, setting the internal |
137 * pointer to NULL. Note that this differs from get(), which also returns | 137 * pointer to NULL. Note that this differs from get(), which also returns |
138 * the pointer, but it does not transfer ownership. | 138 * the pointer, but it does not transfer ownership. |
139 */ | 139 */ |
140 T* detach() { | 140 T* detach() { |
141 T* obj = fObj; | 141 T* obj = fObj; |
142 fObj = NULL; | 142 fObj = NULL; |
143 return obj; | 143 return obj; |
144 } | 144 } |
145 | 145 |
| 146 void swap(SkAutoTDelete* that) { |
| 147 SkTSwap(fObj, that->fObj); |
| 148 } |
| 149 |
146 private: | 150 private: |
147 T* fObj; | 151 T* fObj; |
148 }; | 152 }; |
149 | 153 |
150 // Calls ~T() in the destructor. | 154 // Calls ~T() in the destructor. |
151 template <typename T> class SkAutoTDestroy : SkNoncopyable { | 155 template <typename T> class SkAutoTDestroy : SkNoncopyable { |
152 public: | 156 public: |
153 SkAutoTDestroy(T* obj = NULL) : fObj(obj) {} | 157 SkAutoTDestroy(T* obj = NULL) : fObj(obj) {} |
154 ~SkAutoTDestroy() { | 158 ~SkAutoTDestroy() { |
155 if (NULL != fObj) { | 159 if (NULL != fObj) { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 /** | 462 /** |
459 * Returns void* because this object does not initialize the | 463 * Returns void* because this object does not initialize the |
460 * memory. Use placement new for types that require a cons. | 464 * memory. Use placement new for types that require a cons. |
461 */ | 465 */ |
462 void* get() { return fStorage.get(); } | 466 void* get() { return fStorage.get(); } |
463 private: | 467 private: |
464 SkAlignedSStorage<sizeof(T)*N> fStorage; | 468 SkAlignedSStorage<sizeof(T)*N> fStorage; |
465 }; | 469 }; |
466 | 470 |
467 #endif | 471 #endif |
OLD | NEW |