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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 * Returns a pointer to a D which comes byteOffset bytes after S. | 57 * Returns a pointer to a D which comes byteOffset bytes after S. |
58 */ | 58 */ |
59 template <typename D, typename S> static D* SkTAddOffset(S* ptr, size_t byteOffs
et) { | 59 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. | 60 // 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. | 61 // This relies on the fact that reinterpret_cast can add constness, but cann
ot remove it. |
62 return reinterpret_cast<D*>( | 62 return reinterpret_cast<D*>( |
63 reinterpret_cast<typename SkTConstType<char, SkTIsConst<D>::value>::type
*>(ptr) + byteOffset | 63 reinterpret_cast<typename SkTConstType<char, SkTIsConst<D>::value>::type
*>(ptr) + byteOffset |
64 ); | 64 ); |
65 } | 65 } |
66 | 66 |
67 /** Returns true if the source value 's' will fit in the destination type 'D'. *
/ | |
68 template <typename D, typename S> inline bool SkTFitsIn(S s) { | |
69 // the cast to <S> is just to restore the signedness of S, to avoid | |
70 // sign-unsigned comparison warnings. | |
71 return static_cast<S>(static_cast<D>(s)) == s; | |
72 } | |
73 | |
74 /** \class SkAutoTCallVProc | 67 /** \class SkAutoTCallVProc |
75 | 68 |
76 Call a function when this goes out of scope. The template uses two | 69 Call a function when this goes out of scope. The template uses two |
77 parameters, the object, and a function that is to be called in the destructo
r. | 70 parameters, the object, and a function that is to be called in the destructo
r. |
78 If detach() is called, the object reference is set to null. If the object | 71 If detach() is called, the object reference is set to null. If the object |
79 reference is null when the destructor is called, we do not call the | 72 reference is null when the destructor is called, we do not call the |
80 function. | 73 function. |
81 */ | 74 */ |
82 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { | 75 template <typename T, void (*P)(T*)> class SkAutoTCallVProc : SkNoncopyable { |
83 public: | 76 public: |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 /** | 447 /** |
455 * Returns void* because this object does not initialize the | 448 * Returns void* because this object does not initialize the |
456 * memory. Use placement new for types that require a cons. | 449 * memory. Use placement new for types that require a cons. |
457 */ | 450 */ |
458 void* get() { return fStorage.get(); } | 451 void* get() { return fStorage.get(); } |
459 private: | 452 private: |
460 SkAlignedSStorage<sizeof(T)*N> fStorage; | 453 SkAlignedSStorage<sizeof(T)*N> fStorage; |
461 }; | 454 }; |
462 | 455 |
463 #endif | 456 #endif |
OLD | NEW |