[+] AuStaticPointerCast
[*] More refactoring
This commit is contained in:
parent
69f7260514
commit
c965d8384f
@ -126,7 +126,7 @@ namespace Aurora::Async
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define ASYNC_ERROR(exp) { if constexpr (AuIsSame_v<T, bool>) { SysPushErrorGen(exp); return {}; } else { throw std::string(exp); } }
|
#define ASYNC_ERROR(exp) { if constexpr (AuIsSame_v<T, bool>) { SysPushErrorGen(exp); return {}; } else { throw AuString(exp); } }
|
||||||
#define ASYNC_FINISH { if constexpr (AuIsSame_v<T, bool>) { return true; } }
|
#define ASYNC_FINISH { if constexpr (AuIsSame_v<T, bool>) { return true; } }
|
||||||
|
|
||||||
template<typename T = void, typename... Args, AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<T, bool> || AuIsVoid_v<T>)>
|
template<typename T = void, typename... Args, AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<T, bool> || AuIsVoid_v<T>)>
|
||||||
|
@ -102,20 +102,20 @@ namespace Aurora::Async
|
|||||||
template<typename ReturnValue_t = void, typename ... Args, class Clazz_t, class FunctorTask_t, class FuckYou_t >
|
template<typename ReturnValue_t = void, typename ... Args, class Clazz_t, class FunctorTask_t, class FuckYou_t >
|
||||||
static AuSPtr<IWorkItem> DispathSmartWork(const WorkerId_t &worker, AuSPtr<Clazz_t> owner, FunctorTask_t task, FuckYou_t job, Args ... in)
|
static AuSPtr<IWorkItem> DispathSmartWork(const WorkerId_t &worker, AuSPtr<Clazz_t> owner, FunctorTask_t task, FuckYou_t job, Args ... in)
|
||||||
{
|
{
|
||||||
return DispatchWork<std::tuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
return DispatchWork<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
||||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||||
Async::JobFromTupleClazz<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(job),
|
Async::JobFromTupleClazz<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(job),
|
||||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ReturnValue_t = void, typename ... Args, class Clazz_t, class FunctorTask_t, class FuckYou_t, class FuckYou2_t >
|
template<typename ReturnValue_t = void, typename ... Args, class Clazz_t, class FunctorTask_t, class FuckYou_t, class FuckYou2_t >
|
||||||
static AuSPtr<IWorkItem> DispathSmartWorkEx(const WorkerId_t &worker, AuSPtr<Clazz_t> owner, FunctorTask_t task, FuckYou_t success, FuckYou2_t failure, Args ... in)
|
static AuSPtr<IWorkItem> DispathSmartWorkEx(const WorkerId_t &worker, AuSPtr<Clazz_t> owner, FunctorTask_t task, FuckYou_t success, FuckYou2_t failure, Args ... in)
|
||||||
{
|
{
|
||||||
return DispatchWork<std::tuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
return DispatchWork<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
||||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||||
Async::JobFromTupleClazzEx<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(success, failure),
|
Async::JobFromTupleClazzEx<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(success, failure),
|
||||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,11 +12,11 @@
|
|||||||
#define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type)
|
#define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type)
|
||||||
|
|
||||||
#if !defined(AU_SHARED_FROM_THIS)
|
#if !defined(AU_SHARED_FROM_THIS)
|
||||||
#define AU_SHARED_FROM_THIS (std::static_pointer_cast<std::remove_pointer_t<decltype(this)>>(this->shared_from_this()))
|
#define AU_SHARED_FROM_THIS (AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->shared_from_this()))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(AU_WEAK_FROM_THIS)
|
#if !defined(AU_WEAK_FROM_THIS)
|
||||||
#define AU_WEAK_FROM_THIS (AuWPtr<std::remove_pointer_t<decltype(this)>>(std::static_pointer_cast<std::remove_pointer_t<decltype(this)>>(this->shared_from_this())))
|
#define AU_WEAK_FROM_THIS (AuWPtr<AuRemovePointer_t<decltype(this)>>(AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->shared_from_this())))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define AU_BRACKET_SCOPE(...) __VA_ARGS__
|
#define AU_BRACKET_SCOPE(...) __VA_ARGS__
|
||||||
|
@ -61,16 +61,16 @@ namespace _audetail {
|
|||||||
template <class>
|
template <class>
|
||||||
AuFalseType test(...);
|
AuFalseType test(...);
|
||||||
|
|
||||||
template <typename B>
|
template<typename B>
|
||||||
std::true_type test_pre_ptr_convertible(const volatile B *);
|
AuTrueType test_pre_ptr_convertible(const volatile B *);
|
||||||
template <typename>
|
template<typename>
|
||||||
std::false_type test_pre_ptr_convertible(const volatile void *);
|
AuFalseType test_pre_ptr_convertible(const volatile void *);
|
||||||
|
|
||||||
template <typename, typename>
|
template<typename, typename>
|
||||||
auto test_pre_is_base_of(...)->std::true_type;
|
auto test_pre_is_base_of(...) -> AuTrueType;
|
||||||
template <typename B, typename D>
|
|
||||||
auto test_pre_is_base_of(int) ->
|
template<typename B, typename D>
|
||||||
decltype(test_pre_ptr_convertible<B>(static_cast<D *>(nullptr)));
|
auto test_pre_is_base_of(int) -> decltype(test_pre_ptr_convertible<B>(static_cast<D *>(nullptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -201,7 +201,6 @@ constexpr T &&AuForward(AuRemoveReference_t<T> &&arg) noexcept
|
|||||||
return static_cast<T &&>(arg);
|
return static_cast<T &&>(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if !defined(AURORA_RUNTIME_AU_LIST)
|
#if !defined(AURORA_RUNTIME_AU_LIST)
|
||||||
#define AURORA_RUNTIME_AU_LIST std::vector
|
#define AURORA_RUNTIME_AU_LIST std::vector
|
||||||
#endif
|
#endif
|
||||||
@ -278,12 +277,27 @@ using AuWPtr = AURORA_RUNTIME_AU_WEAK_PTR<T>;
|
|||||||
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
|
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<typename T, typename Deleter_t>
|
||||||
|
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
|
||||||
|
|
||||||
#if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER)
|
#if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER)
|
||||||
#define AURORA_RUNTIME_AU_DEFAULT_DELETER = std::default_delete<T>
|
#define AURORA_RUNTIME_AU_DEFAULT_DELETER std::default_delete
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<typename T, typename Deleter_t AURORA_RUNTIME_AU_DEFAULT_DELETER>
|
template<typename T>
|
||||||
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_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()));
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(AURORA_RUNTIME_AU_PAIR)
|
#if !defined(AURORA_RUNTIME_AU_PAIR)
|
||||||
#define AURORA_RUNTIME_AU_PAIR std::pair
|
#define AURORA_RUNTIME_AU_PAIR std::pair
|
||||||
|
@ -282,7 +282,7 @@ template<typename T, typename Z>
|
|||||||
static auline AuOptional<AuSPtr<T>> AuOptionalSharedStaticCast(AuOptional<AuSPtr<Z>> &in)
|
static auline AuOptional<AuSPtr<T>> AuOptionalSharedStaticCast(AuOptional<AuSPtr<Z>> &in)
|
||||||
{
|
{
|
||||||
if (!in.has_value()) return {};
|
if (!in.has_value()) return {};
|
||||||
return std::static_pointer_cast<T>(in.value());
|
return AuStaticPointerCast<T>(in.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static auline bool AuEndsWith(AuString const &value, AuString const &ending)
|
static auline bool AuEndsWith(AuString const &value, AuString const &ending)
|
||||||
@ -644,8 +644,8 @@ template<template<typename...> class base,typename derived>
|
|||||||
struct is_base_of_template_impl_au
|
struct is_base_of_template_impl_au
|
||||||
{
|
{
|
||||||
template<typename... Ts>
|
template<typename... Ts>
|
||||||
static constexpr std::true_type test(const base<Ts...> *);
|
static constexpr AuTrueType test(const base<Ts...> *);
|
||||||
static constexpr std::false_type test(...);
|
static constexpr AuFalseType test(...);
|
||||||
using type = decltype(test(std::declval<derived*>()));
|
using type = decltype(test(std::declval<derived*>()));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ namespace Aurora::Async
|
|||||||
auto pid = GetCurrentWorkerPId();
|
auto pid = GetCurrentWorkerPId();
|
||||||
if (pid.pool)
|
if (pid.pool)
|
||||||
{
|
{
|
||||||
std::static_pointer_cast<ThreadPool>(pid.pool)->ThisExiting();
|
AuStaticPointerCast<ThreadPool>(pid.pool)->ThisExiting();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ namespace Aurora::Async
|
|||||||
|
|
||||||
static auto GetWorkerInternal(const AuSPtr<IThreadPool> &pool)
|
static auto GetWorkerInternal(const AuSPtr<IThreadPool> &pool)
|
||||||
{
|
{
|
||||||
return std::static_pointer_cast<ThreadPool>(pool).get();
|
return AuStaticPointerCast<ThreadPool>(pool).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto GetWorkerInternal()
|
static auto GetWorkerInternal()
|
||||||
|
@ -395,8 +395,8 @@ namespace Aurora::Compression
|
|||||||
|
|
||||||
auto bufferSize = meta.internalStreamSize / 2;
|
auto bufferSize = meta.internalStreamSize / 2;
|
||||||
|
|
||||||
auto bufferIn = AuSPtr<char>(new char[bufferSize], std::default_delete<char[]>());
|
auto bufferIn = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>());
|
||||||
auto bufferOut = AuSPtr<char>(new char[bufferSize], std::default_delete<char[]>());
|
auto bufferOut = AuSPtr<char>(new char[bufferSize], AuDefaultDeleter<char[]>());
|
||||||
|
|
||||||
while (inputStat < input)
|
while (inputStat < input)
|
||||||
{
|
{
|
||||||
|
@ -518,9 +518,9 @@ namespace Aurora::Compression
|
|||||||
pref.compressionLevel = info.compressionLevel;
|
pref.compressionLevel = info.compressionLevel;
|
||||||
|
|
||||||
auto maxFrameSize = info.lz4BlockSize ? info.lz4BlockSize : 64 * 1024;
|
auto maxFrameSize = info.lz4BlockSize ? info.lz4BlockSize : 64 * 1024;
|
||||||
auto buffer = AuSPtr<char>(new char[maxFrameSize], std::default_delete<char[]>());
|
auto buffer = AuSPtr<char>(new char[maxFrameSize], AuDefaultDeleter<char[]>());
|
||||||
auto maxOut = LZ4F_compressBound(maxFrameSize, &pref);
|
auto maxOut = LZ4F_compressBound(maxFrameSize, &pref);
|
||||||
auto outBuffer = AuSPtr<char>(new char[maxOut], std::default_delete<char[]>());;
|
auto outBuffer = AuSPtr<char>(new char[maxOut], AuDefaultDeleter<char[]>());;
|
||||||
|
|
||||||
auto err = LZ4F_createCompressionContext(&cctxPtr, LZ4F_getVersion());
|
auto err = LZ4F_createCompressionContext(&cctxPtr, LZ4F_getVersion());
|
||||||
if (LZ4F_isError(err))
|
if (LZ4F_isError(err))
|
||||||
@ -598,8 +598,8 @@ namespace Aurora::Compression
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bufferIn = AuSPtr<char>(new char[frameMaxSize / 2], std::default_delete<char[]>());
|
bufferIn = AuSPtr<char>(new char[frameMaxSize / 2], AuDefaultDeleter<char[]>());
|
||||||
bufferOut = AuSPtr<char>(new char[frameMaxSize / 2], std::default_delete<char[]>());
|
bufferOut = AuSPtr<char>(new char[frameMaxSize / 2], AuDefaultDeleter<char[]>());
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Aurora::Console
|
namespace Aurora::Console
|
||||||
{
|
{
|
||||||
static AuArray<std::string, static_cast<size_t>(EAnsiColor::eCount)> kAnsiCheats
|
static AuArray<AuString, static_cast<size_t>(EAnsiColor::eCount)> kAnsiCheats
|
||||||
{
|
{
|
||||||
"\033[0;31m",
|
"\033[0;31m",
|
||||||
"\033[1;31m",
|
"\033[1;31m",
|
||||||
|
@ -299,7 +299,7 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
for (const auto & file : files)
|
for (const auto & file : files)
|
||||||
{
|
{
|
||||||
handles.push_back(std::static_pointer_cast<NtAsyncFileTransaction>(file)->GetHandle());
|
handles.push_back(AuStaticPointerCast<NtAsyncFileTransaction>(file)->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ret = WaitForMultipleObjectsEx(handles.size(), handles.data(), false, timeout ? timeout : INFINITE, TRUE);
|
auto ret = WaitForMultipleObjectsEx(handles.size(), handles.data(), false, timeout ? timeout : INFINITE, TRUE);
|
||||||
@ -307,7 +307,7 @@ namespace Aurora::IO::FS
|
|||||||
#if 0
|
#if 0
|
||||||
for (const auto &file : files)
|
for (const auto &file : files)
|
||||||
{
|
{
|
||||||
std::static_pointer_cast<NtAsyncFileTransaction>(file)->Complete();
|
AuStaticPointerCast<NtAsyncFileTransaction>(file)->Complete();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ namespace Aurora::Memory
|
|||||||
if (!heap_) return nullptr;
|
if (!heap_) return nullptr;
|
||||||
auto ptr = _FAlloc(length);
|
auto ptr = _FAlloc(length);
|
||||||
if (!ptr) return nullptr;
|
if (!ptr) return nullptr;
|
||||||
std::memset(ptr, 0, length);
|
AuMemset(ptr, 0, length);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user