| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 Call a function when this goes out of scope. The template uses two | 100 Call a function when this goes out of scope. The template uses two |
| 101 parameters, the object, and a function that is to be called in the destructor. | 101 parameters, the object, and a function that is to be called in the destructor. |
| 102 If detach() is called, the object reference is set to null. If the object | 102 If detach() is called, the object reference is set to null. If the object |
| 103 reference is null when the destructor is called, we do not call the | 103 reference is null when the destructor is called, we do not call the |
| 104 function. | 104 function. |
| 105 */ | 105 */ |
| 106 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable { | 106 template <typename T, int (*P)(T*)> class SkAutoTCallIProc : SkNoncopyable { |
| 107 public: | 107 public: |
| 108 SkAutoTCallIProc(T* obj): fObj(obj) {} | 108 SkAutoTCallIProc(T* obj): fObj(obj) {} |
| 109 ~SkAutoTCallIProc() { if (fObj) P(fObj); } | 109 ~SkAutoTCallIProc() { if (fObj) P(fObj); } |
| 110 |
| 111 operator T*() const { return fObj; } |
| 112 T* operator->() const { SkASSERT(fObj); return fObj; } |
| 113 |
| 110 T* detach() { T* obj = fObj; fObj = NULL; return obj; } | 114 T* detach() { T* obj = fObj; fObj = NULL; return obj; } |
| 111 private: | 115 private: |
| 112 T* fObj; | 116 T* fObj; |
| 113 }; | 117 }; |
| 114 | 118 |
| 115 /** \class SkAutoTDelete | 119 /** \class SkAutoTDelete |
| 116 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete<
T> | 120 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete<
T> |
| 117 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T
> | 121 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T
> |
| 118 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold | 122 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold |
| 119 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is | 123 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 /** | 494 /** |
| 491 * Returns void* because this object does not initialize the | 495 * Returns void* because this object does not initialize the |
| 492 * memory. Use placement new for types that require a cons. | 496 * memory. Use placement new for types that require a cons. |
| 493 */ | 497 */ |
| 494 void* get() { return fStorage.get(); } | 498 void* get() { return fStorage.get(); } |
| 495 private: | 499 private: |
| 496 SkAlignedSStorage<sizeof(T)*N> fStorage; | 500 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 497 }; | 501 }; |
| 498 | 502 |
| 499 #endif | 503 #endif |
| OLD | NEW |