2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuroraMacros.hpp
|
|
|
|
Date: 2021-6-10
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
2021-07-05 13:34:44 +00:00
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_COPY(type) type(const type&) = default; type &operator=(const type &) = default;
|
|
|
|
#define AU_MOVE(type) type(type&&) = default; type &operator=(type &&) = default;
|
|
|
|
|
|
|
|
#define AU_COPY_MOVE(type) AU_COPY(type) AU_MOVE(type)
|
|
|
|
|
|
|
|
#define AU_NO_COPY(type) type(const type&) = delete;
|
2021-09-06 10:58:08 +00:00
|
|
|
#define AU_NO_MOVE(type) type(type&&) = delete;
|
2021-06-27 21:25:29 +00:00
|
|
|
#define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type)
|
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
|
2021-09-29 10:41:27 +00:00
|
|
|
#if !defined(AU_SHARED_FROM_THIS)
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_SHARED_FROM_THIS (AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->SharedFromThis()))
|
2021-09-29 10:41:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_WEAK_FROM_THIS)
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_WEAK_FROM_THIS (AuWPtr<AuRemovePointer_t<decltype(this)>>(AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->SharedFromThis())))
|
2021-09-29 10:41:27 +00:00
|
|
|
#endif
|
2021-07-05 13:34:44 +00:00
|
|
|
|
2021-09-17 19:26:05 +00:00
|
|
|
#define AU_BRACKET_SCOPE(...) __VA_ARGS__
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(AU_TEMPLATE_ENABLE_WHEN)
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_TEMPLATE_ENABLE_WHEN(...) typename AuEnableIf<__VA_ARGS__>::type* = nullptr
|
2021-10-25 17:06:01 +00:00
|
|
|
#endif
|
2021-09-17 19:26:05 +00:00
|
|
|
|
2021-12-24 16:25:12 +00:00
|
|
|
#define AU_WHAT(n) n
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
/// @hideinitializer
|
2021-06-27 21:25:29 +00:00
|
|
|
#define AU_STRINGIFY_(in) #in
|
|
|
|
#define AU_STRINGIFY(in) AU_STRINGIFY_(in)
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_CONCAT_(a, b) a ## b
|
|
|
|
#define AU_CONCAT(a, b) AU_CONCAT_(a, b)
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
/// @hideinitializer
|
|
|
|
#define _AUKCON_STRINGIFY_X(in) AU_STRINGIFY(in)
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(AU_SHARED_API_EX)
|
|
|
|
#define AU_SHARED_API_EX(vis, name, type, ...) \
|
|
|
|
\
|
|
|
|
vis type *name ## New(__VA_ARGS__); \
|
|
|
|
vis void name ## Release(type *); \
|
|
|
|
static inline void name ## Destroy(type *val) \
|
|
|
|
{ \
|
|
|
|
name ## Release(val); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
struct CppDeleter ## name \
|
|
|
|
{ \
|
|
|
|
void operator()(type *t) \
|
|
|
|
{ \
|
|
|
|
name ## Release(t); \
|
|
|
|
} \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
using name ## Unique_t = AURORA_RUNTIME_AU_UNIQUE_PTR<type, CppDeleter ## name>; \
|
|
|
|
template<typename ... T> \
|
|
|
|
name ## Unique_t name ## Unique(T... args) \
|
|
|
|
{ \
|
|
|
|
return name ## Unique_t(name ## New(args...)); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
using name ## Shared_t = std::shared_ptr<type>; \
|
|
|
|
template<typename ... T> \
|
|
|
|
name ## Shared_t name ## Shared(T... args) \
|
|
|
|
{ \
|
|
|
|
return name ## Shared_t(name ## New(args...), name ## Release); \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_SHARED_API)
|
|
|
|
#define AU_SHARED_API(name, type, ...) AU_SHARED_API_EX(, name, type, #__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_NOINLINE)
|
|
|
|
#if defined(AURORA_COMPILER_MSVC)
|
|
|
|
#define AU_NOINLINE __declspec(noinline)
|
|
|
|
#else
|
|
|
|
#define AU_NOINLINE __attribute__((noinline))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_INLINE)
|
|
|
|
#if defined(AURORA_COMPILER_MSVC)
|
2022-01-18 18:59:19 +00:00
|
|
|
#define AU_INLINE __forceinline
|
2021-10-25 17:06:01 +00:00
|
|
|
#else
|
|
|
|
#define AU_INLINE __attribute__((always_inline))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_NORETURN)
|
|
|
|
#if defined(AURORA_COMPILER_MSVC)
|
|
|
|
#define AU_NORETURN __declspec(noreturn)
|
|
|
|
#elif (defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC))
|
|
|
|
#define AU_NORETURN __attribute__((noreturn))
|
|
|
|
#elif defined(AU_LANG_CPP)
|
|
|
|
#define AU_NORETURN [[noreturn]]
|
|
|
|
#else
|
|
|
|
#define AU_NORETURN
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(AU_ALLOC)
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
#define AU_ALLOC __declspec(allocator)
|
|
|
|
#elif defined(AURORA_COMPILER_CLANG)
|
|
|
|
#define AU_ALLOC __declspec(allocator)
|
|
|
|
#elif defined(AURORA_COMPILER_GCC)
|
|
|
|
#define AU_ALLOC __attribute__((malloc))
|
|
|
|
#else
|
|
|
|
#define AU_ALLOC
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(NO__NEW)
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(_new)
|
|
|
|
#define _new new (std::nothrow)
|
|
|
|
#endif
|
2021-06-30 09:28:52 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-18 14:26:38 +00:00
|
|
|
#if !defined(NO__INLINE)
|
|
|
|
#if !defined(auline)
|
|
|
|
#define auline AU_INLINE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(AU_FWD)
|
|
|
|
#define AU_FWD(var) std::forward<decltype(var)>(var)
|
|
|
|
#endif
|
|
|
|
|
2022-01-18 16:49:50 +00:00
|
|
|
#if !defined(AU_THROW_STRING)
|
|
|
|
#define AU_THROW_STRING(var) throw std::string(var)
|
|
|
|
#endif
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#define AU_ITERATE_ARRAY(index, arry) AuUInt index = 0; index < AuArraySize(arry); index++
|
|
|
|
#define AU_ITERATE_N(index, n) AuUInt index = 0; index < n; index++
|
|
|
|
#define AU_ITERATE_N_TO_X(index, n, x) AuUInt index = n; index < x; index++
|
|
|
|
#define AU_ITERATE_BACKWARDS(index, lastIdx) AuUInt index = lastIdx; index <= 0; index--
|
|
|
|
|
|
|
|
#define AU_ITR_ARRAY AU_ITERATE_ARRAY
|
|
|
|
#define AU_ITR_N AU_ITERATE_N
|
|
|
|
#define AU_ITR_N_TO_X AU_ITERATE_N_TO_X
|
|
|
|
#define AU_ITR_BACKWARDS AU_ITERATE_BACKWARDS
|
2021-10-06 13:48:28 +00:00
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_STRIP_BRACKETS_IMPL(...) __VA_ARGS__
|
2021-10-06 13:48:28 +00:00
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
#if !defined(AU_STRIP_BRACKETS)
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_STRIP_BRACKETS(X) AU_WHAT(AU_STRIP_BRACKETS_IMPL X)
|
2021-10-25 17:06:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_STRIP)
|
|
|
|
#define AU_STRIP AU_STRIP_BRACKETS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_EMIT_FIRST)
|
|
|
|
#define AU_EMIT_FIRST(a, b)a
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_EMIT_SECOND)
|
|
|
|
#define AU_EMIT_SECOND(a, b)b
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AU_EMIT_BOTH)
|
|
|
|
#define AU_EMIT_BOTH(a, b)a, a
|
|
|
|
#endif
|
2021-10-06 13:48:28 +00:00
|
|
|
|
2021-10-21 10:04:29 +00:00
|
|
|
#if !defined(AuBindThis)
|
|
|
|
#define AuBindThis(method, ...) std::bind(method, this, ## __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AuSharedFromThis)
|
|
|
|
#define AuSharedFromThis() AU_SHARED_FROM_THIS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(AuWeakFromThis)
|
|
|
|
#define AuWeakFromThis() AU_SHARED_FROM_THIS
|
2021-10-25 17:06:01 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
#define AU_EMIT_FIRST_COMMA_FIRST(n)n
|
|
|
|
#define AU_EMIT_FIRST_COMMA_OTHERS(n),n
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(variable) AuRemoveConst_t<AuRemoveReference_t<decltype(variable)>>
|
|
|
|
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_CPY(pair) const AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(pair) &pair
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_CPY_SECOND(pair) ,AU_EMIT_CTOR_CPY(pair)
|
|
|
|
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_MOV(pair) AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(pair) &&pair
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_MOV_SECOND(pair) ,AU_EMIT_CTOR_MOV(pair)
|
|
|
|
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_ASSIGN(pair) pair(pair)
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_EMIT_CTOR_ASSIGN_SECOND(pair) ,AU_EMIT_CTOR_ASSIGN(pair)
|
|
|
|
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_DEFINE_CTOR_CPY_VA(thisType, args) \
|
|
|
|
inline thisType(AU_FOR_EACH_FIRST(AU_EMIT_CTOR_CPY, AU_EMIT_CTOR_CPY_SECOND, AU_STRIP_BRACKETS(args))) : AU_FOR_EACH_FIRST(AU_EMIT_CTOR_ASSIGN, AU_EMIT_CTOR_ASSIGN_SECOND, AU_STRIP_BRACKETS(args)) \
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_DEFINE_CTOR_MOV_VA(thisType, args) \
|
|
|
|
inline thisType(AU_FOR_EACH_FIRST(AU_EMIT_CTOR_MOV, AU_EMIT_CTOR_MOV_SECOND, AU_STRIP_BRACKETS(args))) : AU_FOR_EACH_FIRST(AU_EMIT_CTOR_ASSIGN, AU_EMIT_CTOR_ASSIGN_SECOND, AU_STRIP_BRACKETS(args)) \
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// @hideinitializer
|
|
|
|
#define AU_DEFINE_CTOR_VA_(thisType, args) AU_DEFINE_CTOR_CPY_VA(thisType, args) AU_DEFINE_CTOR_MOV_VA(thisType, args)
|
|
|
|
|
|
|
|
|
|
|
|
/// @deprecated
|
|
|
|
#define AU_DEFINE_CTOR_ONE(thisType, pairTypeName) AU_DEFINE_CTOR_VA_(thisType, (AU_EMIT_SECOND pairTypeName))
|
|
|
|
|
2021-10-25 17:06:01 +00:00
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
///
|
|
|
|
#define AU_DEFINE_CTOR_VA(thisType, args) AU_DEFINE_CTOR_CPY_VA(thisType, args) AU_DEFINE_CTOR_MOV_VA(thisType, args)
|