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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 Call a function when this goes out of scope. The template uses two | 70 Call a function when this goes out of scope. The template uses two |
71 parameters, the object, and a function that is to be called in the destructo
r. | 71 parameters, the object, and a function that is to be called in the destructo
r. |
72 If detach() is called, the object reference is set to null. If the object | 72 If detach() is called, the object reference is set to null. If the object |
73 reference is null when the destructor is called, we do not call the | 73 reference is null when the destructor is called, we do not call the |
74 function. | 74 function. |
75 */ | 75 */ |
76 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { | 76 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { |
77 public: | 77 public: |
78 SkAutoTCallVProc(T* obj): fObj(obj) {} | 78 SkAutoTCallVProc(T* obj): fObj(obj) {} |
79 ~SkAutoTCallVProc() { if (fObj) P(fObj); } | 79 ~SkAutoTCallVProc() { if (fObj) P(fObj); } |
| 80 |
| 81 operator T*() const { return fObj; } |
| 82 T& operator*() const { SkASSERT(fObj); return *fObj; } |
| 83 T* operator->() const { SkASSERT(fObj); return fObj; } |
| 84 |
80 T* detach() { T* obj = fObj; fObj = NULL; return obj; } | 85 T* detach() { T* obj = fObj; fObj = NULL; return obj; } |
| 86 void reset(T* obj = NULL) { |
| 87 if (fObj != obj) { |
| 88 if (fObj) { |
| 89 P(fObj); |
| 90 } |
| 91 fObj = obj; |
| 92 } |
| 93 } |
81 private: | 94 private: |
82 T* fObj; | 95 T* fObj; |
83 }; | 96 }; |
84 | 97 |
85 /** \class SkAutoTCallIProc | 98 /** \class SkAutoTCallIProc |
86 | 99 |
87 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 |
88 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. |
89 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 |
90 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 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 /** | 483 /** |
471 * Returns void* because this object does not initialize the | 484 * Returns void* because this object does not initialize the |
472 * memory. Use placement new for types that require a cons. | 485 * memory. Use placement new for types that require a cons. |
473 */ | 486 */ |
474 void* get() { return fStorage.get(); } | 487 void* get() { return fStorage.get(); } |
475 private: | 488 private: |
476 SkAlignedSStorage<sizeof(T)*N> fStorage; | 489 SkAlignedSStorage<sizeof(T)*N> fStorage; |
477 }; | 490 }; |
478 | 491 |
479 #endif | 492 #endif |
OLD | NEW |