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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 110 |
111 operator T*() const { return fObj; } | 111 operator T*() const { return fObj; } |
112 T* operator->() const { SkASSERT(fObj); return fObj; } | 112 T* operator->() const { SkASSERT(fObj); return fObj; } |
113 | 113 |
114 T* detach() { T* obj = fObj; fObj = NULL; return obj; } | 114 T* detach() { T* obj = fObj; fObj = NULL; return obj; } |
115 void reset(T* obj = NULL) { | |
116 if (fObj != obj) { | |
117 if (fObj) { | |
118 P(fObj); | |
119 } | |
120 fObj = obj; | |
121 } | |
122 } | |
msarett
2015/04/09 16:26:32
I'm sure it is possible to implement gif rewinding
scroggo
2015/04/09 17:37:17
git blame is your friend. Using blame, I see we ad
msarett
2015/04/09 19:21:31
All good points. Seems like using SkAutoTCallCPro
| |
115 private: | 123 private: |
116 T* fObj; | 124 T* fObj; |
117 }; | 125 }; |
118 | 126 |
119 /** \class SkAutoTDelete | 127 /** \class SkAutoTDelete |
120 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete< T> | 128 An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete< T> |
121 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T > | 129 automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T > |
122 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold | 130 owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold |
123 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is | 131 either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is |
124 thread-compatible, and once you dereference it, you get the threadsafety | 132 thread-compatible, and once you dereference it, you get the threadsafety |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 /** | 515 /** |
508 * Returns void* because this object does not initialize the | 516 * Returns void* because this object does not initialize the |
509 * memory. Use placement new for types that require a cons. | 517 * memory. Use placement new for types that require a cons. |
510 */ | 518 */ |
511 void* get() { return fStorage.get(); } | 519 void* get() { return fStorage.get(); } |
512 private: | 520 private: |
513 SkAlignedSStorage<sizeof(T)*N> fStorage; | 521 SkAlignedSStorage<sizeof(T)*N> fStorage; |
514 }; | 522 }; |
515 | 523 |
516 #endif | 524 #endif |
OLD | NEW |