diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-28 16:19:45 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-28 16:19:45 +0000 |
commit | 2e0c32af0508a1e544c9953ea2fe128dbae7d429 (patch) | |
tree | 1f1b7bb5c4017b25400f6cc6e73602d63326d72b /src/utils | |
parent | a36c78240e14aeb130a97c43f3992ea19696b929 (diff) |
Start using type traits in src/record instead of macros.
Simplified skip logic by always running clip commands. No performance difference on bot or silk SKPs.
BUG=skia:2378
R=bungeman@google.com, fmalita@chromium.org, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/258693006
git-svn-id: http://skia.googlecode.com/svn/trunk@14410 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/SkTLogic.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/utils/SkTLogic.h b/src/utils/SkTLogic.h index bf9ee1ab25..62952ad13c 100644 --- a/src/utils/SkTLogic.h +++ b/src/utils/SkTLogic.h @@ -58,4 +58,35 @@ struct SkTMux { typename SkTIf<b, B, Neither>::type>::type type; }; +/** SkTEnableIf_c::type = (condition) ? T : [does not exist]; */ +template <bool condition, class T = void> struct SkTEnableIf_c { }; +template <class T> struct SkTEnableIf_c<true, T> { + typedef T type; +}; + +/** SkTEnableIf::type = (Condition::value) ? T : [does not exist]; */ +template <class Condition, class T = void> struct SkTEnableIf + : public SkTEnableIf_c<static_cast<bool>(Condition::value), T> { }; + +/** Use as a return type to enable a function only when cond_type::value is true, + * like C++14's std::enable_if_t. E.g. (N.B. this is a dumb example.) + * SK_WHEN(SkTrue, int) f(void* ptr) { return 1; } + * SK_WHEN(!SkTrue, int) f(void* ptr) { return 2; } + */ +#define SK_WHEN(cond_prefix, T) typename SkTEnableIf_c<cond_prefix::value, T>::type + +// See http://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector +#define SK_CREATE_MEMBER_DETECTOR(member) \ +template <typename T> \ +class HasMember_##member { \ + struct Fallback { int member; }; \ + struct Derived : T, Fallback {}; \ + template <typename U, U> struct Check; \ + template <typename U> static uint8_t func(Check<int Fallback::*, &U::member>*); \ + template <typename U> static uint16_t func(...); \ +public: \ + typedef HasMember_##member type; \ + static const bool value = sizeof(func<Derived>(NULL)) == sizeof(uint16_t); \ +} + #endif |