2019-06-06 19:36:56 -07:00
|
|
|
/*
|
2021-12-30 15:08:43 -08:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2014-10-29 08:01:22 -07:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2014-10-29 08:01:22 -07:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2016-08-02 08:07:09 -07:00
|
|
|
#pragma once
|
2014-09-18 15:15:21 -07:00
|
|
|
|
2023-04-27 03:15:14 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <type_traits>
|
|
|
|
#endif
|
|
|
|
|
2016-07-25 06:31:32 -07:00
|
|
|
#ifdef __cplusplus
|
2016-12-03 04:40:18 -08:00
|
|
|
#define YG_EXTERN_C_BEGIN extern "C" {
|
|
|
|
#define YG_EXTERN_C_END }
|
2016-07-25 06:31:32 -07:00
|
|
|
#else
|
2016-12-03 04:40:18 -08:00
|
|
|
#define YG_EXTERN_C_BEGIN
|
|
|
|
#define YG_EXTERN_C_END
|
2016-07-25 06:31:32 -07:00
|
|
|
#endif
|
2016-08-02 08:07:11 -07:00
|
|
|
|
2023-04-30 08:20:05 -07:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define YG_DEPRECATED(message) [[deprecated(message)]]
|
|
|
|
#elif defined(_MSC_VER)
|
2023-04-30 11:06:02 -07:00
|
|
|
#define YG_DEPRECATED(message) __declspec(deprecated(message))
|
2023-04-30 08:20:05 -07:00
|
|
|
#else
|
|
|
|
#define YG_DEPRECATED(message) __attribute__((deprecated(message)))
|
|
|
|
#endif
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
#ifdef _WINDLL
|
|
|
|
#define WIN_EXPORT __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
#define WIN_EXPORT
|
|
|
|
#endif
|
|
|
|
|
2019-11-01 11:45:19 -07:00
|
|
|
#ifndef YOGA_EXPORT
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define YOGA_EXPORT
|
|
|
|
#else
|
|
|
|
#define YOGA_EXPORT __attribute__((visibility("default")))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-01-09 08:34:56 -08:00
|
|
|
#ifdef NS_ENUM
|
2019-01-08 12:47:53 -08:00
|
|
|
// Cannot use NSInteger as NSInteger has a different size than int (which is the
|
|
|
|
// default type of a enum). Therefor when linking the Yoga C library into obj-c
|
2023-03-21 16:29:09 -07:00
|
|
|
// the header is a mismatch for the Yoga ABI.
|
2017-01-09 08:34:56 -08:00
|
|
|
#define YG_ENUM_BEGIN(name) NS_ENUM(int, name)
|
|
|
|
#define YG_ENUM_END(name)
|
2017-01-08 11:42:43 -08:00
|
|
|
#else
|
2017-01-09 08:34:56 -08:00
|
|
|
#define YG_ENUM_BEGIN(name) enum name
|
2017-01-08 11:42:43 -08:00
|
|
|
#define YG_ENUM_END(name) name
|
|
|
|
#endif
|
2019-05-29 07:38:12 -07:00
|
|
|
|
2023-04-27 03:15:14 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \
|
|
|
|
extern "C++" { \
|
|
|
|
constexpr inline name operator~(name a) { \
|
|
|
|
return static_cast<name>( \
|
|
|
|
~static_cast<std::underlying_type<name>::type>(a)); \
|
|
|
|
} \
|
|
|
|
constexpr inline name operator|(name a, name b) { \
|
|
|
|
return static_cast<name>( \
|
|
|
|
static_cast<std::underlying_type<name>::type>(a) | \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
constexpr inline name operator&(name a, name b) { \
|
|
|
|
return static_cast<name>( \
|
|
|
|
static_cast<std::underlying_type<name>::type>(a) & \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
constexpr inline name operator^(name a, name b) { \
|
|
|
|
return static_cast<name>( \
|
|
|
|
static_cast<std::underlying_type<name>::type>(a) ^ \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
inline name& operator|=(name& a, name b) { \
|
|
|
|
return reinterpret_cast<name&>( \
|
|
|
|
reinterpret_cast<std::underlying_type<name>::type&>(a) |= \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
inline name& operator&=(name& a, name b) { \
|
|
|
|
return reinterpret_cast<name&>( \
|
|
|
|
reinterpret_cast<std::underlying_type<name>::type&>(a) &= \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
inline name& operator^=(name& a, name b) { \
|
|
|
|
return reinterpret_cast<name&>( \
|
|
|
|
reinterpret_cast<std::underlying_type<name>::type&>(a) ^= \
|
|
|
|
static_cast<std::underlying_type<name>::type>(b)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define YG_DEFINE_ENUM_FLAG_OPERATORS(name)
|
|
|
|
#endif
|
|
|
|
|
2022-09-29 22:25:24 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
namespace facebook {
|
|
|
|
namespace yoga {
|
|
|
|
namespace enums {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr int count(); // can't use `= delete` due to a defect in clang < 3.9
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template <int... xs>
|
|
|
|
constexpr int n() {
|
|
|
|
return sizeof...(xs);
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
} // namespace enums
|
|
|
|
} // namespace yoga
|
|
|
|
} // namespace facebook
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define YG_ENUM_DECL(NAME, ...) \
|
|
|
|
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
|
|
|
|
WIN_EXPORT const char* NAME##ToString(NAME);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define YG_ENUM_SEQ_DECL(NAME, ...) \
|
|
|
|
YG_ENUM_DECL(NAME, __VA_ARGS__) \
|
|
|
|
YG_EXTERN_C_END \
|
|
|
|
namespace facebook { \
|
|
|
|
namespace yoga { \
|
|
|
|
namespace enums { \
|
|
|
|
template <> \
|
|
|
|
constexpr int count<NAME>() { \
|
|
|
|
return detail::n<__VA_ARGS__>(); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
YG_EXTERN_C_BEGIN
|
|
|
|
#else
|
|
|
|
#define YG_ENUM_SEQ_DECL YG_ENUM_DECL
|
|
|
|
#endif
|