| 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 }; | 457 }; |
| 458 }; | 458 }; |
| 459 | 459 |
| 460 /** | 460 /** |
| 461 * Reserves memory that is aligned on double and pointer boundaries. | 461 * Reserves memory that is aligned on double and pointer boundaries. |
| 462 * Hopefully this is sufficient for all practical purposes. | 462 * Hopefully this is sufficient for all practical purposes. |
| 463 */ | 463 */ |
| 464 template <size_t N> class SkAlignedSStorage : SkNoncopyable { | 464 template <size_t N> class SkAlignedSStorage : SkNoncopyable { |
| 465 public: | 465 public: |
| 466 void* get() { return fData; } | 466 void* get() { return fData; } |
| 467 const void* get() const { return fData; } |
| 467 private: | 468 private: |
| 468 union { | 469 union { |
| 469 void* fPtr; | 470 void* fPtr; |
| 470 double fDouble; | 471 double fDouble; |
| 471 char fData[N]; | 472 char fData[N]; |
| 472 }; | 473 }; |
| 473 }; | 474 }; |
| 474 | 475 |
| 475 /** | 476 /** |
| 476 * Reserves memory that is aligned on double and pointer boundaries. | 477 * Reserves memory that is aligned on double and pointer boundaries. |
| 477 * Hopefully this is sufficient for all practical purposes. Otherwise, | 478 * Hopefully this is sufficient for all practical purposes. Otherwise, |
| 478 * we have to do some arcane trickery to determine alignment of non-POD | 479 * we have to do some arcane trickery to determine alignment of non-POD |
| 479 * types. Lifetime of the memory is the lifetime of the object. | 480 * types. Lifetime of the memory is the lifetime of the object. |
| 480 */ | 481 */ |
| 481 template <int N, typename T> class SkAlignedSTStorage : SkNoncopyable { | 482 template <int N, typename T> class SkAlignedSTStorage : SkNoncopyable { |
| 482 public: | 483 public: |
| 483 /** | 484 /** |
| 484 * Returns void* because this object does not initialize the | 485 * Returns void* because this object does not initialize the |
| 485 * memory. Use placement new for types that require a cons. | 486 * memory. Use placement new for types that require a cons. |
| 486 */ | 487 */ |
| 487 void* get() { return fStorage.get(); } | 488 void* get() { return fStorage.get(); } |
| 488 private: | 489 private: |
| 489 SkAlignedSStorage<sizeof(T)*N> fStorage; | 490 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 490 }; | 491 }; |
| 491 | 492 |
| 492 #endif | 493 #endif |
| OLD | NEW |