20 #define _USE_MATH_DEFINES
29 #define _CRTDBG_MAP_ALLOC
32 #define DEBUG_CLIENTBLOCK new(_CLIENT_BLOCK, __FILE__, __LINE__)
33 #define new DEBUG_CLIENTBLOCK
38 #define UNREACHABLE_INTRINSIC __assume(false)
40 #elif defined(__GNUC__)
45 #define UNREACHABLE_INTRINSIC __builtin_unreachable()
49 #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
59 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
60 TypeName(const TypeName &) = delete; \
61 TypeName & operator =(const TypeName &) = delete
65 #define UNUSED_VAR(X) (void)(X)
72 #define UNUSED UNUSED_VAR
82 #define WIN32_LEAN_AND_MEAN
83 #define _WIN32_WINNT 0x0501
86 #define PLATFORM_CRYPTOGRAPHY (_WIN32_WINNT >= 0x0602)
97 #define PLATFORM_CRYPTOGRAPHY 0
99 #include <arpa/inet.h>
100 #include <netinet/in.h>
101 #include <netinet/tcp.h>
102 #include <sys/socket.h>
126 #include <condition_variable>
139 #include <type_traits>
140 #include <unordered_map>
141 #include <unordered_set>
165 template <
typename T,
size_t Size>
168 static_assert(
sizeof(T) == Size,
"Check the size of integral types");
197 std::string_view a_Format,
eLogLevel, fmt::format_args a_ArgList
200 fmt::vprint(a_Format, a_ArgList);
206 std::string_view a_Format,
eLogLevel, fmt::printf_args a_ArgList
209 fmt::vprintf(a_Format, a_ArgList);
216 fmt::print(
"{}\n", a_Message);
231 #define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
235 #define MiB * 1024 * 1024
238 #define FAST_FLOOR_DIV(x, div) (((x) - (((x) < 0) ? ((div) - 1) : 0)) / (div))
250 cAssertFailure(
const AString & aExpression,
const AString & aFileName,
int aLineNumber):
251 mExpression(aExpression),
252 mFileName(aFileName),
253 mLineNumber(aLineNumber)
257 const AString & expression()
const {
return mExpression; }
258 const AString & fileName()
const {
return mFileName; }
259 int lineNumber()
const {
return mLineNumber; }
265 #define ASSERT(x) do { if (!(x)) { throw cAssertFailure(#x, __FILE__, __LINE__);} } while (0)
269 #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
276 #define ASSERT(x) ( !!(x) || ( LOGERROR("Assertion failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
280 #define VERIFY(x) (!!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), std::abort(), 0))
286 #define UNREACHABLE(x) UNREACHABLE_INTRINSIC
288 #define UNREACHABLE(x) ( FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__), std::abort(), 0)
300 return std::unique_ptr<T>(
new std::remove_extent_t<T>[a_Size]);
306 return std::unique_ptr<T>(
new T);
335 template <
typename T>
336 T
Clamp(T a_Value, T a_Min, T a_Max)
338 return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
346 template <
typename C =
int,
typename T>
347 typename std::enable_if<std::is_arithmetic<T>::value, C>::type
FloorC(T a_Value)
349 return static_cast<C
>(std::floor(a_Value));
353 template <
typename C =
int,
typename T>
354 typename std::enable_if<std::is_arithmetic<T>::value, C>::type
CeilC(T a_Value)
356 return static_cast<C
>(std::ceil(a_Value));
364 using cTickTime = std::chrono::duration<signed int, std::ratio_multiply<std::chrono::milliseconds::period, std::ratio<50>>>;
367 using cTickTimeLong = std::chrono::duration<signed long long int, cTickTime::period>;
370 constexpr
cTickTimeLong operator ""_tick(
const unsigned long long a_Ticks)
378 #ifndef TOLUA_TEMPLATE_BIND
379 #define TOLUA_TEMPLATE_BIND(x)
382 #ifdef TOLUA_EXPOSITION
383 #error TOLUA_EXPOSITION should never actually be defined
386 template <
typename T>
390 return static_cast<std::make_unsigned_t<T>
>(a_Val);
394 constexpr std::string_view
methodName(std::string_view a_PrettyFunction)
396 size_t Bracket = a_PrettyFunction.rfind(
"(");
397 size_t Space = a_PrettyFunction.rfind(
" ", Bracket) + 1;
399 return a_PrettyFunction.substr(Space, Bracket - Space);
403 #if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
404 #define __PRETTY_FUNCTION__ __FUNCSIG__
407 #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
OverloadedVariantAccess(Ts...) -> OverloadedVariantAccess< Ts... >
constexpr std::string_view methodName(std::string_view a_PrettyFunction)
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
std::basic_string_view< std::byte > ContiguousByteBufferView
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
std::chrono::duration< signed int, std::ratio_multiply< std::chrono::milliseconds::period, std::ratio< 50 > >> cTickTime
unsigned long long UInt64
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
std::basic_string< std::byte > ContiguousByteBuffer
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
std::enable_if_t<!std::is_array_v< T >, std::unique_ptr< T > > make_unique_for_overwrite()
void LogSimple(std::string_view a_Message, eLogLevel a_LogLevel)
void LogFormat(std::string_view a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList)
void LogPrintf(std::string_view a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList)
You can use this struct to use in std::visit example: std::visit( OverloadedVariantAccess { [&] (cFir...