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;
77#ifdef INK_ENABLE_UNREAL
81 return CityHash32(
string, FCStringAnsi::Strlen(
string));
91typedef decltype(
static_cast<int*
>(
nullptr) -
static_cast<int*
>(
nullptr))
ptrdiff_t;
94static_assert(
sizeof(
byte_t) == 1);
95static_assert(
sizeof(uint16_t) == 2);
96static_assert(
sizeof(int16_t) == 2);
98static_assert(
sizeof(int32_t) == 4);
99static_assert(
sizeof(uint64_t) == 8);
100static_assert(
sizeof(
ptrdiff_t) ==
sizeof(
void*));
106typedef const unsigned char*
ip_t;
122 bool operator==(
const list_flag& o)
const {
return list_id == o.list_id && flag == o.flag; }
124 bool operator!=(
const list_flag& o)
const {
return ! (*
this == o); }
136# pragma warning(push)
139 justification : "functions are defined in header file, they do not need to be used." \
143 static inline constexpr bool starts_with(
const char*
string,
const char* prefix)
146 if (*
string != *prefix) {
156 static inline constexpr bool is_whitespace(
const char*
string,
bool includeNewline =
true)
160 switch (*(
string++)) {
162 case '\f': [[fallthrough]];
163 case '\r': [[fallthrough]];
165 if (! includeNewline)
168 case '\t': [[fallthrough]];
169 case '\v': [[fallthrough]];
171 default:
return false;
176 inline bool is_part_of_word(
char character) {
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);
213 inline const char* message()
const {
return _msg; }
221# pragma GCC diagnostic push
222# pragma GCC diagnostic ignored "-Wunused-parameter"
224# pragma warning(push)
227 justification : "dependend on rtti, exception and stl support not all arguments are needed" \
231template<
typename... Args>
232void ink_assert(
bool condition,
const char* msg =
nullptr, Args... args)
234 static const char* EMPTY =
"";
235 if (msg ==
nullptr) {
239#if defined(INKCPP_ENABLE_STL) || defined(INKCPP_ENABLE_CSTD)
240 if constexpr (
sizeof...(args) > 0) {
241 size_t size = snprintf(
nullptr, 0, msg, args...) + 1;
242 char* message =
static_cast<char*
>(malloc(size));
243 snprintf(message, size, msg, args...);
248#ifdef INK_ENABLE_EXCEPTIONS
250#elif defined(INK_ENABLE_CSTD)
251 fprintf(stderr,
"Ink Assert: %s\n", msg);
254# 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:128
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:112
unsigned char byte_t
Byte type.
Definition system.h:88
unsigned int size_t
Used for the size of arrays.
Definition system.h:109
uint32_t offset_t
Verify sizes.
Definition system.h:103
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:202
uint32_t thread_t
Used to uniquely identify threads.
Definition system.h:115
decltype(static_cast< int * >(nullptr) - static_cast< int * >(nullptr)) ptrdiff_t
Ptr difference type.
Definition system.h:91
constexpr list_flag empty_flag
value representing an empty list
Definition system.h:130
hash_t hash_string(const char *string)
Simple hash for serialization of strings.
Definition system.h:79
const unsigned char * ip_t
Instruction pointer used for addressing within the story instructions.
Definition system.h:106
uint32_t hash_t
Name hash (used for temporary variables)
Definition system.h:72