Chromium Code Reviews| Index: src/utils/SkTLogic.h |
| =================================================================== |
| --- src/utils/SkTLogic.h (revision 0) |
| +++ src/utils/SkTLogic.h (working copy) |
| @@ -0,0 +1,39 @@ |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkTLogic_DEFINED |
| +#define SkTLogic_DEFINED |
| + |
|
mtklein
2013/07/11 14:56:57
Some sort of high-level what's-going-on-here would
bungeman-skia
2013/07/11 20:22:03
Sure, added comment that this is basically providi
|
| +/** SkTBool::type = self; SkTBool::value = b; */ |
| +template <bool b> struct SkTBool { |
| + typedef SkTBool type; |
| + static const bool value = b; |
| +}; |
| +typedef SkTBool<true> SkTrue; |
| +typedef SkTBool<false> SkFalse; |
| + |
| +/** SkTIf_c::type = (condition) ? T : F; */ |
| +template <bool condition, typename T, typename F> struct SkTIf_c { |
| + typedef F type; |
| +}; |
| +template <typename T, typename F> struct SkTIf_c<true, T, F> { |
| + typedef T type; |
| +}; |
| + |
| +/** SkTIf::type = (Condition::value) ? T : F; */ |
| +template <typename Condition, typename T, typename F> struct SkTIf { |
| + typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type type; |
| +}; |
| + |
| +/** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */ |
| +template <typename a, typename b, typename Both, typename A, typename B, typename Neither> |
| +struct SkTMux { |
| + typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type, |
| + typename SkTIf<b, B, Neither>::type>::type type; |
| +}; |
| + |
| +#endif |