| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 */ | 91 */ |
| 92 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable { | 92 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable { |
| 93 public: | 93 public: |
| 94 SkAutoTCallIProc(T* obj): fObj(obj) {} | 94 SkAutoTCallIProc(T* obj): fObj(obj) {} |
| 95 ~SkAutoTCallIProc() { if (fObj) P(fObj); } | 95 ~SkAutoTCallIProc() { if (fObj) P(fObj); } |
| 96 T* detach() { T* obj = fObj; fObj = NULL; return obj; } | 96 T* detach() { T* obj = fObj; fObj = NULL; return obj; } |
| 97 private: | 97 private: |
| 98 T* fObj; | 98 T* fObj; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 /** \class SkAutoTDelete |
| 102 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete<
T> |
| 103 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T
> |
| 104 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold |
| 105 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is |
| 106 thread-compatible, and once you dereference it, you get the threadsafety |
| 107 guarantees of T. |
| 108 |
| 109 The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*) |
| 110 */ |
| 101 template <typename T> class SkAutoTDelete : SkNoncopyable { | 111 template <typename T> class SkAutoTDelete : SkNoncopyable { |
| 102 public: | 112 public: |
| 103 SkAutoTDelete(T* obj = NULL) : fObj(obj) {} | 113 SkAutoTDelete(T* obj = NULL) : fObj(obj) {} |
| 104 ~SkAutoTDelete() { SkDELETE(fObj); } | 114 ~SkAutoTDelete() { SkDELETE(fObj); } |
| 105 | 115 |
| 106 T* get() const { return fObj; } | 116 T* get() const { return fObj; } |
| 107 T& operator*() const { SkASSERT(fObj); return *fObj; } | 117 T& operator*() const { SkASSERT(fObj); return *fObj; } |
| 108 T* operator->() const { SkASSERT(fObj); return fObj; } | 118 T* operator->() const { SkASSERT(fObj); return fObj; } |
| 109 | 119 |
| 110 void reset(T* obj) { | 120 void reset(T* obj) { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 /** | 458 /** |
| 449 * Returns void* because this object does not initialize the | 459 * Returns void* because this object does not initialize the |
| 450 * memory. Use placement new for types that require a cons. | 460 * memory. Use placement new for types that require a cons. |
| 451 */ | 461 */ |
| 452 void* get() { return fStorage.get(); } | 462 void* get() { return fStorage.get(); } |
| 453 private: | 463 private: |
| 454 SkAlignedSStorage<sizeof(T)*N> fStorage; | 464 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 455 }; | 465 }; |
| 456 | 466 |
| 457 #endif | 467 #endif |
| OLD | NEW |