Chromium Code Reviews| Index: include/core/SkTemplates.h |
| =================================================================== |
| --- include/core/SkTemplates.h (revision 8808) |
| +++ include/core/SkTemplates.h (working copy) |
| @@ -119,6 +119,24 @@ |
| T* fObj; |
| }; |
| +// Calls ~T() in the destructor. |
| +template <typename T> class SkAutoTDestroy : SkNoncopyable { |
| +public: |
| + SkAutoTDestroy(T* obj = NULL) : fObj(obj) {} |
| + ~SkAutoTDestroy() { |
|
robertphillips
2013/04/22 22:05:13
NULL !=
|
| + if (fObj) { |
| + fObj->~T(); |
| + } |
| + } |
| + |
| + T* get() const { return fObj; } |
| + T& operator*() const { SkASSERT(fObj); return *fObj; } |
| + T* operator->() const { SkASSERT(fObj); return fObj; } |
| + |
| +private: |
| + T* fObj; |
| +}; |
| + |
| template <typename T> class SkAutoTDeleteArray : SkNoncopyable { |
| public: |
| SkAutoTDeleteArray(T array[]) : fArray(array) {} |