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); }
118inline list_flag read_list_flag(
const char*& ptr)
120 list_flag result = *
reinterpret_cast<const list_flag*
>(ptr);
121 ptr +=
sizeof(list_flag);
130#ifdef INK_ENABLE_UNREAL
134 return CityHash32(
string, FCStringAnsi::Strlen(
string));
138hash_t hash_data(
const unsigned char* data,
size_t len);
145# pragma warning(push)
148 justification : "functions are defined in header file, they do not need to be used." \
152 static inline constexpr bool starts_with(
const char*
string,
const char* prefix)
155 if (*
string != *prefix) {
165 static inline constexpr bool is_whitespace(
const char*
string,
bool includeNewline =
true)
169 switch (*(
string++)) {
171 case '\f': [[fallthrough]];
172 case '\r': [[fallthrough]];
174 if (! includeNewline)
177 case '\t': [[fallthrough]];
178 case '\v': [[fallthrough]];
180 default:
return false;
185 inline bool is_part_of_word(
char character) {
return isalpha(character) || isdigit(character); }
187 static inline constexpr bool is_whitespace(
char character,
bool includeNewline =
true)
191 if (! includeNewline)
193 case '\t': [[fallthrough]];
194 case ' ':
return true;
195 default:
return false;
199#ifndef INK_ENABLE_UNREAL
201 void zero_memory(
void* buffer,
size_t length);
222 inline const char* message()
const {
return _msg; }
230# pragma GCC diagnostic push
231# pragma GCC diagnostic ignored "-Wunused-parameter"
233# pragma warning(push)
236 justification : "dependend on rtti, exception and stl support not all arguments are needed" \
240template<
typename... Args>
241void ink_assert(
bool condition,
const char* msg =
nullptr, Args... args)
243 static const char* EMPTY =
"";
244 if (msg ==
nullptr) {
248#if defined(INK_ENABLE_STL) || defined(INK_ENABLE_CSTD)
249 if constexpr (
sizeof...(args) > 0) {
250 size_t size = snprintf(
nullptr, 0, msg, args...) + 1;
251 char* message =
static_cast<char*
>(malloc(size));
252 snprintf(message, size, msg, args...);
256#ifdef INK_ENABLE_EXCEPTIONS
258#elif defined(INK_ENABLE_CSTD)
259 fprintf(stderr,
"Ink Assert: %s\n", msg);
262# warning no assertion handling this could lead to invalid code paths
267# pragma GCC diagnostic pop
272template<
typename... Args>
273[[noreturn]]
inline void ink_assert(
const char* msg =
nullptr, Args... args)
275 ink_assert(
false, msg, args...);
276#ifdef INK_ENABLE_CSTD
281namespace runtime::internal
283 constexpr unsigned abs(
int i) {
return static_cast<unsigned>(i < 0 ? -i : i); }
286 struct always_false {
287 static constexpr bool value =
false;
290 template<
bool Con,
typename T1,
typename T2>
295 template<
typename T1,
typename T2>
296 struct if_type<false, T1, T2> {
300 template<
bool Con,
typename T1,
typename T2>
301 using if_t =
typename if_type<Con, T1, T2>::type;
303 template<
bool Enable,
typename T =
void>
308 struct enable_if<true, T> {
312 template<
bool Enable,
typename T =
void>
313 using enable_if_t =
typename enable_if<Enable, T>::type;
324constexpr std::nullopt_t
nullopt = std::nullopt;
351 const T& operator*()
const {
return value(); }
353 T& operator*() {
return value(); }
355 const T* operator->()
const {
return &value(); }
357 T* operator->() {
return &value(); }
359 constexpr bool has_value()
const {
return _has_value; }
367 constexpr const T& value()
const
373 constexpr operator bool()
const {
return has_value(); }
376 constexpr T value_or(U&& u)
const
378 return _has_value ? _value :
static_cast<T
>(u);
381 template<
typename... Args>
382 T& emplace(Args... args)
387 new (&_value) T(args...);
393 void test_value()
const
396 inkFail(
"Can't access empty optional!");
400 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:126
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:322
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:324
std::runtime_error ink_exception
exception type thrown if something goes wrong
Definition system.h:211
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:128
hash_t hash_string(const char *string)
Simple hash for serialization of strings.
Definition system.h:132
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