| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkTFitsIn_DEFINED | 8 #ifndef SkTFitsIn_DEFINED |
| 9 #define SkTFitsIn_DEFINED | 9 #define SkTFitsIn_DEFINED |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 /** A low side predicate which tests if the source value < Min(D). | 34 /** A low side predicate which tests if the source value < Min(D). |
| 35 * Assumes that Min(S) <= Min(D). | 35 * Assumes that Min(S) <= Min(D). |
| 36 */ | 36 */ |
| 37 template <typename D, typename S> struct SkTOutOfRange_LT_MinD { | 37 template <typename D, typename S> struct SkTOutOfRange_LT_MinD { |
| 38 typedef SkTrue can_be_true; | 38 typedef SkTrue can_be_true; |
| 39 typedef S source_type; | 39 typedef S source_type; |
| 40 static bool apply(S s) { | 40 static bool apply(S s) { |
| 41 typedef typename SkTHasMoreDigits<S, D>::type precondition; | 41 typedef typename SkTHasMoreDigits<S, D>::type precondition; |
| 42 SK_COMPILE_ASSERT(precondition::value, SkTOutOfRange_LT_MinD__minS_gt_mi
nD); | 42 static_assert(precondition::value, "SkTOutOfRange_LT_MinD__minS_gt_minD"
); |
| 43 | 43 |
| 44 return s < static_cast<S>((std::numeric_limits<D>::min)()); | 44 return s < static_cast<S>((std::numeric_limits<D>::min)()); |
| 45 } | 45 } |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 /** A low side predicate which tests if the source value is less than 0. */ | 48 /** A low side predicate which tests if the source value is less than 0. */ |
| 49 template <typename D, typename S> struct SkTOutOfRange_LT_Zero { | 49 template <typename D, typename S> struct SkTOutOfRange_LT_Zero { |
| 50 typedef SkTrue can_be_true; | 50 typedef SkTrue can_be_true; |
| 51 typedef S source_type; | 51 typedef S source_type; |
| 52 static bool apply(S s) { | 52 static bool apply(S s) { |
| 53 return s < static_cast<S>(0); | 53 return s < static_cast<S>(0); |
| 54 } | 54 } |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 /** A high side predicate which tests if the source value > Max(D). | 57 /** A high side predicate which tests if the source value > Max(D). |
| 58 * Assumes that Max(S) >= Max(D). | 58 * Assumes that Max(S) >= Max(D). |
| 59 */ | 59 */ |
| 60 template <typename D, typename S> struct SkTOutOfRange_GT_MaxD { | 60 template <typename D, typename S> struct SkTOutOfRange_GT_MaxD { |
| 61 typedef SkTrue can_be_true; | 61 typedef SkTrue can_be_true; |
| 62 typedef S source_type; | 62 typedef S source_type; |
| 63 static bool apply(S s) { | 63 static bool apply(S s) { |
| 64 typedef typename SkTHasMoreDigits<S, D>::type precondition; | 64 typedef typename SkTHasMoreDigits<S, D>::type precondition; |
| 65 SK_COMPILE_ASSERT(precondition::value, SkTOutOfRange_GT_MaxD__maxS_lt_ma
xD); | 65 static_assert(precondition::value, "SkTOutOfRange_GT_MaxD__maxS_lt_maxD"
); |
| 66 | 66 |
| 67 return s > static_cast<S>((std::numeric_limits<D>::max)()); | 67 return s > static_cast<S>((std::numeric_limits<D>::max)()); |
| 68 } | 68 } |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 /** Composes two SkTOutOfRange predicates. | 71 /** Composes two SkTOutOfRange predicates. |
| 72 * First checks OutOfRange_Low then, if in range, OutOfRange_High. | 72 * First checks OutOfRange_Low then, if in range, OutOfRange_High. |
| 73 */ | 73 */ |
| 74 template<class OutOfRange_Low, class OutOfRange_High> struct SkTOutOfRange_Eithe
r { | 74 template<class OutOfRange_Low, class OutOfRange_High> struct SkTOutOfRange_Eithe
r { |
| 75 typedef SkTrue can_be_true; | 75 typedef SkTrue can_be_true; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 typedef typename SkTMux<S_is_signed, D_is_signed, S2S, S2U, U2S, U2U>::type
selector; | 193 typedef typename SkTMux<S_is_signed, D_is_signed, S2S, S2U, U2S, U2U>::type
selector; |
| 194 // This type is an SkTRangeChecker. | 194 // This type is an SkTRangeChecker. |
| 195 typedef typename selector::type type; | 195 typedef typename selector::type type; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 } // namespace Private | 198 } // namespace Private |
| 199 } // namespace sktfitsin | 199 } // namespace sktfitsin |
| 200 | 200 |
| 201 /** Returns true if the integer source value 's' will fit in the integer destina
tion type 'D'. */ | 201 /** Returns true if the integer source value 's' will fit in the integer destina
tion type 'D'. */ |
| 202 template <typename D, typename S> inline bool SkTFitsIn(S s) { | 202 template <typename D, typename S> inline bool SkTFitsIn(S s) { |
| 203 SK_COMPILE_ASSERT(std::numeric_limits<S>::is_integer, SkTFitsIn_source_must_
be_integer); | 203 static_assert(std::numeric_limits<S>::is_integer, "SkTFitsIn_source_must_be_
integer"); |
| 204 SK_COMPILE_ASSERT(std::numeric_limits<D>::is_integer, SkTFitsIn_destination_
must_be_integer); | 204 static_assert(std::numeric_limits<D>::is_integer, "SkTFitsIn_destination_mus
t_be_integer"); |
| 205 | 205 |
| 206 return !sktfitsin::Private::SkTFitsIn<D, S>::type::OutOfRange(s); | 206 return !sktfitsin::Private::SkTFitsIn<D, S>::type::OutOfRange(s); |
| 207 } | 207 } |
| 208 | 208 |
| 209 #endif | 209 #endif |
| OLD | NEW |