OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 T* set(const T& src) { | 68 T* set(const T& src) { |
69 if (this->isValid()) { | 69 if (this->isValid()) { |
70 *fPtr = src; | 70 *fPtr = src; |
71 } else { | 71 } else { |
72 fPtr = new (SkTCast<T*>(fStorage)) T(src); | 72 fPtr = new (SkTCast<T*>(fStorage)) T(src); |
73 } | 73 } |
74 return fPtr; | 74 return fPtr; |
75 } | 75 } |
76 | 76 |
77 /** | 77 /** |
| 78 * Destroy the lazy object (if it was created via init() or set()) |
| 79 */ |
| 80 void reset() { |
| 81 if (this->isValid()) { |
| 82 fPtr->~T(); |
| 83 fPtr = NULL; |
| 84 } |
| 85 } |
| 86 |
| 87 /** |
78 * Returns true if a valid object has been initialized in the SkTLazy, | 88 * Returns true if a valid object has been initialized in the SkTLazy, |
79 * false otherwise. | 89 * false otherwise. |
80 */ | 90 */ |
81 bool isValid() const { return NULL != fPtr; } | 91 bool isValid() const { return NULL != fPtr; } |
82 | 92 |
83 /** | 93 /** |
84 * Returns the object. This version should only be called when the caller | 94 * Returns the object. This version should only be called when the caller |
85 * knows that the object has been initialized. | 95 * knows that the object has been initialized. |
86 */ | 96 */ |
87 T* get() const { SkASSERT(this->isValid()); return fPtr; } | 97 T* get() const { SkASSERT(this->isValid()); return fPtr; } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 operator const T*() const { return fObj; } | 183 operator const T*() const { return fObj; } |
174 | 184 |
175 const T& operator *() const { return *fObj; } | 185 const T& operator *() const { return *fObj; } |
176 | 186 |
177 private: | 187 private: |
178 const T* fObj; | 188 const T* fObj; |
179 SkTLazy<T> fLazy; | 189 SkTLazy<T> fLazy; |
180 }; | 190 }; |
181 | 191 |
182 #endif | 192 #endif |
OLD | NEW |