1/* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7#ifndef SkMacros_DEFINED 8#define SkMacros_DEFINED 9 10/* 11 * Usage: SK_MACRO_CONCAT(a, b) to construct the symbol ab 12 * 13 * SK_MACRO_CONCAT_IMPL_PRIV just exists to make this work. Do not use directly 14 * 15 */ 16#define SK_MACRO_CONCAT(X, Y) SK_MACRO_CONCAT_IMPL_PRIV(X, Y) 17#define SK_MACRO_CONCAT_IMPL_PRIV(X, Y) X ## Y 18 19/* 20 * Usage: SK_MACRO_APPEND_LINE(foo) to make foo123, where 123 is the current 21 * line number. Easy way to construct 22 * unique names for local functions or 23 * variables. 24 */ 25#define SK_MACRO_APPEND_LINE(name) SK_MACRO_CONCAT(name, __LINE__) 26 27#define SK_MACRO_APPEND_COUNTER(name) SK_MACRO_CONCAT(name, __COUNTER__) 28 29//////////////////////////////////////////////////////////////////////////////// 30 31// Can be used to bracket data types that must be dense, e.g. hash keys. 32#if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop didn't seem to work! 33 #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \ 34 _Pragma("GCC diagnostic error \"-Wpadded\"") 35 #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop") 36#else 37 #define SK_BEGIN_REQUIRE_DENSE 38 #define SK_END_REQUIRE_DENSE 39#endif 40 41#define SK_INIT_TO_AVOID_WARNING = 0 42 43//////////////////////////////////////////////////////////////////////////////// 44 45/** 46 * Defines overloaded bitwise operators to make it easier to use an enum as a 47 * bitfield. 48 */ 49#define SK_MAKE_BITFIELD_OPS(X) \ 50 inline X operator |(X a, X b) { \ 51 return (X) (+a | +b); \ 52 } \ 53 inline X& operator |=(X& a, X b) { \ 54 return (a = a | b); \ 55 } \ 56 inline X operator &(X a, X b) { \ 57 return (X) (+a & +b); \ 58 } \ 59 inline X& operator &=(X& a, X b) { \ 60 return (a = a & b); \ 61 } \ 62 template <typename T> \ 63 inline X operator &(T a, X b) { \ 64 return (X) (+a & +b); \ 65 } \ 66 template <typename T> \ 67 inline X operator &(X a, T b) { \ 68 return (X) (+a & +b); \ 69 } \ 70 71#define SK_DECL_BITFIELD_OPS_FRIENDS(X) \ 72 friend X operator |(X a, X b); \ 73 friend X& operator |=(X& a, X b); \ 74 \ 75 friend X operator &(X a, X b); \ 76 friend X& operator &=(X& a, X b); \ 77 \ 78 template <typename T> \ 79 friend X operator &(T a, X b); \ 80 \ 81 template <typename T> \ 82 friend X operator &(X a, T b); \ 83 84#endif // SkMacros_DEFINED 85