slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
YGMacros.h
浏览该文件的文档.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#ifdef __cplusplus
11#include <type_traits>
12#endif
13
14#ifdef __cplusplus
15#define YG_EXTERN_C_BEGIN extern "C" {
16#define YG_EXTERN_C_END }
17#else
18#define YG_EXTERN_C_BEGIN
19#define YG_EXTERN_C_END
20#endif
21
22#if defined(__cplusplus)
23#define YG_DEPRECATED(message) [[deprecated(message)]]
24#elif defined(_MSC_VER)
25#define YG_DEPRECATED(message) __declspec(deprecated(message))
26#else
27#define YG_DEPRECATED(message) __attribute__((deprecated(message)))
28#endif
29
30#ifdef _WINDLL
31#define YG_EXPORT __declspec(dllexport)
32#elif defined(__EMSCRIPTEN__)
33#define YG_EXPORT __attribute__((visibility("default"), used))
34#elif !defined(_MSC_VER)
35#define YG_EXPORT __attribute__((visibility("default")))
36#else
37#define YG_EXPORT
38#endif
39
40#ifdef __OBJC__
41#if __has_include(<Foundation/Foundation.h>)
42#import <Foundation/Foundation.h>
43#endif
44#endif
45
46#ifdef NS_ENUM
47// Cannot use NSInteger as NSInteger has a different size than int (which is the
48// default type of a enum). Therefor when linking the Yoga C library into obj-c
49// the header is a mismatch for the Yoga ABI.
50#define YG_ENUM_BEGIN(name) NS_ENUM(int, name)
51#define YG_ENUM_END(name)
52#else
53#define YG_ENUM_BEGIN(name) enum name
54#define YG_ENUM_END(name) name
55#endif
56
57#ifdef __cplusplus
58#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \
59 extern "C++" { \
60 constexpr name operator~(name a) { \
61 return static_cast<name>( \
62 ~static_cast<std::underlying_type<name>::type>(a)); \
63 } \
64 constexpr name operator|(name a, name b) { \
65 return static_cast<name>( \
66 static_cast<std::underlying_type<name>::type>(a) | \
67 static_cast<std::underlying_type<name>::type>(b)); \
68 } \
69 constexpr name operator&(name a, name b) { \
70 return static_cast<name>( \
71 static_cast<std::underlying_type<name>::type>(a) & \
72 static_cast<std::underlying_type<name>::type>(b)); \
73 } \
74 constexpr name operator^(name a, name b) { \
75 return static_cast<name>( \
76 static_cast<std::underlying_type<name>::type>(a) ^ \
77 static_cast<std::underlying_type<name>::type>(b)); \
78 } \
79 inline name& operator|=(name& a, name b) { \
80 return reinterpret_cast<name&>( \
81 reinterpret_cast<std::underlying_type<name>::type&>(a) |= \
82 static_cast<std::underlying_type<name>::type>(b)); \
83 } \
84 inline name& operator&=(name& a, name b) { \
85 return reinterpret_cast<name&>( \
86 reinterpret_cast<std::underlying_type<name>::type&>(a) &= \
87 static_cast<std::underlying_type<name>::type>(b)); \
88 } \
89 inline name& operator^=(name& a, name b) { \
90 return reinterpret_cast<name&>( \
91 reinterpret_cast<std::underlying_type<name>::type&>(a) ^= \
92 static_cast<std::underlying_type<name>::type>(b)); \
93 } \
94 }
95#else
96#define YG_DEFINE_ENUM_FLAG_OPERATORS(name)
97#endif
98
99#define YG_ENUM_DECL(NAME, ...) \
100 typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
101 YG_EXPORT const char* NAME##ToString(NAME);