docs
Loading...
Searching...
No Matches
Defines.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
6
7// Needed for limit defines, like INTMAX_MAX, which is used by the std C++ library
8#ifndef __STDC_LIMIT_MACROS
9#define __STDC_LIMIT_MACROS
10#endif
11
12#include <cstdint>
13#include <cstddef>
14#include <limits.h>
15
16#ifdef SWIG
17#define UExport
18#else
19
20#include <Ultralight/Config.h>
21#include <Ultralight/Exports.h>
22
23// Require C++20 Support
24#if defined(_MSC_VER)
25# if _MSC_VER < 1930
26# error This project needs at least Visual Studio 2022 to build
27# elif defined(_MSVC_LANG) && _MSVC_LANG < 202002L
28# error This project must be compiled with /std:c++20 or later
29# endif
30#elif __cplusplus < 202002L
31# error This project can only be compiled with a compiler that supports C++20
32#endif
33
34#if INTPTR_MAX == INT32_MAX
35# define UL_ARCH_32_BIT
36#elif INTPTR_MAX == INT64_MAX
37# define UL_ARCH_64_BIT
38#else
39# error "Unknown CPU architecture: environment not 32 or 64-bit."
40#endif
41
42#if defined(__aarch64__)
43# define UL_ARCH_ARM64
44# if defined(__APPLE__)
45# define UL_ARCH_ARM64_APPLE_SILICON
46# endif
47#endif
48
49#if defined(__WIN32__) || defined(_WIN32)
50# define _thread_local __declspec(thread)
51# ifndef _NATIVE_WCHAR_T_DEFINED
52# define DISABLE_NATIVE_WCHAR_T
53# endif
54#else
55# define _thread_local __thread
56#endif
57
58#ifndef UL_COMPILER_GCC_LIKE
59# if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
60# define UL_COMPILER_GCC_LIKE
61# endif
62#endif
63
64#ifndef UL_ALWAYS_INLINE
65#if defined(UL_COMPILER_GCC_LIKE) && defined(NDEBUG)
66# define UL_ALWAYS_INLINE inline __attribute__((__always_inline__))
67# elif defined(_MSC_VER) && defined(NDEBUG)
68# define UL_ALWAYS_INLINE __forceinline
69# else
70# define UL_ALWAYS_INLINE inline
71# endif
72#endif
73
74#ifndef UL_UNLIKELY
75# if defined(UL_COMPILER_GCC_LIKE)
76# define UL_UNLIKELY(x) __builtin_expect(!!(x), 0)
77# else
78# define UL_UNLIKELY(x) (x)
79# endif
80#endif
81
82#ifndef UL_LIKELY
83# if defined(UL_COMPILER_GCC_LIKE)
84# define UL_LIKELY(x) __builtin_expect(!!(x), 1)
85# else
86# define UL_LIKELY(x) (x)
87# endif
88#endif
89
90#ifndef UL_ALIGN
91 #if defined(UL_COMPILER_GCC_LIKE)
92 #define UL_ALIGN(x) __attribute__((aligned(x)))
93 #elif defined(__cplusplus) && __cplusplus >= 201103L
94 #define UL_ALIGN(x) alignas(x)
95 #elif defined(_MSC_VER)
96 #define UL_ALIGN(x) __declspec(align(x))
97 #else
98 #define UL_ALIGN(x)
99 #endif
100#endif
101
102#ifdef __cplusplus
103
104#include <type_traits>
105
106namespace ultralight {
107
108///
109/// Whether or not a scoped enum has opted into the bitmask operators below.
110///
111/// To opt in, declare `consteval void ul_enable_bitmask_operators(E);` beside the enum
112/// definition. The function needs only a declaration-- no body is needed. The operators find it
113/// through argument-dependent lookup.
114///
115/// Opting in enables `|`, `&`, `^`, `~`, `|=`, `&=`, and `^=`. The result of each operation
116/// keeps the enum type.
117///
118/// ```
119/// enum class Permissions : uint8_t {
120/// None = 0,
121/// Read = 1 << 0,
122/// Write = 1 << 1,
123/// };
124/// consteval void ul_enable_bitmask_operators(Permissions);
125///
126/// Permissions access = Permissions::Read | Permissions::Write;
127/// ```
128///
129/// @see HasFlag()
130///
131template <typename T>
132concept BitmaskEnum = std::is_enum_v<T> && requires(T e) { ul_enable_bitmask_operators(e); };
133
134template <BitmaskEnum T>
135constexpr T operator|(T a, T b) {
136 using U = std::underlying_type_t<T>;
137 return static_cast<T>(static_cast<U>(a) | static_cast<U>(b));
138}
139
140template <BitmaskEnum T>
141constexpr T operator&(T a, T b) {
142 using U = std::underlying_type_t<T>;
143 return static_cast<T>(static_cast<U>(a) & static_cast<U>(b));
144}
145
146template <BitmaskEnum T>
147constexpr T operator^(T a, T b) {
148 using U = std::underlying_type_t<T>;
149 return static_cast<T>(static_cast<U>(a) ^ static_cast<U>(b));
150}
151
152template <BitmaskEnum T>
153constexpr T operator~(T a) {
154 using U = std::underlying_type_t<T>;
155 return static_cast<T>(~static_cast<U>(a));
156}
157
158template <BitmaskEnum T>
159constexpr T& operator|=(T& a, T b) { return a = a | b; }
160
161template <BitmaskEnum T>
162constexpr T& operator&=(T& a, T b) { return a = a & b; }
163
164template <BitmaskEnum T>
165constexpr T& operator^=(T& a, T b) { return a = a ^ b; }
166
167///
168/// Whether or not every bit in `bits` is set in `flags`.
169///
170/// ```
171/// if (HasFlag(access, Permissions::Write)) { ... }
172/// ```
173///
174/// @param flags The value to test.
175///
176/// @param bits The bit or bits to look for.
177///
178/// @return Returns true when every bit of `bits` is set in `flags` (false when `bits` is zero).
179///
180template <BitmaskEnum T>
181constexpr bool HasFlag(T flags, T bits) {
182 using U = std::underlying_type_t<T>;
183 return (static_cast<U>(flags) & static_cast<U>(bits)) == static_cast<U>(bits)
184 && static_cast<U>(bits) != 0;
185}
186
187} // namespace ultralight
188
189#endif // #ifdef __cplusplus
190
191#endif // #ifdef SWIG
192
193#define ULTRALIGHT_VERSION "2.0.0"
194#define ULTRALIGHT_VERSION_MAJOR 2
195#define ULTRALIGHT_VERSION_MINOR 0
196#define ULTRALIGHT_VERSION_PATCH 0
197
198#define WEBKIT_VERSION "615.1.18.100.1"
199#define WEBKIT_VERSION_MAJOR 615
200#define WEBKIT_VERSION_MINOR 1
201#define WEBKIT_VERSION_TINY 18
202#define WEBKIT_VERSION_MICRO 100
203#define WEBKIT_VERSION_NANO 1
204
205///
206/// The platform token of ULTRALIGHT_USER_AGENT (the parenthesized part), chosen for the
207/// build's target OS. Apple builds report Intel on every architecture, as Safari does.
208///
209#if defined(_WIN32)
210# define ULTRALIGHT_USER_AGENT_PLATFORM "Windows NT 10.0; Win64; x64"
211#elif defined(__APPLE__)
212# define ULTRALIGHT_USER_AGENT_PLATFORM "Macintosh; Intel Mac OS X 10_15_7"
213#elif defined(__linux__) && defined(__aarch64__)
214# define ULTRALIGHT_USER_AGENT_PLATFORM "X11; Linux aarch64"
215#elif defined(__linux__)
216# define ULTRALIGHT_USER_AGENT_PLATFORM "X11; Linux x86_64"
217#else
218# define ULTRALIGHT_USER_AGENT_PLATFORM "Windows NT 10.0; Win64; x64"
219#endif
220
221#define ULTRALIGHT_USER_AGENT "Mozilla/5.0 (" ULTRALIGHT_USER_AGENT_PLATFORM ") " \
222 "AppleWebKit/" WEBKIT_VERSION " (KHTML, like Gecko) " \
223 "Ultralight/" ULTRALIGHT_VERSION " Version/16.4.1 " \
224 "Safari/" WEBKIT_VERSION
225
226#ifdef __cplusplus
227extern "C" {
228#endif
229
230///
231/// Full library version string (corresponds to ULTRALIGHT_VERSION)
232///
234
238
239///
240/// Full WebKit version string (corresponds to WEBKIT_VERSION)
241///
243
249
250#ifdef __cplusplus
251}
252#endif
#define UExport
Definition Exports.h:22
uint32_t UltralightVersionMinor()
uint32_t UltralightVersionPatch()
uint32_t WebKitVersionMinor()
uint32_t WebKitVersionNano()
uint32_t WebKitVersionMicro()
uint32_t WebKitVersionMajor()
uint32_t UltralightVersionMajor()
const char * WebKitVersionString()
Full WebKit version string (corresponds to WEBKIT_VERSION).
uint32_t WebKitVersionTiny()
const char * UltralightVersionString()
Full library version string (corresponds to ULTRALIGHT_VERSION).
Root namespace for every public Ultralight type, function, and enumeration.