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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 ~SkAutoTMalloc() { | 265 ~SkAutoTMalloc() { |
266 sk_free(fPtr); | 266 sk_free(fPtr); |
267 } | 267 } |
268 | 268 |
269 /** Resize the memory area pointed to by the current ptr preserving contents
. */ | 269 /** Resize the memory area pointed to by the current ptr preserving contents
. */ |
270 void realloc(size_t count) { | 270 void realloc(size_t count) { |
271 fPtr = reinterpret_cast<T*>(sk_realloc_throw(fPtr, count * sizeof(T))); | 271 fPtr = reinterpret_cast<T*>(sk_realloc_throw(fPtr, count * sizeof(T))); |
272 } | 272 } |
273 | 273 |
274 /** Resize the memory area pointed to by the current ptr without preserving
contents. */ | 274 /** Resize the memory area pointed to by the current ptr without preserving
contents. */ |
275 void reset(size_t count) { | 275 T* reset(size_t count) { |
276 sk_free(fPtr); | 276 sk_free(fPtr); |
277 fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW); | 277 fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW); |
| 278 return fPtr; |
278 } | 279 } |
279 | 280 |
280 T* get() const { return fPtr; } | 281 T* get() const { return fPtr; } |
281 | 282 |
282 operator T*() { | 283 operator T*() { |
283 return fPtr; | 284 return fPtr; |
284 } | 285 } |
285 | 286 |
286 operator const T*() const { | 287 operator const T*() const { |
287 return fPtr; | 288 return fPtr; |
288 } | 289 } |
289 | 290 |
290 T& operator[](int index) { | 291 T& operator[](int index) { |
291 return fPtr[index]; | 292 return fPtr[index]; |
292 } | 293 } |
293 | 294 |
294 const T& operator[](int index) const { | 295 const T& operator[](int index) const { |
295 return fPtr[index]; | 296 return fPtr[index]; |
296 } | 297 } |
297 | 298 |
298 /** | 299 /** |
| 300 * Releases the block back to the heap |
| 301 */ |
| 302 void free() { |
| 303 this->reset(0); |
| 304 } |
| 305 |
| 306 /** |
299 * Transfer ownership of the ptr to the caller, setting the internal | 307 * Transfer ownership of the ptr to the caller, setting the internal |
300 * pointer to NULL. Note that this differs from get(), which also returns | 308 * pointer to NULL. Note that this differs from get(), which also returns |
301 * the pointer, but it does not transfer ownership. | 309 * the pointer, but it does not transfer ownership. |
302 */ | 310 */ |
303 T* detach() { | 311 T* detach() { |
304 T* ptr = fPtr; | 312 T* ptr = fPtr; |
305 fPtr = NULL; | 313 fPtr = NULL; |
306 return ptr; | 314 return ptr; |
307 } | 315 } |
308 | 316 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 * Returns void* because this object does not initialize the | 450 * Returns void* because this object does not initialize the |
443 * memory. Use placement new for types that require a cons. | 451 * memory. Use placement new for types that require a cons. |
444 */ | 452 */ |
445 void* get() { return fStorage.get(); } | 453 void* get() { return fStorage.get(); } |
446 const void* get() const { return fStorage.get(); } | 454 const void* get() const { return fStorage.get(); } |
447 private: | 455 private: |
448 SkAlignedSStorage<sizeof(T)*N> fStorage; | 456 SkAlignedSStorage<sizeof(T)*N> fStorage; |
449 }; | 457 }; |
450 | 458 |
451 #endif | 459 #endif |
OLD | NEW |