AuroraRuntime/Include/AuroraTypedefs.hpp
2022-01-28 00:45:37 +00:00

431 lines
9.5 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuroraTypedefs.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
#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
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
{};
template<class T, class U>
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(...);
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)));
}
template<class T>
struct AuIsClass : decltype(_audetail::test<T>(nullptr))
{};
template<class T>
inline constexpr bool AuIsClass_v = AuIsClass<T>::value;
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
>
{};
template<typename Base, typename Derived>
inline constexpr bool AuIsBaseOf_v = AuIsBaseOf<Base, Derived>::value;
template<class>
inline constexpr bool AuIsPointer_v = false;
template<class T>
inline constexpr bool AuIsPointer_v<T *> = true;
template<class T>
inline constexpr bool AuIsPointer_v<T *const> = true;
template <class T>
inline constexpr bool AuIsPointer_v<T *volatile> = true;
template <class T>
inline constexpr bool AuIsPointer_v<T *const volatile> = true;
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;
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<class T> struct AuRemoveConst
{
typedef T type;
};
template<class T> struct AuRemoveConst<const T>
{
typedef T type;
};
template<class T>
using AuRemoveConst_t = typename AuRemoveConst<T>::type;
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;
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);
}
#if !defined(AURORA_RUNTIME_AU_LIST)
#define AURORA_RUNTIME_AU_LIST std::vector
#endif
#if defined(_CPPSHARP)
template<typename T>
using AuList = AURORA_RUNTIME_AU_LIST<T>;
#else
namespace Aurora::Memory
{
template <class T>
struct SpeedyArrayAllocator;
}
template<typename T>
using AuList = AuConditional_t<AuIsClass_v<T>, AURORA_RUNTIME_AU_LIST<T>, AURORA_RUNTIME_AU_LIST<T, Aurora::Memory::SpeedyArrayAllocator<T>>>;
#endif
#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>;
#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
#if !defined(AURORA_RUNTIME_AU_WEAK_PTR)
#define AURORA_RUNTIME_AU_WEAK_PTR std::weak_ptr
#endif
template<typename T>
using AuWPtr = AURORA_RUNTIME_AU_WEAK_PTR<T>;
#if !defined(AURORA_RUNTIME_AU_UNIQUE_PTR)
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
#endif
#if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER)
#define AURORA_RUNTIME_AU_DEFAULT_DELETER std::default_delete
#endif
template<typename T>
using AuDefaultDeleter = AURORA_RUNTIME_AU_DEFAULT_DELETER<T>;
#include <Aurora/Memory/ExtendStlLikeSharedPtr.hpp>
template<typename T>
using AuSPtr = typename Aurora::Memory::ExSharedPtr<T, AURORA_RUNTIME_AU_SHARED_PTR<T>>;
template<typename T, typename Deleter_t>
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
#if !defined(AU_AuEnableSharedFromThis)
#define AU_AuEnableSharedFromThis
template<class X>
struct AuEnableSharedFromThis : Aurora::Memory::ExSharedFromThis<X, std::enable_shared_from_this<X>>
{};
#endif
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()));
}
#if !defined(AURORA_RUNTIME_AU_PAIR)
#define AURORA_RUNTIME_AU_PAIR std::pair
#endif
template<typename A_t, typename B_t>
using AuPair = AURORA_RUNTIME_AU_PAIR<A_t, B_t>;
#if !defined(AURORA_RUNTIME_AU_TUPLE)
#define AURORA_RUNTIME_AU_TUPLE std::tuple
#endif
template<class... Types>
using AuTuple = AURORA_RUNTIME_AU_TUPLE<Types...>;
#if defined(AURORA_COMPILER_MSVC)
using AuAtomicInt = long;
#else
using AuAtomicInt = int;
#endif
#if !defined(AURORA_RUNTIME_AU_OPTIONAL)
#define AURORA_RUNTIME_AU_OPTIONAL std::optional
#endif
template<typename T>
using AuOptional = AURORA_RUNTIME_AU_OPTIONAL<T>;
template<typename ...T>
using AuPredicate = AuFunction<bool(T...)>;
using AuVoidFunc = AuFunction<void(void)>;
template<typename ...T>
using AuConsumer = AuFunction<void(T...)>;
template<class T>
using AuSupplier = AuFunction<T(void)>;
template<class T, typename ...Args>
using AuSupplierConsumer = AuFunction<T(Args...)>;
//#include "tinyutf8.h"
using AuString = std::string;// tiny_utf8::utf8_string;
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;
#if defined(_CPPSHARP)
using AuInt8 = Aurora::Types::uint8_t;
#else
using AuInt8 = Aurora::Types::int8_t;
#endif
using AuMach = Aurora::Types::size_t;
using AuSMach = Aurora::Types::ssize_t;
using AuSInt = AuSMach;
using AuUInt = AuMach;
using AuStreamReadWrittenPair_t = AuPair<AuUInt32, AuUInt32>;
using AuThreadId_t = AuUInt64;
static const AuThreadId_t kThreadIdSpecialMask = AuThreadId_t(1) << AuThreadId_t(63);
#if defined(__has_include) && !defined(_AUHAS_GLM) && defined(_AU_DETECT_GLM)
#if __has_include(<glm/glm.hpp>)
#define _AUHAS_GLM
#endif
#endif
#if !defined(_AUHAS_GLM)
template<int N>
struct AuFVec
{
float elements[N];
float operator [](int idx) const
{
return elements[N];
}
float &operator [](int idx)
{
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