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"
57#ifdef INK_ENABLE_UNREAL
58# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
59# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
61# define inkAssert(...) ink::ink_assert(__VA_ARGS__)
62# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
80typedef unsigned long long uint64_t;
81typedef unsigned short uint16_t;
95typedef decltype(
static_cast<int*
>(
nullptr) -
static_cast<int*
>(
nullptr))
ptrdiff_t;
98static_assert(
sizeof(
byte_t) == 1);
99static_assert(
sizeof(uint16_t) == 2);
100static_assert(
sizeof(int16_t) == 2);
101static_assert(
sizeof(
uint32_t) == 4);
102static_assert(
sizeof(int32_t) == 4);
103static_assert(
sizeof(uint64_t) == 8);
104static_assert(
sizeof(
ptrdiff_t) ==
sizeof(
void*));
110typedef const unsigned char*
ip_t;
126 bool operator==(
const list_flag& o)
const {
return list_id == o.list_id && flag == o.flag; }
128 bool operator!=(
const list_flag& o)
const {
return ! (*
this == o); }
136#ifdef INK_ENABLE_UNREAL
140 return CityHash32(
string, FCStringAnsi::Strlen(
string));
146 return CityHash32(
reinterpret_cast<const char*
>(data), len);
157# pragma warning(push)
159# pragma warning(disable : 4514)
162 static inline constexpr bool starts_with(
const char*
string,
const char* prefix)
165 if (*
string != *prefix) {
175 static inline constexpr bool is_whitespace(
const char*
string,
bool includeNewline =
true)
179 switch (*(
string++)) {
181 case '\f': [[fallthrough]];
182 case '\r': [[fallthrough]];
184 if (! includeNewline)
187 case '\t': [[fallthrough]];
188 case '\v': [[fallthrough]];
190 default:
return false;
195 inline bool is_part_of_word(
char character) {
return isalpha(character) || isdigit(character); }
197 static inline constexpr bool is_whitespace(
char character,
bool includeNewline =
true)
201 if (! includeNewline)
203 case '\t': [[fallthrough]];
204 case ' ':
return true;
205 default:
return false;
209#ifndef INK_ENABLE_UNREAL
211 void zero_memory(
void* buffer,
size_t length);
232 inline const char* message()
const {
return _msg; }
240# pragma GCC diagnostic push
241# pragma GCC diagnostic ignored "-Wunused-parameter"
243# pragma warning(push)
245# pragma warning(disable : 4100)
249template<
typename... Args>
250void ink_assert(
bool condition,
const char* msg =
nullptr, Args... args)
252 static const char* EMPTY =
"";
253 if (msg ==
nullptr) {
257#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_CSTD)
258 if constexpr (
sizeof...(args) > 0) {
259 size_t size = snprintf(
nullptr, 0, msg, args...) + 1;
260 char* message =
static_cast<char*
>(malloc(size));
261 snprintf(message, size, msg, args...);
265#ifdef INK_ENABLE_EXCEPTIONS
267#elif defined(INK_ENABLE_CSTD)
268 fprintf(stderr,
"Ink Assert: %s\n", msg);
270#elif defined(INK_ENABLE_UNREAL)
273# warning no assertion handling this could lead to invalid code paths
278# pragma GCC diagnostic pop
285template<
typename... Args>
286[[noreturn]]
inline void ink_assert(
const char* msg =
nullptr, Args... args)
289#ifdef INK_ENABLE_CSTD
294namespace runtime::internal
296 constexpr unsigned abs(
int i) {
return static_cast<unsigned>(i < 0 ? -i : i); }
299 struct always_false {
300 static constexpr bool value =
false;
303 template<
bool Con,
typename T1,
typename T2>
308 template<
typename T1,
typename T2>
309 struct if_type<false, T1, T2> {
313 template<
bool Con,
typename T1,
typename T2>
314 using if_t =
typename if_type<Con, T1, T2>::type;
316 template<
bool Enable,
typename T =
void>
321 struct enable_if<true, T> {
325 template<
bool Enable,
typename T =
void>
326 using enable_if_t =
typename enable_if<Enable, T>::type;
337constexpr std::nullopt_t
nullopt = std::nullopt;
364 const T& operator*()
const {
return value(); }
366 T& operator*() {
return value(); }
368 const T* operator->()
const {
return &value(); }
370 T* operator->() {
return &value(); }
372 constexpr bool has_value()
const {
return _has_value; }
380 constexpr const T& value()
const
386 constexpr operator bool()
const {
return has_value(); }
389 constexpr T value_or(U&& u)
const
391 return _has_value ? _value :
static_cast<T
>(u);
394 template<
typename... Args>
395 T& emplace(Args... args)
400 new (&_value) T(args...);
406 void test_value()
const
409 inkFail(
"Can't access empty optional!");
413 bool _has_value =
false;
#define inkFail(text,...)
Compile argument agnostic assert macro (always asserts).
Definition system.h:59
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:132
unsigned int uint32_t
define basic numeric type
Definition system.h:71
std::optional< T > optional
custom optional implementation for usage if STL is disabled
Definition system.h:335
const hash_t InvalidHash
Invalid hash value.
Definition system.h:88
uint32_t container_t
Used as the unique identifier for an ink container.
Definition system.h:116
void ink_assert(bool condition, const char *msg=nullptr, Args... args)
Assert helper, not to be used directly, please use inkAssert and inkFail to be enviroment agnostic.
Definition system.h:250
unsigned char byte_t
Byte type.
Definition system.h:92
unsigned int size_t
Used for the size of arrays.
Definition system.h:113
uint32_t offset_t
Verify sizes.
Definition system.h:107
hash_t hash_data(const unsigned char *data, size_t len)
Simple hash for detcting changes in binary data.
Definition system.h:144
constexpr std::nullopt_t nullopt
an empty optional
Definition system.h:337
std::runtime_error ink_exception
exception type thrown if something goes wrong
Definition system.h:221
uint32_t thread_t
Used to uniquely identify threads.
Definition system.h:119
decltype(static_cast< int * >(nullptr) - static_cast< int * >(nullptr)) ptrdiff_t
Ptr difference type.
Definition system.h:95
constexpr list_flag empty_flag
value representing an empty list
Definition system.h:134
hash_t hash_string(const char *string)
Simple hash for serialization of strings.
Definition system.h:138
const unsigned char * ip_t
Instruction pointer used for addressing within the story instructions.
Definition system.h:110
uint32_t hash_t
Name hash (used for temporary variables).
Definition system.h:85