UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Common.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Base Declarations
3
4#pragma once
5
6#include <stdlib.h> // size_t etc.
7#include <stdint.h> // Sized integer types, minimums and maximums: int##_t, uint##_t, INT##_MAX, UINT##_MAX
8#include <new> // placement new
9
10//------------------------------------------------------------------
11// Sanity check platform defines
12#ifndef ULANG_PLATFORM
13#error ULANG_PLATFORM must be defined.
14#endif
15
16#ifndef ULANG_PLATFORM_WINDOWS
17// Windows requires special handling for now...
18#define ULANG_PLATFORM_WINDOWS 0
19#endif
20
21#if !defined(ULANG_PLATFORM_MAC)
22#define ULANG_PLATFORM_MAC 0
23#endif
24
25#if !defined(ULANG_PLATFORM_LINUX)
26#define ULANG_PLATFORM_LINUX 0
27#endif
28
29#define ULANG_PLATFORM_POSIX (ULANG_PLATFORM_MAC || ULANG_PLATFORM_LINUX)
30
31#ifndef ULANG_PLATFORM_EXTENSION
32#define ULANG_PLATFORM_EXTENSION 0
33#endif
34
35//------------------------------------------------------------------
36// Define macros to help with the inclusion of platform specific headers
37#define ULANG_STRINGIFY(x) ULANG_STRINGIFY_INNER(x)
38#define ULANG_STRINGIFY_INNER(x) #x
39
40#define ULANG_PREPROCESSOR_JOIN(x, y) ULANG_PREPROCESSOR_JOIN_INNER(x, y)
41#define ULANG_PREPROCESSOR_JOIN_INNER(x, y) x##y
42
43// Update SNDBS.cs if this macro changes
44#if ULANG_PLATFORM_EXTENSION
45#define ULANG_PLATFORM_HEADER_NAME(Suffix) ULANG_STRINGIFY(ULANG_PREPROCESSOR_JOIN(ULANG_PLATFORM, Suffix))
46#else
47#define ULANG_PLATFORM_HEADER_NAME(Suffix) ULANG_STRINGIFY(ULANG_PREPROCESSOR_JOIN(ULANG_PLATFORM/ULANG_PLATFORM, Suffix))
48#endif
49
50// Update SNDBS.cs if this macro changes
51#if ULANG_PLATFORM_EXTENSION
52#define ULANG_PLATFORM_HEADER_NAME_WITH_PREFIX(Prefix, Suffix) ULANG_STRINGIFY(Prefix/ULANG_PREPROCESSOR_JOIN(ULANG_PLATFORM, Suffix))
53#else
54#define ULANG_PLATFORM_HEADER_NAME_WITH_PREFIX(Prefix, Suffix) ULANG_STRINGIFY(Prefix/ULANG_PLATFORM/ULANG_PREPROCESSOR_JOIN(ULANG_PLATFORM, Suffix))
55#endif
56
57//------------------------------------------------------------------
58// Include platform-specific header
59#include ULANG_PLATFORM_HEADER_NAME_WITH_PREFIX(uLang/Common/Platform,Common.h)
60
61//------------------------------------------------------------------
63#define ULANG_API_VERSION 2
64
65//------------------------------------------------------------------
66// DLL API
67
68#ifndef DLLIMPORT
69 #define DLLIMPORT ULANG_DLLIMPORT
70 #define DLLEXPORT ULANG_DLLEXPORT
71#endif
72
73#ifndef DLLIMPORT_VTABLE
74 #define DLLIMPORT_VTABLE ULANG_DLLIMPORT_VTABLE
75 #define DLLEXPORT_VTABLE ULANG_DLLEXPORT_VTABLE
76#endif
77
78//------------------------------------------------------------------
79// Warnings
80
81#if defined(__GNUC__) || defined(__clang__) // Check __clang__ first, since Clang on Windows also defines _MSC_VER
82 #define ULANG_THIRD_PARTY_INCLUDES_START \
83 _Pragma("GCC diagnostic push") \
84 _Pragma("GCC diagnostic ignored \"-Wundef\"") \
85 _Pragma("GCC diagnostic ignored \"-Wswitch-default\"") \
86 _Pragma("GCC diagnostic ignored \"-Wswitch-enum\"")
87 _Pragma("GCC diagnostic ignored \"-Wenum-compare\"")
88 #define ULANG_THIRD_PARTY_INCLUDES_END \
89 _Pragma("GCC diagnostic pop")
90
91 _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
92
93#elif defined(_MSC_VER)
94 #pragma warning(disable: 4100) // 'identifier' : unreferenced formal parameter https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4100
95 #pragma warning(disable: 4127) // Conditional expression is constant https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4127
96 #pragma warning(disable: 4251) // 'type' needs to have dll-interface to be used by clients of 'type' https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4251
97 #pragma warning(disable: 4275) // non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275
98 #pragma warning(disable: 6255) // _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead.
99 #pragma warning(disable: 6326) // Potential comparison of a constant with another constant.
100
101 // Disable warnings that would otherwise occur in third party includes such as LLVM
102 #define ULANG_THIRD_PARTY_INCLUDES_START \
103 __pragma(warning(push)) \
104 __pragma(warning(disable: 4141 4189 4244 4245 4267 4324 4458 4624 4668 6313 4389 5054))
105 #define ULANG_THIRD_PARTY_INCLUDES_END \
106 __pragma(warning(pop))
107#else
108 #define ULANG_THIRD_PARTY_INCLUDES_START
109 #define ULANG_THIRD_PARTY_INCLUDES_END
110#endif
111
112#if defined(__clang__)
113 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_START \
114 _Pragma("GCC diagnostic push") \
115 _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \
116 _Pragma("GCC diagnostic ignored \"-Wdynamic-class-memaccess\"")
117 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_END \
118 _Pragma("GCC diagnostic pop")
119#elif defined(__GNUC__)
120 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_START \
121 _Pragma("GCC diagnostic push") \
122 _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \
123 _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") \
124 _Pragma("GCC diagnostic ignored \"-Wclass-memaccess\"")
125 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_END \
126 _Pragma("GCC diagnostic pop")
127#else
128 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_START
129 #define ULANG_IGNORE_CLASS_MEMACCESS_WARNING_END
130#endif
131
132#ifndef ULANG_SILENCE_SECURITY_WARNING_START
133#define ULANG_SILENCE_SECURITY_WARNING_START
134#endif
135#ifndef ULANG_SILENCE_SECURITY_WARNING_END
136#define ULANG_SILENCE_SECURITY_WARNING_END
137#endif
138
139//------------------------------------------------------------------
140// Dynamic symbol visibility
141
142#if defined(_MSC_VER)
143 #define ULANG_DLLIMPORT __declspec(dllimport)
144 #define ULANG_DLLEXPORT __declspec(dllexport)
145 #define ULANG_DLLIMPORT_VTABLE
146 #define ULANG_DLLEXPORT_VTABLE
147#elif defined(__clang__)
148 #if ULANG_PLATFORM_POSIX
149 #define ULANG_DLLIMPORT __attribute__((visibility("default")))
150 #define ULANG_DLLEXPORT __attribute__((visibility("default")))
151 #else
152 #define ULANG_DLLIMPORT __declspec(dllimport)
153 #define ULANG_DLLEXPORT __declspec(dllexport)
154 #endif
155 #define ULANG_DLLIMPORT_VTABLE __attribute__((__type_visibility__("default")))
156 #define ULANG_DLLEXPORT_VTABLE __attribute__((__type_visibility__("default")))
157#elif defined(__GNUC__)
158 #define ULANG_DLLIMPORT __attribute__((visibility("default")))
159 #define ULANG_DLLEXPORT __attribute__((visibility("default")))
160 #define ULANG_DLLIMPORT_VTABLE __attribute__((visibility("default")))
161 #define ULANG_DLLEXPORT_VTABLE __attribute__((visibility("default")))
162#else
163 #define ULANG_DLLIMPORT
164 #define ULANG_DLLEXPORT
165 #define ULANG_DLLIMPORT_VTABLE
166 #define ULANG_DLLEXPORT_VTABLE
167#endif
168
169//------------------------------------------------------------------
170// Alignment
171
172#if defined(__clang__) || defined(__GNUC__)
173 #define ULANG_GCC_PACK(n) __attribute__((packed,aligned(n)))
174 #define ULANG_GCC_ALIGN(n) __attribute__((aligned(n)))
175#else
176 #define ULANG_GCC_PACK(n)
177 #define ULANG_GCC_ALIGN(n)
178#endif
179#if defined(_MSC_VER)
180 #define ULANG_MS_ALIGN(n) __declspec(align(n))
181#else
182 #define ULANG_MS_ALIGN(n)
183#endif
184
185//------------------------------------------------------------------
186// Inlining
187
188#define ULANG_FORCEINLINE inline
189#define ULANG_FORCENOINLINE
190
191#if 0
192#if defined(_MSC_VER)
193 #define ULANG_FORCEINLINE __forceinline
194 #define ULANG_FORCENOINLINE __declspec(noinline)
195#elif defined(__clang__) || defined(__GNUC__)
196 #define ULANG_FORCEINLINE inline __attribute__ ((always_inline))
197 #define ULANG_FORCENOINLINE __attribute__((noinline))
198#else
199 #define ULANG_FORCEINLINE inline
200 #define ULANG_FORCENOINLINE
201#endif
202#endif
203
204//------------------------------------------------------------------
205// Restrict
206
207#define ULANG_RESTRICT __restrict
208
209//------------------------------------------------------------------
210// Likely
211
212#if defined(__clang__) || defined(__GNUC__)
213 #define ULANG_LIKELY(x) __builtin_expect(!!(x), 1)
214 #define ULANG_UNLIKELY(x) __builtin_expect(!!(x), 0)
215#else
216 #define ULANG_LIKELY(x) (x)
217 #define ULANG_UNLIKELY(x) (x)
218#endif
219
220//------------------------------------------------------------------
221// Array count
222
223#if defined(_MSC_VER) && (_MSC_VER >= 1400)
224 #define ULANG_COUNTOF(x) _countof(x)
225#else
226 #define ULANG_COUNTOF(x) (sizeof(x)/sizeof(x[0]))
227#endif
228
229//------------------------------------------------------------------
230// Switch case fall-through warning suppression.
231
232#if __cplusplus >= 201703L
233 #define ULANG_FALLTHROUGH [[fallthrough]]
234#elif defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__)
235 #define ULANG_FALLTHROUGH __attribute__((fallthrough))
236#else
237 #define ULANG_FALLTHROUGH
238#endif
239
240//------------------------------------------------------------------
241// Mark a code path that is unreachable.
242
243#define ULANG_UNREACHABLE() while(true) { ULANG_BREAK(); }
244
245//------------------------------------------------------------------
246// Static analysis
247
248#if defined( __clang_analyzer__ )
249 // A fake function marked with noreturn that acts as a marker for CA_ASSUME to ensure the
250 // static analyzer doesn't take an analysis path that is assumed not to be navigable.
252
253 #define ULANG_CA_ASSUME(Expr) (__builtin_expect(!bool(Expr), 0) ? ULANG_CA_AssumeNoReturn() : (void)0)
254#elif defined( _PREFAST_ ) || defined( PVS_STUDIO )
255 #define ULANG_CA_ASSUME(Expr) __analysis_assume( !!( Expr ) )
256#else
257 #define ULANG_CA_ASSUME(Expr) ((void)Expr)
258#endif
259
260//------------------------------------------------------------------
261// Asserts
262
263// ULANG_ERRORF, ULANG_ASSERTF: Check for FATAL error conditions - conditional expression is KEPT in release builds.
264// ULANG_VERIFYF: Check for RECOVERABLE error conditions - conditional expression is KEPT in release builds.
265// ULANG_ENSUREF: Check for RECOVERABLE error conditions - conditional expression is KEPT in release builds.
266
267#if ULANG_DO_CHECK
268 #define ULANG_ASSERT(expr) { if (ULANG_UNLIKELY((bool)!(expr))) { if ((*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Fatal, #expr, __FILE__, __LINE__, "") == ::uLang::EErrorAction::Break) { ULANG_BREAK(); } ULANG_CA_ASSUME(false); } }
269 #define ULANG_VERIFY(expr) { if (ULANG_UNLIKELY((bool)!(expr)) && (*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Recoverable, #expr, __FILE__, __LINE__, "") == ::uLang::EErrorAction::Break) ULANG_BREAK(); }
270 #define ULANG_ENSURE(expr) ( ULANG_LIKELY(!!(expr)) || (\
271 ( ((*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Recoverable, #expr, __FILE__, __LINE__, "") == ::uLang::EErrorAction::Break) && \
272 ([] ()->bool { ULANG_BREAK(); return false; } ()) \
273 ) \
274 ) )
275
276 #define ULANG_ERRORF(format, ...) { if ((*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Fatal, "", __FILE__, __LINE__, format, ##__VA_ARGS__) == ::uLang::EErrorAction::Break) ULANG_BREAK(); }
277 #define ULANG_ASSERTF(expr, format, ...) { if (ULANG_UNLIKELY((bool)!(expr))) { if ((*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Fatal, #expr, __FILE__, __LINE__, format, ##__VA_ARGS__) == ::uLang::EErrorAction::Break) { ULANG_BREAK(); } ULANG_CA_ASSUME(false); } }
278 #define ULANG_VERIFYF(expr, format, ...) { if (ULANG_UNLIKELY((bool)!(expr)) && (*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Recoverable, #expr, __FILE__, __LINE__, format, ##__VA_ARGS__) == ::uLang::EErrorAction::Break) ULANG_BREAK(); }
279 #define ULANG_ENSUREF(expr, format, ...) ( ULANG_LIKELY(!!(expr)) || (\
280 ( ((*::uLang::GetSystemParams()._AssertFailed)(::uLang::EAssertSeverity::Recoverable, #expr, __FILE__, __LINE__, format, ##__VA_ARGS__) == ::uLang::EErrorAction::Break) && \
281 ([] ()->bool { ULANG_BREAK(); return false; } ()) \
282 ) \
283 ) )
284#else
285 #define ULANG_ASSERT(expr) (void(sizeof(!!(expr))))
286 #define ULANG_VERIFY(expr) (void(sizeof(!!(expr))))
287 #define ULANG_ENSURE(expr) (!!(expr))
288
289 #define ULANG_ERRORF(format, ...) (void(0))
290 #define ULANG_ASSERTF(expr, format, ...) (void(sizeof(!!(expr))))
291 #define ULANG_VERIFYF(expr, format, ...) (void(sizeof(!!(expr))))
292 #define ULANG_ENSUREF(expr, format, ...) (!!(expr))
293#endif
294
295//------------------------------------------------------------------
296// Logging
297
298#define VERSE_SUPPRESS_UNUSED(_Variable) (void)(_Variable);
299
300// Ensure either just enumerator (Error), fully qualified (ELogVerbosity::Error) or variable (MyVerbosity) work equally well.
301#define USING_ELogVerbosity \
302 constexpr uLang::ELogVerbosity Error = uLang::ELogVerbosity::Error; VERSE_SUPPRESS_UNUSED(Error) \
303 constexpr uLang::ELogVerbosity Warning = uLang::ELogVerbosity::Warning; VERSE_SUPPRESS_UNUSED(Warning) \
304 constexpr uLang::ELogVerbosity Display = uLang::ELogVerbosity::Display; VERSE_SUPPRESS_UNUSED(Display) \
305 constexpr uLang::ELogVerbosity Log = uLang::ELogVerbosity::Log; VERSE_SUPPRESS_UNUSED(Log) \
306 constexpr uLang::ELogVerbosity Verbose = uLang::ELogVerbosity::Verbose; VERSE_SUPPRESS_UNUSED(Verbose) \
307
308#define ULANG_LOGF(verbosity, format, ...) \
309 { USING_ELogVerbosity \
310 (*::uLang::GetSystemParams()._LogMessage)(verbosity, format, ##__VA_ARGS__); \
311 }
312
313//------------------------------------------------------------------
314// Memory
315
316#if !defined(ULANG_AGGRESSIVE_MEMORY_SAVING)
317 #define ULANG_AGGRESSIVE_MEMORY_SAVING 0
318#endif
319
320
321namespace uLang
322{
323
324// Type of nullptr
325using NullPtrType = std::nullptr_t;
326
327// Language default sized storage types
328
330using Float = double;
331using Boolean = bool;
332
334
337{
338 Continue = 0, // Continue to exhaustively iterate through all items
339 SkipChildren = 1, // Skip iterating through any children/sub-items and continue though other items in hierarchy
340 Stop = 2 // Stop iterating through items and early exit
341};
342
345{
346 Stopped = 0, // Iteration was terminated early by the visitor functor and wants the caller to exit early
347 Completed = 1, // Iteration is done iterating and wants the caller to continue iterating if there are more elements to iterate over
348};
349
351enum class EResult : int8_t
352{
353 Unspecified = -1,
354 OK = 0,
355 Error,
356};
357
360{
361 Continue = 0,
362 Break,
363};
364
365// Comparison result value
366enum class EEquate : int8_t
367{
368 Less = -1,
369 Equal = 0,
370 Greater = 1
371};
372
373
376
379
381enum EIndex { IndexNone = -1 };
382
383//------------------------------------------------------------------
384// System Initialization
385
387{
388 Fatal = 0,
390};
391
393{
394 Error, // Prints an error to console (and log file)
395 Warning, // Prints a warning to console (and log file)
396 Display, // Prints a message to console (and log file)
397 Verbose, // Prints a verbose message to console (and log file)
398 Log, // Prints a message to a log file (does not print to console)
399};
400
403{
404 using FMalloc = void * (*)(size_t);
405 using FRealloc = void * (*)(void *, size_t);
406 using FFree = void (*)(void *);
407
408 using FAssert = EErrorAction(*)(EAssertSeverity /* Severity */, const char * /* Expr */, const char * /* File */, int32_t /* Line */, const char * /* Format */, ...);
409 using FLog = void(*)(ELogVerbosity /* Verbosity */, const char* /* Format */, ...);
410
412
416
419
421
426};
427ULANGCORE_API bool operator==(const SSystemParams& Lhs, const SSystemParams& Rhs);
428
430ULANGCORE_API SSystemParams& GetSystemParams();
431
432//------------------------------------------------------------------
433// Memory management
434
436class CAllocatorInstance;
438
446
451
458
463
464}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
float swift_float2 __attribute__((__ext_vector_type__(2)))
Definition MarketplaceKitWrapper.h:67
const bool
Definition NetworkReplayStreaming.h:178
Definition MemoryBase.h:99
Definition Allocator.h:35
Definition GenericPlatformFile.h:25
Definition VVMEngineEnvironment.h:23
std::nullptr_t NullPtrType
Definition Common.h:325
bool Boolean
Default size for uLang Float Type.
Definition Common.h:331
EDefaultInit
Enum used to force default initialization.
Definition Common.h:378
@ DefaultInit
Definition Common.h:378
EResult
Generic error codes.
Definition Common.h:352
@ Unspecified
Not sure if success or failure.
@ Error
Some error occurred.
@ OK
Success.
SSystemParams & GetSystemParams()
Global variable for efficient access.
Definition Common.cpp:9
bool IsInitialized()
Definition Common.cpp:39
const CAllocatorInstance GSystemAllocatorInstance([](const CAllocatorInstance *, size_t NumBytes) -> void *{ return GetSystemParams()._HeapMalloc(NumBytes);}, [](const CAllocatorInstance *, void *Memory, size_t NumBytes) -> void *{ return GetSystemParams()._HeapRealloc(Memory, NumBytes);}, [](const CAllocatorInstance *, void *Memory) { GetSystemParams()._HeapFree(Memory);})
Definition Common.h:437
EIterateResult
Iteration result returned from an iteration.
Definition Common.h:345
bool operator==(const SSystemParams &Lhs, const SSystemParams &Rhs)
Definition Common.cpp:21
EAssertSeverity
Definition Common.h:387
EIndex
Used to signify an unspecified index.
Definition Common.h:381
@ IndexNone
Definition Common.h:381
ENoInit
Enum used in constructors to indicate they should not initialize anything.
Definition Common.h:375
@ NoInit
Definition Common.h:375
ELogVerbosity
Definition Common.h:393
int64_t Integer
Definition Common.h:329
const uint32_t uint32_invalid
Default size for uLang Boolean Type.
Definition Common.h:333
EErrorAction
Generic action after error has occurred.
Definition Common.h:360
EEquate
Definition Common.h:367
EVisitResult
Result returned from a visitor functor indicating how to continue or to quit early.
Definition Common.h:337
EResult DeInitialize()
Definition Common.cpp:44
void SetGlobalVerbosity(const uLang::ELogVerbosity GlobalVerbosity)
Definition Common.cpp:49
double Float
Default size for uLang Integer Type.
Definition Common.h:330
Parameters to initialize the uLang module.
Definition Common.h:403
ELogVerbosity _Verbosity
Won't print anything under the _Verbosity level.
Definition Common.h:420
void(*)(void *) FFree
Definition Common.h:406
FRealloc _HeapRealloc
Reallocate system heap memory.
Definition Common.h:414
SSystemParams(int APIVersion, FMalloc HeapMalloc, FRealloc HeapRealloc, FFree HeapFree, FAssert AssertFailed, FLog LogMessage=nullptr)
Definition Common.h:422
int _APIVersion
Set this to ULANG_API_VERSION.
Definition Common.h:411
EErrorAction(*)(EAssertSeverity, const char *, const char *, int32_t, const char *,...) FAssert
Definition Common.h:408
void(*)(ELogVerbosity, const char *,...) FLog
Definition Common.h:409
FFree _HeapFree
Free system heap memory.
Definition Common.h:415
void *(*)(void *, size_t) FRealloc
Definition Common.h:405
FLog _LogMessage
Print a message.
Definition Common.h:418
FAssert _AssertFailed
Called when an assert fails.
Definition Common.h:417
FMalloc _HeapMalloc
Allocate system heap memory.
Definition Common.h:413