gfx/skia/trunk/src/utils/SkTLogic.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 *
michael@0 7 *
michael@0 8 * This header provides some of the helpers (std::integral_constant) and
michael@0 9 * type transformations (std::conditional) which will become available with
michael@0 10 * C++11 in the type_traits header.
michael@0 11 *
michael@0 12 * Because we lack constexpr, we cannot mimic
michael@0 13 * std::integral_constant::'constexpr operator T()'.
michael@0 14 * As a result we introduce SkTBool and SkTIf similar to Boost in order to
michael@0 15 * minimize the visual noise of many uses of '::value'.
michael@0 16 */
michael@0 17
michael@0 18 #ifndef SkTLogic_DEFINED
michael@0 19 #define SkTLogic_DEFINED
michael@0 20
michael@0 21 /** Represents a templated integer constant.
michael@0 22 * Pre-C++11 version of std::integral_constant.
michael@0 23 */
michael@0 24 template <typename T, T v> struct SkTIntegralConstant {
michael@0 25 static const T value = v;
michael@0 26 typedef T value_type;
michael@0 27 typedef SkTIntegralConstant<T, v> type;
michael@0 28 };
michael@0 29
michael@0 30 /** Convenience specialization of SkTIntegralConstant. */
michael@0 31 template <bool b> struct SkTBool : SkTIntegralConstant<bool, b> { };
michael@0 32
michael@0 33 /** Pre-C++11 version of std::true_type. */
michael@0 34 typedef SkTBool<true> SkTrue;
michael@0 35
michael@0 36 /** Pre-C++11 version of std::false_type. */
michael@0 37 typedef SkTBool<false> SkFalse;
michael@0 38
michael@0 39 /** SkTIf_c::type = (condition) ? T : F;
michael@0 40 * Pre-C++11 version of std::conditional.
michael@0 41 */
michael@0 42 template <bool condition, typename T, typename F> struct SkTIf_c {
michael@0 43 typedef F type;
michael@0 44 };
michael@0 45 template <typename T, typename F> struct SkTIf_c<true, T, F> {
michael@0 46 typedef T type;
michael@0 47 };
michael@0 48
michael@0 49 /** SkTIf::type = (Condition::value) ? T : F; */
michael@0 50 template <typename Condition, typename T, typename F> struct SkTIf {
michael@0 51 typedef typename SkTIf_c<static_cast<bool>(Condition::value), T, F>::type type;
michael@0 52 };
michael@0 53
michael@0 54 /** SkTMux::type = (a && b) ? Both : (a) ? A : (b) ? B : Neither; */
michael@0 55 template <typename a, typename b, typename Both, typename A, typename B, typename Neither>
michael@0 56 struct SkTMux {
michael@0 57 typedef typename SkTIf<a, typename SkTIf<b, Both, A>::type,
michael@0 58 typename SkTIf<b, B, Neither>::type>::type type;
michael@0 59 };
michael@0 60
michael@0 61 #endif

mercurial