| 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 |
| 11 #define SkTemplates_DEFINED | 11 #define SkTemplates_DEFINED |
| 12 | 12 |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 #include <climits> |
| 15 #include <limits> |
| 14 #include <new> | 16 #include <new> |
| 15 | 17 |
| 16 /** \file SkTemplates.h | 18 /** \file SkTemplates.h |
| 17 | 19 |
| 18 This file contains light-weight template classes for type-safe and exception
-safe | 20 This file contains light-weight template classes for type-safe and exception
-safe |
| 19 resource management. | 21 resource management. |
| 20 */ | 22 */ |
| 21 | 23 |
| 22 /** | 24 /** |
| 23 * Marks a local variable as known to be unused (to avoid warnings). | 25 * Marks a local variable as known to be unused (to avoid warnings). |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 * Returns a pointer to a D which comes byteOffset bytes after S. | 59 * Returns a pointer to a D which comes byteOffset bytes after S. |
| 58 */ | 60 */ |
| 59 template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
et) { | 61 template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
et) { |
| 60 // The intermediate char* has the same const-ness as D as this produces bett
er error messages. | 62 // The intermediate char* has the same const-ness as D as this produces bett
er error messages. |
| 61 // This relies on the fact that reinterpret_cast can add constness, but cann
ot remove it. | 63 // This relies on the fact that reinterpret_cast can add constness, but cann
ot remove it. |
| 62 return reinterpret_cast<D*>( | 64 return reinterpret_cast<D*>( |
| 63 reinterpret_cast<typename SkTConstType<char, SkTIsConst<D>::value>::type
*>(ptr) + byteOffset | 65 reinterpret_cast<typename SkTConstType<char, SkTIsConst<D>::value>::type
*>(ptr) + byteOffset |
| 64 ); | 66 ); |
| 65 } | 67 } |
| 66 | 68 |
| 69 /** SkTSetBit<N, T>::value is a T with the Nth bit set. */ |
| 70 template<unsigned N, typename T = uintmax_t> struct SkTSetBit { |
| 71 static const T value = static_cast<T>(1) << N; |
| 72 SK_COMPILE_ASSERT(sizeof(T)*CHAR_BIT > N, SkTSetBit_N_too_large); |
| 73 SK_COMPILE_ASSERT(std::numeric_limits<T>::is_integer, SkTSetBit_T_must_be_in
teger); |
| 74 SK_COMPILE_ASSERT(!std::numeric_limits<T>::is_signed, SkTSetBit_T_must_be_un
signed); |
| 75 SK_COMPILE_ASSERT(std::numeric_limits<T>::radix == 2, SkTSetBit_T_radix_must
_be_2); |
| 76 }; |
| 77 |
| 67 /** \class SkAutoTCallVProc | 78 /** \class SkAutoTCallVProc |
| 68 | 79 |
| 69 Call a function when this goes out of scope. The template uses two | 80 Call a function when this goes out of scope. The template uses two |
| 70 parameters, the object, and a function that is to be called in the destructo
r. | 81 parameters, the object, and a function that is to be called in the destructo
r. |
| 71 If detach() is called, the object reference is set to null. If the object | 82 If detach() is called, the object reference is set to null. If the object |
| 72 reference is null when the destructor is called, we do not call the | 83 reference is null when the destructor is called, we do not call the |
| 73 function. | 84 function. |
| 74 */ | 85 */ |
| 75 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { | 86 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { |
| 76 public: | 87 public: |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 /** | 480 /** |
| 470 * Returns void* because this object does not initialize the | 481 * Returns void* because this object does not initialize the |
| 471 * memory. Use placement new for types that require a cons. | 482 * memory. Use placement new for types that require a cons. |
| 472 */ | 483 */ |
| 473 void* get() { return fStorage.get(); } | 484 void* get() { return fStorage.get(); } |
| 474 private: | 485 private: |
| 475 SkAlignedSStorage<sizeof(T)*N> fStorage; | 486 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 476 }; | 487 }; |
| 477 | 488 |
| 478 #endif | 489 #endif |
| OLD | NEW |