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
35#ifdef INK_ENABLE_UNREAL
36# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len)
37# define FORMAT_STRING_STR "%hs"
39# define inkZeroMemory ink::internal::zero_memory
40# define FORMAT_STRING_STR "%s"
43#ifdef INK_ENABLE_UNREAL
44# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
45# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
47# define inkAssert ink::ink_assert
48# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
67typedef unsigned long long uint64_t;
68typedef unsigned short uint16_t;
82typedef decltype(
static_cast<int*
>(
nullptr) -
static_cast<int*
>(
nullptr))
ptrdiff_t;
85static_assert(
sizeof(
byte_t) == 1);
86static_assert(
sizeof(uint16_t) == 2);
87static_assert(
sizeof(int16_t) == 2);
89static_assert(
sizeof(int32_t) == 4);
90static_assert(
sizeof(uint64_t) == 8);
91static_assert(
sizeof(
ptrdiff_t) ==
sizeof(
void*));
97typedef const unsigned char*
ip_t;
113 bool operator==(
const list_flag& o)
const {
return list_id == o.list_id && flag == o.flag; }
115 bool operator!=(
const list_flag& o)
const {
return ! (*
this == o); }
123#ifdef INK_ENABLE_UNREAL
127 return CityHash32(
string, FCStringAnsi::Strlen(
string));
131hash_t hash_data(
const unsigned char* data,
size_t len);
138# pragma warning(push)
141 justification : "functions are defined in header file, they do not need to be used." \
145 static inline constexpr bool starts_with(
const char*
string,
const char* prefix)
148 if (*
string != *prefix) {
158 static inline constexpr bool is_whitespace(
const char*
string,
bool includeNewline =
true)
162 switch (*(
string++)) {
164 case '\f': [[fallthrough]];
165 case '\r': [[fallthrough]];
167 if (! includeNewline)
170 case '\t': [[fallthrough]];
171 case '\v': [[fallthrough]];
173 default:
return false;
178 inline bool is_part_of_word(
char character) {
return isalpha(character) || isdigit(character); }
180 static inline constexpr bool is_whitespace(
char character,
bool includeNewline =
true)
184 if (! includeNewline)
186 case '\t': [[fallthrough]];
187 case ' ':
return true;
188 default:
return false;
192#ifndef INK_ENABLE_UNREAL
194 void zero_memory(
void* buffer,
size_t length);
215 inline const char* message()
const {
return _msg; }
223# pragma GCC diagnostic push
224# pragma GCC diagnostic ignored "-Wunused-parameter"
226# pragma warning(push)
229 justification : "dependend on rtti, exception and stl support not all arguments are needed" \
233template<
typename... Args>
234void ink_assert(
bool condition,
const char* msg =
nullptr, Args... args)
236 static const char* EMPTY =
"";
237 if (msg ==
nullptr) {
241#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_CSTD)
242 if constexpr (
sizeof...(args) > 0) {
243 size_t size = snprintf(
nullptr, 0, msg, args...) + 1;
244 char* message =
static_cast<char*
>(malloc(size));
245 snprintf(message, size, msg, args...);
249#ifdef INK_ENABLE_EXCEPTIONS
251#elif defined(INK_ENABLE_CSTD)
252 fprintf(stderr,
"Ink Assert: %s\n", msg);
255# warning no assertion handling this could lead to invalid code paths
260# pragma GCC diagnostic pop
265template<
typename... Args>
266[[noreturn]]
inline void ink_assert(
const char* msg =
nullptr, Args... args)
268 ink_assert(
false, msg, args...);
269#ifdef INK_ENABLE_CSTD
274namespace runtime::internal
276 constexpr unsigned abs(
int i) {
return static_cast<unsigned>(i < 0 ? -i : i); }
279 struct always_false {
280 static constexpr bool value =
false;
283 template<
bool Con,
typename T1,
typename T2>
288 template<
typename T1,
typename T2>
289 struct if_type<false, T1, T2> {
293 template<
bool Con,
typename T1,
typename T2>
294 using if_t =
typename if_type<Con, T1, T2>::type;
296 template<
bool Enable,
typename T =
void>
301 struct enable_if<true, T> {
305 template<
bool Enable,
typename T =
void>
306 using enable_if_t =
typename enable_if<Enable, T>::type;
317constexpr std::nullopt_t
nullopt = std::nullopt;
344 const T& operator*()
const {
return value(); }
346 T& operator*() {
return value(); }
348 const T* operator->()
const {
return &value(); }
350 T* operator->() {
return &value(); }
352 constexpr bool has_value()
const {
return _has_value; }
360 constexpr const T& value()
const
366 constexpr operator bool()
const {
return has_value(); }
369 constexpr T value_or(U&& u)
const
371 return _has_value ? _value :
static_cast<T
>(u);
374 template<
typename... Args>
375 T& emplace(Args... args)
380 new (&_value) T(args...);
386 void test_value()
const
389 inkFail(
"Can't access empty optional!");
393 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:119
unsigned int uint32_t
define basic numeric type
Definition system.h:58
std::optional< T > optional
custom optional implementation for usage if STL is disabled
Definition system.h:315
const hash_t InvalidHash
Invalid hash value.
Definition system.h:75
uint32_t container_t
Used as the unique identifier for an ink container.
Definition system.h:103
unsigned char byte_t
Byte type.
Definition system.h:79
unsigned int size_t
Used for the size of arrays.
Definition system.h:100
uint32_t offset_t
Verify sizes.
Definition system.h:94
constexpr std::nullopt_t nullopt
an empty optional
Definition system.h:317
std::runtime_error ink_exception
exception type thrown if something goes wrong
Definition system.h:204
uint32_t thread_t
Used to uniquely identify threads.
Definition system.h:106
decltype(static_cast< int * >(nullptr) - static_cast< int * >(nullptr)) ptrdiff_t
Ptr difference type.
Definition system.h:82
constexpr list_flag empty_flag
value representing an empty list
Definition system.h:121
hash_t hash_string(const char *string)
Simple hash for serialization of strings.
Definition system.h:125
const unsigned char * ip_t
Instruction pointer used for addressing within the story instructions.
Definition system.h:97
uint32_t hash_t
Name hash (used for temporary variables)
Definition system.h:72