2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuroraTypedefs.hpp
|
|
|
|
Date: 2021-6-10
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTINE_TYPEDEFS_INCLUDE)
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <array>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <memory>
|
|
|
|
#else
|
|
|
|
#if defined(AURORA_RUNTINE_TYPEDEFS_INCLUDE_HEADER)
|
|
|
|
#include <AURORA_RUNTINE_TYPEDEFS_INCLUDE_HEADER>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-01-19 17:08:13 +00:00
|
|
|
template<bool v>
|
|
|
|
struct AuBoolType
|
|
|
|
{
|
|
|
|
static constexpr bool value = v;
|
|
|
|
using value_type = bool;
|
|
|
|
using type = AuBoolType;
|
|
|
|
|
|
|
|
constexpr operator value_type() const noexcept
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr value_type operator()() const noexcept
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using AuFalseType = AuBoolType<false>;
|
|
|
|
using AuTrueType = AuBoolType<true>;
|
|
|
|
|
|
|
|
template<class T, class U>
|
|
|
|
struct AuIsSame : AuFalseType
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuIsSame<T, T> : AuTrueType
|
|
|
|
{};
|
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template<class T, class U>
|
2022-01-19 17:08:13 +00:00
|
|
|
inline constexpr bool AuIsSame_v = AuIsSame<T, U>::value;
|
|
|
|
|
|
|
|
namespace _audetail {
|
|
|
|
template <class T>
|
|
|
|
AuBoolType<!std::is_union<T>::value> test(int T:: *);
|
|
|
|
|
|
|
|
template <class>
|
|
|
|
AuFalseType test(...);
|
2022-01-19 17:53:33 +00:00
|
|
|
|
2022-01-19 18:53:22 +00:00
|
|
|
template<typename B>
|
|
|
|
AuTrueType test_pre_ptr_convertible(const volatile B *);
|
|
|
|
template<typename>
|
|
|
|
AuFalseType test_pre_ptr_convertible(const volatile void *);
|
|
|
|
|
|
|
|
template<typename, typename>
|
|
|
|
auto test_pre_is_base_of(...) -> AuTrueType;
|
|
|
|
|
|
|
|
template<typename B, typename D>
|
|
|
|
auto test_pre_is_base_of(int) -> decltype(test_pre_ptr_convertible<B>(static_cast<D *>(nullptr)));
|
2022-01-19 17:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuIsClass : decltype(_audetail::test<T>(nullptr))
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline constexpr bool AuIsClass_v = AuIsClass<T>::value;
|
|
|
|
|
2022-01-19 17:53:33 +00:00
|
|
|
template <typename Base, typename Derived>
|
|
|
|
struct AuIsBaseOf :
|
|
|
|
AuBoolType<
|
|
|
|
AuIsClass_v<Base> &&
|
|
|
|
AuIsClass_v<Derived> &&
|
|
|
|
decltype(_audetail::test_pre_is_base_of<Base, Derived>(0))::value
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template<typename Base, typename Derived>
|
2022-01-19 17:53:33 +00:00
|
|
|
inline constexpr bool AuIsBaseOf_v = AuIsBaseOf<Base, Derived>::value;
|
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template<class>
|
2022-01-19 17:08:13 +00:00
|
|
|
inline constexpr bool AuIsPointer_v = false;
|
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template<class T>
|
|
|
|
inline constexpr bool AuIsPointer_v<T *> = true;
|
2022-01-19 17:08:13 +00:00
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template<class T>
|
|
|
|
inline constexpr bool AuIsPointer_v<T *const> = true;
|
2022-01-19 17:08:13 +00:00
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template <class T>
|
|
|
|
inline constexpr bool AuIsPointer_v<T *volatile> = true;
|
2022-01-19 17:08:13 +00:00
|
|
|
|
2022-01-19 19:26:30 +00:00
|
|
|
template <class T>
|
|
|
|
inline constexpr bool AuIsPointer_v<T *const volatile> = true;
|
2022-01-19 17:08:13 +00:00
|
|
|
|
2022-01-19 17:53:33 +00:00
|
|
|
template<class T>
|
|
|
|
struct AuRemovePointer {typedef T type;};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuRemovePointer<T*> {typedef T type;};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuRemovePointer<T* const> {typedef T type;};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuRemovePointer<T* volatile> {typedef T type;};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuRemovePointer<T* const volatile> {typedef T type;};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
using AuRemovePointer_t = typename AuRemovePointer<T>::type;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
using AuIsVoid = AuIsSame<void, T>;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline constexpr bool AuIsVoid_v = AuIsVoid<T>::value;
|
|
|
|
|
2022-01-19 18:18:13 +00:00
|
|
|
template <class T>
|
|
|
|
struct AuRemoveReference
|
|
|
|
{
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct AuRemoveReference<T &>
|
|
|
|
{
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
struct AuRemoveReference<T &&>
|
|
|
|
{
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
using AuRemoveReference_t = typename AuRemoveReference<T>::type;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
constexpr AuRemoveReference_t<T> &&AuMove(T &&arg) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<AuRemoveReference_t<T> &&>(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<bool Test, class T = void>
|
|
|
|
struct AuEnableIf
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuEnableIf<true, T>
|
|
|
|
{
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<bool Test, class T = void>
|
|
|
|
using AuEnableIf_t = typename AuEnableIf<Test, T>::type;
|
|
|
|
|
|
|
|
|
|
|
|
template<bool Test, class T, class T2>
|
|
|
|
struct AuConditional
|
|
|
|
{
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T, class T2>
|
|
|
|
struct AuConditional<false, T, T2>
|
|
|
|
{
|
|
|
|
using type = T2;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<bool Test, class T, class T2>
|
|
|
|
using AuConditional_t = typename AuConditional<Test, T, T2>::type;
|
|
|
|
|
2022-01-19 18:30:57 +00:00
|
|
|
template <class T>
|
|
|
|
constexpr T &&AuForward(AuRemoveReference_t<T> &arg) noexcept
|
|
|
|
{
|
|
|
|
return static_cast<T &&>(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
constexpr T &&AuForward(AuRemoveReference_t<T> &&arg) noexcept
|
|
|
|
{
|
|
|
|
//static_assert(!is_lvalue_reference_v<T>, "bad forward call");
|
|
|
|
return static_cast<T &&>(arg);
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_LIST)
|
2021-09-29 08:02:51 +00:00
|
|
|
#define AURORA_RUNTIME_AU_LIST std::vector
|
2021-09-06 10:58:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_CPPSHARP)
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using AuList = AURORA_RUNTIME_AU_LIST<T>;
|
|
|
|
|
|
|
|
#else
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
namespace Aurora::Memory
|
|
|
|
{
|
|
|
|
template <class T>
|
|
|
|
struct SpeedyArrayAllocator;
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename T>
|
2022-01-19 17:08:13 +00:00
|
|
|
using AuList = typename std::conditional<AuIsClass_v<T>, AURORA_RUNTIME_AU_LIST<T>, AURORA_RUNTIME_AU_LIST<T, Aurora::Memory::SpeedyArrayAllocator<T>>>::type;
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-09-29 08:02:51 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_ARRAY)
|
|
|
|
#define AURORA_RUNTIME_AU_ARRAY std::array
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename T, size_t Z>
|
|
|
|
using AuArray = AURORA_RUNTIME_AU_ARRAY<T, Z>;
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_AU_FUNC)
|
|
|
|
#define AURORA_RUNTIME_AU_FUNC std::function
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
using AuFunction = AURORA_RUNTIME_AU_FUNC<T>;
|
|
|
|
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_HASH_MAP)
|
|
|
|
#define AURORA_RUNTIME_AU_HASH_MAP std::unordered_map
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename T, typename Z>
|
|
|
|
using AuHashMap = AURORA_RUNTIME_AU_HASH_MAP<T, Z>;
|
|
|
|
|
|
|
|
template<typename T, typename Z, class Utility>
|
|
|
|
using AuHashMapEx = AURORA_RUNTIME_AU_HASH_MAP<T, Z, Utility, Utility>;
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_AU_BST)
|
|
|
|
#define AURORA_RUNTIME_AU_BST std::map
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename T, typename Z>
|
|
|
|
using AuBST = AURORA_RUNTIME_AU_BST<T, Z>;
|
|
|
|
|
|
|
|
template<typename T, typename Z, class Utility>
|
|
|
|
using AuBSTEx = AURORA_RUNTIME_AU_BST<T, Z, Utility>;
|
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_AU_SHARED_PTR)
|
|
|
|
#define AURORA_RUNTIME_AU_SHARED_PTR std::shared_ptr
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2021-09-06 10:58:08 +00:00
|
|
|
using AuSPtr = AURORA_RUNTIME_AU_SHARED_PTR<T>;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_WEAK_PTR)
|
|
|
|
#define AURORA_RUNTIME_AU_WEAK_PTR std::weak_ptr
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename T>
|
|
|
|
using AuWPtr = AURORA_RUNTIME_AU_WEAK_PTR<T>;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_UNIQUE_PTR)
|
|
|
|
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-19 18:53:22 +00:00
|
|
|
template<typename T, typename Deleter_t>
|
|
|
|
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
|
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER)
|
2022-01-19 18:53:22 +00:00
|
|
|
#define AURORA_RUNTIME_AU_DEFAULT_DELETER std::default_delete
|
2021-11-05 17:34:23 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-19 18:53:22 +00:00
|
|
|
template<typename T>
|
|
|
|
using AuDefaultDeleter = AURORA_RUNTIME_AU_DEFAULT_DELETER<T>;
|
|
|
|
|
|
|
|
template <class T, class T2>
|
|
|
|
AuSPtr<T> AuStaticPointerCast(const AuSPtr<T2> &other) noexcept
|
|
|
|
{
|
|
|
|
return AuSPtr<T>(other, static_cast<typename AuSPtr<T>::element_type *>(other.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class T2>
|
|
|
|
AuSPtr<T> AuStaticPointerCast(AuSPtr<T2> &&other) noexcept
|
|
|
|
{
|
|
|
|
return AuSPtr<T>(AuMove(other), static_cast<typename AuSPtr<T>::element_type *>(other.get()));
|
|
|
|
}
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_PAIR)
|
|
|
|
#define AURORA_RUNTIME_AU_PAIR std::pair
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
template<typename A_t, typename B_t>
|
|
|
|
using AuPair = AURORA_RUNTIME_AU_PAIR<A_t, B_t>;
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-01-19 17:08:13 +00:00
|
|
|
|
|
|
|
#if !defined(AURORA_RUNTIME_AU_TUPLE)
|
|
|
|
#define AURORA_RUNTIME_AU_TUPLE std::tuple
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<class... Types>
|
|
|
|
using AuTuple = AURORA_RUNTIME_AU_TUPLE<Types...>;
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#if defined(AURORA_COMPILER_MSVC)
|
|
|
|
using AuAtomicInt = long;
|
|
|
|
#else
|
|
|
|
using AuAtomicInt = int;
|
|
|
|
#endif
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if !defined(AURORA_RUNTIME_AU_OPTIONAL)
|
|
|
|
#define AURORA_RUNTIME_AU_OPTIONAL std::optional
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
using AuOptional = AURORA_RUNTIME_AU_OPTIONAL<T>;
|
|
|
|
|
2021-09-29 12:33:25 +00:00
|
|
|
template<typename ...T>
|
|
|
|
using AuPredicate = AuFunction<bool(T...)>;
|
2021-09-29 08:02:51 +00:00
|
|
|
|
|
|
|
using AuVoidFunc = AuFunction<void(void)>;
|
|
|
|
|
2021-09-29 12:33:25 +00:00
|
|
|
template<typename ...T>
|
|
|
|
using AuConsumer = AuFunction<void(T...)>;
|
2021-09-29 10:41:27 +00:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
using AuSupplier = AuFunction<T(void)>;
|
2021-09-29 08:02:51 +00:00
|
|
|
|
2021-09-29 12:33:25 +00:00
|
|
|
template<class T, typename ...Args>
|
|
|
|
using AuSupplierConsumer = AuFunction<T(Args...)>;
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
//#include "tinyutf8.h"
|
|
|
|
|
|
|
|
using AuString = std::string;// tiny_utf8::utf8_string;
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
using AuUInt64 = Aurora::Types::uint64_t;
|
|
|
|
using AuUInt32 = Aurora::Types::uint32_t;
|
|
|
|
using AuUInt16 = Aurora::Types::uint16_t;
|
|
|
|
using AuUInt8 = Aurora::Types::uint8_t;
|
|
|
|
using AuInt64 = Aurora::Types::int64_t;
|
|
|
|
using AuInt32 = Aurora::Types::int32_t;
|
|
|
|
using AuInt16 = Aurora::Types::int16_t;
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
#if defined(_CPPSHARP)
|
|
|
|
using AuInt8 = Aurora::Types::uint8_t;
|
|
|
|
#else
|
2021-06-27 21:25:29 +00:00
|
|
|
using AuInt8 = Aurora::Types::int8_t;
|
2021-09-06 10:58:08 +00:00
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
using AuMach = Aurora::Types::size_t;
|
|
|
|
using AuSMach = Aurora::Types::ssize_t;
|
|
|
|
using AuSInt = AuSMach;
|
|
|
|
using AuUInt = AuMach;
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
using AuStreamReadWrittenPair_t = AuPair<AuUInt32, AuUInt32>;
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
using AuThreadId_t = AuUInt64;
|
2021-09-06 10:58:08 +00:00
|
|
|
static const AuThreadId_t kThreadIdSpecialMask = AuThreadId_t(1) << AuThreadId_t(63);
|
|
|
|
|
2021-12-26 15:50:15 +00:00
|
|
|
#if defined(__has_include) && !defined(_AUHAS_GLM) && defined(_AU_DETECT_GLM)
|
2021-09-06 10:58:08 +00:00
|
|
|
#if __has_include(<glm/glm.hpp>)
|
|
|
|
#define _AUHAS_GLM
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(_AUHAS_GLM)
|
|
|
|
template<int N>
|
|
|
|
struct AuFVec
|
|
|
|
{
|
|
|
|
float elements[N];
|
2021-10-02 13:19:25 +00:00
|
|
|
|
|
|
|
float operator [](int idx) const
|
|
|
|
{
|
|
|
|
return elements[N];
|
|
|
|
}
|
|
|
|
|
|
|
|
float &operator [](int idx)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
|
|
|
return elements[N];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using AuVec3 = AuFVec<3>;
|
|
|
|
using AuVec4 = AuFVec<4>;
|
|
|
|
#else
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
|
|
|
using AuVec3 = glm::vec3;
|
|
|
|
using AuVec4 = glm::vec4;
|
|
|
|
#endif
|