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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return fPtr; | 74 return fPtr; |
75 } | 75 } |
76 | 76 |
77 /** | 77 /** |
78 * Returns true if a valid object has been initialized in the SkTLazy, | 78 * Returns true if a valid object has been initialized in the SkTLazy, |
79 * false otherwise. | 79 * false otherwise. |
80 */ | 80 */ |
81 bool isValid() const { return NULL != fPtr; } | 81 bool isValid() const { return NULL != fPtr; } |
82 | 82 |
83 /** | 83 /** |
84 * Returns either NULL, or a copy of the object that was passed to | 84 * Returns the object. This version should only be called when the caller |
85 * set() or the constructor. | 85 * knows that the object has been initialized. |
86 */ | 86 */ |
87 T* get() const { SkASSERT(this->isValid()); return fPtr; } | 87 T* get() const { SkASSERT(this->isValid()); return fPtr; } |
| 88 |
| 89 /** |
| 90 * Like above but doesn't assert if object isn't initialized (in which case |
| 91 * NULL is returned). |
| 92 */ |
| 93 T* getMaybeNull() const { return fPtr; } |
88 | 94 |
89 private: | 95 private: |
90 friend void* operator new<T>(size_t, SkTLazy* lazy); | 96 friend void* operator new<T>(size_t, SkTLazy* lazy); |
91 | 97 |
92 T* fPtr; // NULL or fStorage | 98 T* fPtr; // NULL or fStorage |
93 char fStorage[sizeof(T)]; | 99 char fStorage[sizeof(T)]; |
94 }; | 100 }; |
95 | 101 |
96 // Use the below macro (SkNEW_IN_TLAZY) rather than calling this directly | 102 // Use the below macro (SkNEW_IN_TLAZY) rather than calling this directly |
97 template <typename T> void* operator new(size_t, SkTLazy<T>* lazy) { | 103 template <typename T> void* operator new(size_t, SkTLazy<T>* lazy) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 operator const T*() const { return fObj; } | 173 operator const T*() const { return fObj; } |
168 | 174 |
169 const T& operator *() const { return *fObj; } | 175 const T& operator *() const { return *fObj; } |
170 | 176 |
171 private: | 177 private: |
172 const T* fObj; | 178 const T* fObj; |
173 SkTLazy<T> fLazy; | 179 SkTLazy<T> fLazy; |
174 }; | 180 }; |
175 | 181 |
176 #endif | 182 #endif |
OLD | NEW |