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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 guarantees of T. | 125 guarantees of T. |
126 | 126 |
127 The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*) | 127 The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*) |
128 */ | 128 */ |
129 template <typename T> class SkAutoTDelete : SkNoncopyable { | 129 template <typename T> class SkAutoTDelete : SkNoncopyable { |
130 public: | 130 public: |
131 SkAutoTDelete(T* obj = NULL) : fObj(obj) {} | 131 SkAutoTDelete(T* obj = NULL) : fObj(obj) {} |
132 ~SkAutoTDelete() { SkDELETE(fObj); } | 132 ~SkAutoTDelete() { SkDELETE(fObj); } |
133 | 133 |
134 T* get() const { return fObj; } | 134 T* get() const { return fObj; } |
135 operator T*() { return fObj; } | 135 operator T*() const { return fObj; } |
136 T& operator*() const { SkASSERT(fObj); return *fObj; } | 136 T& operator*() const { SkASSERT(fObj); return *fObj; } |
137 T* operator->() const { SkASSERT(fObj); return fObj; } | 137 T* operator->() const { SkASSERT(fObj); return fObj; } |
138 | 138 |
139 void reset(T* obj) { | 139 void reset(T* obj) { |
140 if (fObj != obj) { | 140 if (fObj != obj) { |
141 SkDELETE(fObj); | 141 SkDELETE(fObj); |
142 fObj = obj; | 142 fObj = obj; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 /** | 507 /** |
508 * Returns void* because this object does not initialize the | 508 * Returns void* because this object does not initialize the |
509 * memory. Use placement new for types that require a cons. | 509 * memory. Use placement new for types that require a cons. |
510 */ | 510 */ |
511 void* get() { return fStorage.get(); } | 511 void* get() { return fStorage.get(); } |
512 private: | 512 private: |
513 SkAlignedSStorage<sizeof(T)*N> fStorage; | 513 SkAlignedSStorage<sizeof(T)*N> fStorage; |
514 }; | 514 }; |
515 | 515 |
516 #endif | 516 #endif |
OLD | NEW |