| 1 | /* |
| 2 | * Copyright (C) 2016 The Qt Company Ltd. |
| 3 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 4 | * |
| 5 | * SPDX-License-Identifier: MIT |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | #include <QtCore/qtconfigmacros.h> |
| 12 | #include <type_traits> |
| 13 | #endif |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | #ifdef QT_NAMESPACE |
| 17 | #define QT_NAMESPACE_REF ::QT_NAMESPACE::QtYoga |
| 18 | #else |
| 19 | #define QT_NAMESPACE_REF ::QtYoga |
| 20 | #endif |
| 21 | |
| 22 | #define USE_QT_YOGA_NAMESPACE using namespace QT_NAMESPACE_REF; |
| 23 | |
| 24 | #define QT_YOGA_NAMESPACE_BEGIN \ |
| 25 | QT_BEGIN_NAMESPACE \ |
| 26 | inline namespace QtYoga { |
| 27 | #define QT_YOGA_NAMESPACE_END \ |
| 28 | } \ |
| 29 | QT_END_NAMESPACE |
| 30 | #endif |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | #define YG_EXTERN_C_BEGIN // extern "C" { |
| 34 | #define YG_EXTERN_C_END // } |
| 35 | #else |
| 36 | #define YG_EXTERN_C_BEGIN |
| 37 | #define YG_EXTERN_C_END |
| 38 | #endif |
| 39 | |
| 40 | #if defined(__cplusplus) |
| 41 | #define YG_DEPRECATED(message) [[deprecated(message)]] |
| 42 | #elif defined(_MSC_VER) |
| 43 | #define YG_DEPRECATED(message) __declspec(deprecated(message)) |
| 44 | #else |
| 45 | #define YG_DEPRECATED(message) __attribute__((deprecated(message))) |
| 46 | #endif |
| 47 | |
| 48 | #ifdef _WINDLL |
| 49 | #define WIN_EXPORT // __declspec(dllexport) |
| 50 | #else |
| 51 | #define WIN_EXPORT |
| 52 | #endif |
| 53 | |
| 54 | #ifndef YOGA_EXPORT |
| 55 | #ifdef _MSC_VER |
| 56 | #define YOGA_EXPORT |
| 57 | #else |
| 58 | #define YOGA_EXPORT // __attribute__((visibility("default"))) |
| 59 | #endif |
| 60 | #endif |
| 61 | |
| 62 | #ifdef NS_ENUM |
| 63 | // Cannot use NSInteger as NSInteger has a different size than int (which is the |
| 64 | // default type of a enum). Therefor when linking the Yoga C library into obj-c |
| 65 | // the header is a mismatch for the Yoga ABI. |
| 66 | #define YG_ENUM_BEGIN(name) NS_ENUM(int, name) |
| 67 | #define YG_ENUM_END(name) |
| 68 | #else |
| 69 | #define YG_ENUM_BEGIN(name) enum name |
| 70 | #define YG_ENUM_END(name) name |
| 71 | #endif |
| 72 | |
| 73 | #ifdef __cplusplus |
| 74 | #define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \ |
| 75 | extern "C++" { \ |
| 76 | constexpr inline name operator~(name a) { \ |
| 77 | return static_cast<name>( \ |
| 78 | ~static_cast<std::underlying_type<name>::type>(a)); \ |
| 79 | } \ |
| 80 | constexpr inline name operator|(name a, name b) { \ |
| 81 | return static_cast<name>( \ |
| 82 | static_cast<std::underlying_type<name>::type>(a) | \ |
| 83 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 84 | } \ |
| 85 | constexpr inline name operator&(name a, name b) { \ |
| 86 | return static_cast<name>( \ |
| 87 | static_cast<std::underlying_type<name>::type>(a) & \ |
| 88 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 89 | } \ |
| 90 | constexpr inline name operator^(name a, name b) { \ |
| 91 | return static_cast<name>( \ |
| 92 | static_cast<std::underlying_type<name>::type>(a) ^ \ |
| 93 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 94 | } \ |
| 95 | inline name& operator|=(name& a, name b) { \ |
| 96 | return reinterpret_cast<name&>( \ |
| 97 | reinterpret_cast<std::underlying_type<name>::type&>(a) |= \ |
| 98 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 99 | } \ |
| 100 | inline name& operator&=(name& a, name b) { \ |
| 101 | return reinterpret_cast<name&>( \ |
| 102 | reinterpret_cast<std::underlying_type<name>::type&>(a) &= \ |
| 103 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 104 | } \ |
| 105 | inline name& operator^=(name& a, name b) { \ |
| 106 | return reinterpret_cast<name&>( \ |
| 107 | reinterpret_cast<std::underlying_type<name>::type&>(a) ^= \ |
| 108 | static_cast<std::underlying_type<name>::type>(b)); \ |
| 109 | } \ |
| 110 | } |
| 111 | #else |
| 112 | #define YG_DEFINE_ENUM_FLAG_OPERATORS(name) |
| 113 | #endif |
| 114 | |
| 115 | #ifdef __cplusplus |
| 116 | QT_YOGA_NAMESPACE_BEGIN |
| 117 | namespace facebook { |
| 118 | namespace yoga { |
| 119 | namespace enums { |
| 120 | |
| 121 | template <typename T> |
| 122 | constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9 |
| 123 | |
| 124 | namespace detail { |
| 125 | template <int... xs> |
| 126 | constexpr int n() { |
| 127 | return sizeof...(xs); |
| 128 | } |
| 129 | } // namespace detail |
| 130 | |
| 131 | } // namespace enums |
| 132 | } // namespace yoga |
| 133 | } // namespace facebook |
| 134 | QT_YOGA_NAMESPACE_END |
| 135 | #endif |
| 136 | |
| 137 | #define YG_ENUM_DECL(NAME, ...) \ |
| 138 | typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \ |
| 139 | WIN_EXPORT const char* NAME##ToString(NAME); |
| 140 | |
| 141 | #ifdef __cplusplus |
| 142 | #define YG_ENUM_SEQ_DECL(NAME, ...) \ |
| 143 | YG_ENUM_DECL(NAME, __VA_ARGS__) \ |
| 144 | QT_YOGA_NAMESPACE_BEGIN \ |
| 145 | YG_EXTERN_C_END \ |
| 146 | namespace facebook { \ |
| 147 | namespace yoga { \ |
| 148 | namespace enums { \ |
| 149 | template <> \ |
| 150 | constexpr int count<NAME>() { \ |
| 151 | return detail::n<__VA_ARGS__>(); \ |
| 152 | } \ |
| 153 | } \ |
| 154 | } \ |
| 155 | } \ |
| 156 | YG_EXTERN_C_BEGIN \ |
| 157 | QT_YOGA_NAMESPACE_END |
| 158 | #else |
| 159 | #define YG_ENUM_SEQ_DECL YG_ENUM_DECL |
| 160 | #endif |
| 161 | |