Chromium Code Reviews| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 T* detach() { | 112 T* detach() { |
| 113 T* obj = fObj; | 113 T* obj = fObj; |
| 114 fObj = NULL; | 114 fObj = NULL; |
| 115 return obj; | 115 return obj; |
| 116 } | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 T* fObj; | 119 T* fObj; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 // Calls ~T() in the destructor. | |
| 123 template <typename T> class SkAutoTDestroy : SkNoncopyable { | |
| 124 public: | |
| 125 SkAutoTDestroy(T* obj = NULL) : fObj(obj) {} | |
| 126 ~SkAutoTDestroy() { | |
|
robertphillips
2013/04/22 22:05:13
NULL !=
| |
| 127 if (fObj) { | |
| 128 fObj->~T(); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 T* get() const { return fObj; } | |
| 133 T& operator*() const { SkASSERT(fObj); return *fObj; } | |
| 134 T* operator->() const { SkASSERT(fObj); return fObj; } | |
| 135 | |
| 136 private: | |
| 137 T* fObj; | |
| 138 }; | |
| 139 | |
| 122 template <typename T> class SkAutoTDeleteArray : SkNoncopyable { | 140 template <typename T> class SkAutoTDeleteArray : SkNoncopyable { |
| 123 public: | 141 public: |
| 124 SkAutoTDeleteArray(T array[]) : fArray(array) {} | 142 SkAutoTDeleteArray(T array[]) : fArray(array) {} |
| 125 ~SkAutoTDeleteArray() { SkDELETE_ARRAY(fArray); } | 143 ~SkAutoTDeleteArray() { SkDELETE_ARRAY(fArray); } |
| 126 | 144 |
| 127 T* get() const { return fArray; } | 145 T* get() const { return fArray; } |
| 128 void free() { SkDELETE_ARRAY(fArray); fArray = NULL; } | 146 void free() { SkDELETE_ARRAY(fArray); fArray = NULL; } |
| 129 T* detach() { T* array = fArray; fArray = NULL; return array; } | 147 T* detach() { T* array = fArray; fArray = NULL; return array; } |
| 130 | 148 |
| 131 private: | 149 private: |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 /** | 373 /** |
| 356 * Returns void* because this object does not initialize the | 374 * Returns void* because this object does not initialize the |
| 357 * memory. Use placement new for types that require a cons. | 375 * memory. Use placement new for types that require a cons. |
| 358 */ | 376 */ |
| 359 void* get() { return fStorage.get(); } | 377 void* get() { return fStorage.get(); } |
| 360 private: | 378 private: |
| 361 SkAlignedSStorage<sizeof(T)*N> fStorage; | 379 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 362 }; | 380 }; |
| 363 | 381 |
| 364 #endif | 382 #endif |
| OLD | NEW |