2022-04-01 04:06:53 +00:00
/***
Copyright ( C ) 2021 J Reece Wilson ( a / k / a " Reece " ) . All rights reserved .
File : AuroraMacros . hpp
File : AU_MACROS . hpp
Date : 2021 - 6 - 10
Author : Reece
* * */
# pragma once
2024-03-25 13:39:43 +00:00
# define AU_DEF(type) inline type() = default;
2022-05-27 19:18:49 +00:00
2024-03-25 13:39:43 +00:00
# define AU_COPY(type) inline type(const type&) = default; inline type &operator=(const type &) = default;
# define AU_MOVE(type) inline type(type&&) = default; inline type &operator=(type &&) = default;
# define AU_COPY_MOVE(type) AU_COPY(type) AU_MOVE(type)
# define AU_COPY_MOVE_DEF(type) AU_COPY(type) AU_MOVE(type) AU_DEF(type)
2022-04-01 04:06:53 +00:00
2024-03-25 13:39:43 +00:00
# define AU_NO_COPY(type) inline type(const type&) = delete;
# define AU_NO_MOVE(type) inline type(type&&) = delete;
# define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type)
# define AU_OPERATOR_COPY(type) inline type &operator =(const type ©) { AuResetMember(*this, copy); return *this; }
# define AU_OPERATOR_MOVE(type) inline type &operator =(type &&move) { AuResetMember(*this, AuMove(move)); return *this; }
# define AU_OPERATOR_COPY_MOVE(type) AU_OPERATOR_COPY(type) AU_OPERATOR_MOVE(type)
2022-04-01 04:06:53 +00:00
# if !defined(AU_SHARED_FROM_THIS)
# define AU_SHARED_FROM_THIS (AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->SharedFromThis()))
# endif
# if !defined(AU_WEAK_FROM_THIS)
2023-09-28 11:14:46 +00:00
# define AU_WEAK_FROM_THIS (AuWPtr<AuRemovePointer_t<decltype(this)>>(AU_SHARED_FROM_THIS))
2022-04-01 04:06:53 +00:00
# endif
# define AU_BRACKET_SCOPE(...) __VA_ARGS__
# if !defined(AU_TEMPLATE_ENABLE_WHEN)
# define AU_TEMPLATE_ENABLE_WHEN(...) typename AuEnableIf<__VA_ARGS__>::type* = nullptr
# endif
# define AU_WHAT(n) n
/// @hideinitializer
# define _AU_STRINGIFY(in) #in
# define AU_STRINGIFY(in) _AU_STRINGIFY(in)
/// @hideinitializer
# define _AU_CONCAT(a, b) a ## b
# define AU_CONCAT(a, b) _AU_CONCAT(a, b)
/// @hideinitializer
# define _AUKCON_STRINGIFY_X(in) AU_STRINGIFY(in)
# 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 \
{ \
2024-09-13 07:50:25 +00:00
inline void operator ( ) ( type * t ) const \
2022-04-01 04:06:53 +00:00
{ \
2022-06-24 21:31:22 +00:00
if ( ! t ) return ; \
2022-04-01 04:06:53 +00:00
name # # Release ( t ) ; \
} \
} ; \
\
2024-09-22 16:20:16 +00:00
using name # # SmallUnique_t = AuUPtr < type , CppDeleter # # name > ; \
using name # # SUnique_t = AuUPtr < type , CppDeleter # # name > ; \
using name # # Unique_t = name # # SmallUnique_t ; \
using name # # GUnique_t = AuHUPOf_t < type > ; \
2022-06-24 21:31:22 +00:00
template < class . . . T > \
2024-09-22 16:20:16 +00:00
name # # GUnique_t name # # GenericUnique ( T & & . . . args ) \
2022-04-01 04:06:53 +00:00
{ \
2024-09-22 16:20:16 +00:00
return name # # GUnique_t ( name # # New ( AuForward < T & & > ( args ) . . . ) , name # # Release ) ; \
} \
template < class . . . T > \
name # # SmallUnique_t name # # Unique ( T & & . . . args ) \
{ \
return name # # SmallUnique_t ( name # # New ( AuForward < T & & > ( args ) . . . ) ) ; \
2022-04-01 04:06:53 +00:00
} \
\
2022-06-24 21:31:22 +00:00
using name # # Shared_t = AuSPtr < type > ; \
template < class . . . T > \
2023-08-20 22:51:58 +00:00
name # # Shared_t name # # Shared ( T & & . . . args ) \
2022-04-01 04:06:53 +00:00
{ \
2023-08-20 22:51:58 +00:00
auto ptr = name # # New ( AuForward < T & & > ( args ) . . . ) ; \
2024-03-15 08:41:47 +00:00
if ( ! ptr ) \
{ \
return { } ; \
} \
AUROXTL_COMMODITY_TRY \
{ \
return name # # Shared_t ( ptr , name # # Release ) ; \
} \
AUROXTL_COMMODITY_CATCH \
{ \
return { } ; \
} \
2022-04-01 04:06:53 +00:00
}
# endif
# if !defined(AU_SHARED_API)
2023-03-21 02:33:37 +00:00
# define AU_SHARED_API(name, type, ...) AU_SHARED_API_EX(, name, type, ##__VA_ARGS__)
2022-04-01 04:06:53 +00:00
# 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)
# define AU_INLINE __forceinline
# 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
# endif
# 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
# endif
# if !defined(NO__NEW)
2023-05-03 19:06:37 +00:00
// new... the way it should be.
// not sure who thought it would be a good idea to add tags in the placement new syntax
2022-04-01 04:06:53 +00:00
# if !defined(_new)
# define _new new (std::nothrow)
# endif
# endif
2023-05-03 19:06:37 +00:00
# if !defined(NO_C_CLASS_MACROS)
// C-like inline and static for classes/structures (hence the c-prefix... class)
2024-09-27 16:52:56 +00:00
# if defined(AU_LANG_CPP_17_)
# if !defined(cstatic)
# define cstatic inline static
# endif
# else
# if !defined(cstatic)
# define cstatic static
# endif
2023-05-03 19:06:37 +00:00
# endif
# if !defined(cinline)
# define cinline AU_INLINE
# endif
# endif
2022-04-01 04:06:53 +00:00
# if !defined(NO__INLINE)
2023-05-03 19:06:37 +00:00
// an actual inline pseudo-keyword without the requirement of mucho-texto
2022-04-01 04:06:53 +00:00
# if !defined(auline)
# define auline AU_INLINE
# endif
# endif
# if !defined(AU_FWD)
# define AU_FWD(var) AuForward<decltype(var)>(var)
# endif
2023-08-18 11:48:28 +00:00
# if !defined(AU_ALIGN)
# if defined(AURORA_COMPILER_MSVC)
# define AU_ALIGN(uSize) __declspec(align(uSize))
# else
# define AU_ALIGN(uSize) __attribute__((aligned(uSize)))
# endif
# endif
2024-09-27 16:52:56 +00:00
# if defined(AU_LANG_CPP_20_)
# define AU_EOB_LIKELY [[likely]]
# else
# define AU_EOB_LIKELY
# endif
# if defined(AU_LANG_CPP_20_)
# define AU_EOB_UNLIKELY [[unlikely]]
# else
# define AU_EOB_UNLIKELY
# endif
2024-10-13 07:49:59 +00:00
// AU_INLINE - inline a function, not C++ linkage. AU_INLINE is a C inline / forceinline / always_inline
// auline - "inline" "forceinline" etc tokens are ambiguous in the world of C/C++ headers. auline is a C inline / forceinline / always_inline
// AU_INLINE_XX - C++ inline linkage after XX revision
// AU_CONSTEXPR_XX - C++ constexpr after XX revision
// AU_INLINE_OR_STATIC_XX - C++ inline linkage after XX revision, otherwise use static. Intended for pre-C++17 inlines w/ duplicate symbols.
// AU_OPTIMIZED - Inline (forceinline / always_inline) into caller function or emit noninternalized symbol in the object of the translation unit. In the latter case, we should get some simple leaf function emitted into .code memory nearby, and perhaps the optimizer pass will take care it.
//
// yay, more confusion over what "inline" actually means
# define AU_OPTIMIZED static auline
// ps:
// we wont add __attribute__((optimize(...)) macros
// most compilers treat them as file level options; no per function attributes override this.
// AU_OPTIMIZED doesn't mean -Ourmom optimization. see above.
2024-09-27 16:52:56 +00:00
# if defined(AU_LANG_CPP_14_)
2024-10-13 07:49:59 +00:00
# define AU_CONSTEXPR_14 AUROXTL_CONSTEXPR
# define AU_INLINE_14 inline
2024-09-27 16:52:56 +00:00
# define AU_INLINE_OR_STATIC_14 inline
2024-10-13 07:49:59 +00:00
# define AU_INLINE_CONSTEXPR_14 AU_OPTIMIZED AU_CONSTEXPR_14
# define AU_STATIC_CONSTEXPR_14 static AU_CONSTEXPR_14
2024-09-27 16:52:56 +00:00
# else
# define AU_CONSTEXPR_14
# define AU_INLINE_14
# define AU_INLINE_OR_STATIC_14 static
2024-10-13 07:49:59 +00:00
# define AU_INLINE_CONSTEXPR_14 AU_OPTIMIZED
# define AU_STATIC_CONSTEXPR_14 static
2024-09-27 16:52:56 +00:00
# endif
# if defined(AU_LANG_CPP_17_)
2024-10-13 07:49:59 +00:00
# define AU_CONSTEXPR_17 AUROXTL_CONSTEXPR
# define AU_INLINE_CONSTEXPR_17 AU_OPTIMIZED AU_CONSTEXPR_17
# define AU_STATIC_CONSTEXPR_17 static AU_CONSTEXPR_17
# define AU_INLINE_17 inline
2024-09-27 16:52:56 +00:00
# define AU_INLINE_OR_STATIC_17 inline
# undef AU_CONSTEXPR_14
2024-10-13 07:49:59 +00:00
# define AU_CONSTEXPR_14 AUROXTL_CONSTEXPR
2024-09-27 16:52:56 +00:00
# undef AU_INLINE_14
2024-10-13 07:49:59 +00:00
# define AU_INLINE_14 inline
2024-09-27 16:52:56 +00:00
# undef AU_INLINE_OR_STATIC_14
# define AU_INLINE_OR_STATIC_14 inline
# else
# define AU_CONSTEXPR_17
# define AU_INLINE_17
# define AU_INLINE_OR_STATIC_17 static
2024-10-13 07:49:59 +00:00
# define AU_INLINE_CONSTEXPR_17 AU_OPTIMIZED
# define AU_STATIC_CONSTEXPR_17 static
2024-09-27 16:52:56 +00:00
# endif
# if defined(AU_LANG_CPP_20_)
2024-10-13 07:49:59 +00:00
# define AU_CONSTEXPR_20 AUROXTL_CONSTEXPR
# define AU_INLINE_20 inline
2024-09-27 16:52:56 +00:00
# undef AU_CONSTEXPR_17
2024-10-13 07:49:59 +00:00
# define AU_CONSTEXPR_17 AUROXTL_CONSTEXPR
2024-09-27 16:52:56 +00:00
# undef AU_INLINE_17
2024-10-13 07:49:59 +00:00
# define AU_INLINE_17 inline
2024-09-27 16:52:56 +00:00
# undef AU_INLINE_OR_STATIC_17
# define AU_INLINE_OR_STATIC_17 inline
# else
# define AU_CONSTEXPR_20
# define AU_INLINE_20
# endif
2024-10-13 07:49:59 +00:00
# define AU_INLINE_OR_STATIC_20 AU_INLINE_OR_STATIC_17
# define AU_INLINE_CONSTEXPR_20 AU_INLINE_CONSTEXPR_17
# define AU_STATIC_CONSTEXPR_20 AU_STATIC_CONSTEXPR_17
2024-09-27 16:52:56 +00:00
# define AUROXTL_CONSTEXPR_14 AU_CONSTEXPR_14
# define AUROXTL_CONSTEXPR_17 AU_CONSTEXPR_17
# define AUROXTL_CONSTEXPR_20 AU_CONSTEXPR_20
# if defined(AU_LANG_CPP_20_)
# define AU_BIT_FIELD_AFTER_20(n) : n
2024-09-27 17:18:11 +00:00
# define AU_BIT_FIELD_INIT_AFTER_20(n) { n }
2024-09-27 16:52:56 +00:00
# else
# define AU_BIT_FIELD_AFTER_20(n)
2024-09-27 17:18:11 +00:00
# define AU_BIT_FIELD_INIT_AFTER_20(n)
2024-09-27 16:52:56 +00:00
# endif
# if defined(AU_LANG_CPP_20_)
# define AU_BIT_FIELD_U32_AFTER_20 AuUInt32
# define AU_BIT_FIELD_U64_AFTER_20 AuUInt64
# define AU_BIT_FIELD_U64L_AFTER_20 AuUInt64
# else
# define AU_BIT_FIELD_U32_AFTER_20 AuUInt8
# define AU_BIT_FIELD_U64_AFTER_20 AuUInt8
# define AU_BIT_FIELD_U64L_AFTER_20 AuUInt16
# endif
# if defined(AU_LANG_CPP_20_)
# define AU_CO_ROUTINE_SUS_ALWAYS std::suspend_always
# else
# define AU_CO_ROUTINE_SUS_ALWAYS bool
# endif
2024-10-16 13:13:42 +00:00
# if defined(AU_LANG_CPP_20_)
# define AU_CO_ROUTINE_SUS_NEVER std::suspend_never
# else
# define AU_CO_ROUTINE_SUS_NEVER bool
# endif
2022-04-04 05:10:16 +00:00
# if defined(_AURORA_MISSING_STD_EXCEPTION)
# define AuStringException AuString
# else
struct AuStringException : std : : exception
{
2022-09-13 14:51:23 +00:00
inline AuStringException ( const char * str ) : pNullString ( str )
2022-04-04 05:10:16 +00:00
{
}
2022-09-13 14:51:23 +00:00
inline const char * what ( ) const noexcept override
2022-04-04 05:10:16 +00:00
{
return pNullString ;
}
const char * pNullString ;
} ;
# endif
2022-09-26 14:48:30 +00:00
struct AuStringOwnedException : AuStringException
{
inline AuStringOwnedException ( const char * str ) noexcept : AuStringException ( " " )
{
buffer = str ;
this - > pNullString = buffer . c_str ( ) ;
}
inline AuStringOwnedException ( const std : : string & str ) noexcept : AuStringException ( " " )
{
buffer = str ;
this - > pNullString = buffer . c_str ( ) ;
}
inline AuStringOwnedException ( std : : string & & str ) noexcept : AuStringException ( " " )
{
buffer = std : : move ( str ) ;
this - > pNullString = buffer . c_str ( ) ;
}
std : : string buffer ;
} ;
# if !defined(AU_THROW_CONST_STRING)
# define AU_THROW_CONST_STRING(var) throw AuStringException(var)
# endif
2022-04-01 04:06:53 +00:00
# if !defined(AU_THROW_STRING)
2022-09-26 14:48:30 +00:00
# define AU_THROW_STRING(var) throw AuStringOwnedException(var)
2022-04-01 04:06:53 +00:00
# endif
# 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
# define AU_STRIP_BRACKETS_IMPL(...) __VA_ARGS__
# if !defined(AU_STRIP_BRACKETS)
# define AU_STRIP_BRACKETS(X) AU_WHAT(AU_STRIP_BRACKETS_IMPL X)
# 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
# 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)
2024-03-02 00:54:11 +00:00
# define AuWeakFromThis() AU_WEAK_FROM_THIS
2022-04-01 04:06:53 +00:00
# endif
2023-09-28 11:14:46 +00:00
# if !defined(AuSharedPointerFromThis)
# define AuSharedPointerFromThis(pPtr) (AuSPtr<AuRemoveReference_t<decltype(*pPtr)>>(AuSharedFromThis(), pPtr))
# endif
2024-03-06 20:44:02 +00:00
# if !defined(AuSharedPointerFromShared)
# define AuSharedPointerFromShared(pPtr, pParentShared) (AuSPtr<AuRemoveReference_t<decltype(*pPtr)>>(pParentShared, pPtr))
# endif
2023-09-28 11:14:46 +00:00
2022-04-01 04:06:53 +00:00
# define AU_EMIT_FIRST_COMMA_FIRST(n)n
# define AU_EMIT_FIRST_COMMA_OTHERS(n),n
2022-05-27 19:18:49 +00:00
# include "Objects/Objects.hpp"
2024-07-30 00:51:20 +00:00
2024-09-22 16:20:16 +00:00
# include "AU_USING.hpp"
# if defined(AURORA_ROXTL_HAS_DELETER_ASSERT)
# define _AUROXTL_DELETER_ASSERT(pThat, Type) \
if ( pThat . GetDeleter ( ) ! = Type : : Get ( ) ) \
{ \
AuMemoryPanic ( " Invalid Deleter " ) ; \
}
# else
# define _AUROXTL_DELETER_ASSERT(pThat, Type)
# endif