11#ifdef INK_ENABLE_UNREAL
12# include "Misc/AssertionMacros.h"
13# include "Misc/CString.h"
14# include "HAL/UnrealMemory.h"
15# include "Hash/CityHash.h"
18# ifdef INK_ENABLE_EXCEPTIONS
34#ifdef INK_ENABLE_UNREAL
35# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len)
36# define FORMAT_STRING_STR "%hs"
38# define inkZeroMemory ink::internal::zero_memory
39# define FORMAT_STRING_STR "%s"
42#ifdef INK_ENABLE_UNREAL
43# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
44# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
46# define inkAssert ink::ink_assert
47# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
64typedef unsigned long long uint64_t;
65typedef unsigned short uint16_t;
74#ifdef INK_ENABLE_UNREAL
78 return CityHash32(
string, FCStringAnsi::Strlen(
string));
88typedef decltype(
static_cast<int*
>(
nullptr) -
static_cast<int*
>(
nullptr))
ptrdiff_t;
91static_assert(
sizeof(
byte_t) == 1);
92static_assert(
sizeof(uint16_t) == 2);
93static_assert(
sizeof(int16_t) == 2);
95static_assert(
sizeof(int32_t) == 4);
96static_assert(
sizeof(uint64_t) == 8);
97static_assert(
sizeof(
ptrdiff_t) ==
sizeof(
void*));
103typedef const unsigned char*
ip_t;
119 bool operator==(
const list_flag& o)
const {
return list_id == o.list_id && flag == o.flag; }
121 bool operator!=(
const list_flag& o)
const {
return ! (*
this == o); }
133# pragma warning(push)
136 justification : "functions are defined in header file, they do not need to be used." \
140 static inline constexpr bool starts_with(
const char*
string,
const char* prefix)
143 if (*
string != *prefix) {
153 static inline constexpr bool is_whitespace(
const char*
string,
bool includeNewline =
true)
157 switch (*(
string++)) {
160 if (! includeNewline)
163 case '\t': [[fallthrough]];
165 default:
return false;
173 static inline bool is_part_of_word(
char character)
175 return isalpha(character) || isdigit(character);
178 static inline constexpr bool is_whitespace(
char character,
bool includeNewline =
true)
182 if (! includeNewline)
184 case '\t': [[fallthrough]];
185 case ' ':
return true;
186 default:
return false;
190#ifndef INK_ENABLE_UNREAL
192 void zero_memory(
void* buffer,
size_t length);
200#ifdef INK_ENABLE_EXCEPTIONS
213 inline const char* message()
const {
return _msg; }
221#ifndef INK_ENABLE_UNREAL
222template<
typename... Args>
223void ink_assert(
bool condition,
const char* msg =
nullptr, Args... args)
225 static const char* EMPTY =
"";
226 if (msg ==
nullptr) {
230 if constexpr (
sizeof...(args) > 0) {
231 size_t size = snprintf(
nullptr, 0, msg, args...) + 1;
232 char* message =
static_cast<char*
>(malloc(size));
233 snprintf(message, size, msg, args...);
237# ifdef INK_ENABLE_EXCEPTIONS
239# elif defined(INK_ENABLE_CSTD)
240 fprintf(stderr,
"Ink Assert: %s\n", msg);
243# error "This path needs a way to warn and then terminate, otherwise it'll silently fail"
248template<
typename... Args>
249[[noreturn]]
inline void ink_assert(
const char* msg =
nullptr, Args... args)
251 ink_assert(
false, msg, args...);
256namespace runtime::internal
258 constexpr unsigned abs(
int i) {
return static_cast<unsigned>(i < 0 ? -i : i); }
261 struct always_false {
262 static constexpr bool value =
false;
265 template<
bool Con,
typename T1,
typename T2>
270 template<
typename T1,
typename T2>
271 struct if_type<false, T1, T2> {
275 template<
bool Con,
typename T1,
typename T2>
276 using if_t =
typename if_type<Con, T1, T2>::type;
278 template<
bool Enable,
typename T =
void>
283 struct enable_if<true, T> {
287 template<
bool Enable,
typename T =
void>
288 using enable_if_t =
typename enable_if<Enable, T>::type;
299constexpr std::nullopt_t
nullopt = std::nullopt;
326 const T& operator*()
const {
return value(); }
328 T& operator*() {
return value(); }
330 const T* operator->()
const {
return &value(); }
332 T* operator->() {
return &value(); }
334 constexpr bool has_value()
const {
return _has_value; }
342 constexpr const T& value()
const
348 constexpr operator bool()
const {
return has_value(); }
351 constexpr T value_or(U&& u)
const
353 return _has_value ? _value :
static_cast<T
>(u);
356 template<
typename... Args>
357 T& emplace(Args... args)
362 new (&_value) T(args...);
368 void test_value()
const
371 inkFail(
"Can't access empty optional!");
375 bool _has_value =
false;
Namespace contaning all modules and classes from InkCPP.
Definition choice.h:11
constexpr list_flag null_flag
value of an unset list_flag
Definition system.h:125
unsigned int uint32_t
define basic numeric type
Definition system.h:55
std::optional< T > optional
custom optional implementation for usage if STL is disabled
Definition system.h:297
const hash_t InvalidHash
Invalid hash value.
Definition system.h:72
uint32_t container_t
Used as the unique identifier for an ink container.
Definition system.h:109
unsigned char byte_t
Byte type.
Definition system.h:85
unsigned int size_t
Used for the size of arrays.
Definition system.h:106
uint32_t offset_t
Verify sizes.
Definition system.h:100
constexpr std::nullopt_t nullopt
an empty optional
Definition system.h:299
std::runtime_error ink_exception
exception type thrown if something goes wrong
Definition system.h:202
uint32_t thread_t
Used to uniquely identify threads.
Definition system.h:112
decltype(static_cast< int * >(nullptr) - static_cast< int * >(nullptr)) ptrdiff_t
Ptr difference type.
Definition system.h:88
constexpr list_flag empty_flag
value representing an empty list
Definition system.h:127
hash_t hash_string(const char *string)
Simple hash for serialization of strings.
Definition system.h:76
const unsigned char * ip_t
Instruction pointer used for addressing within the story instructions.
Definition system.h:103
uint32_t hash_t
Name hash (used for temporary variables)
Definition system.h:69