[+] 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; } }
|
||||
|
||||
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 >
|
||||
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,
|
||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||
Async::JobFromTupleClazz<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(job),
|
||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||
false);
|
||||
return DispatchWork<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||
Async::JobFromTupleClazz<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(job),
|
||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||
false);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return DispatchWork<std::tuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||
Async::JobFromTupleClazzEx<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(success, failure),
|
||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||
false);
|
||||
return DispatchWork<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>(worker,
|
||||
TaskFromTupleCallableWithBindOwner2<FTask<AuTuple<AuSPtr<Clazz_t>, Args...>, ReturnValue_t>, ReturnValue_t, FunctorTask_t>(task),
|
||||
Async::JobFromTupleClazzEx<ReturnValue_t, AuSPtr<Clazz_t>, Args...>(success, failure),
|
||||
AuMakeTuple<AuSPtr<Clazz_t>, Args...>(AU_FWD(owner), AuForward<Args>(in)...),
|
||||
false);
|
||||
}
|
||||
}
|
@ -12,11 +12,11 @@
|
||||
#define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type)
|
||||
|
||||
#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
|
||||
|
||||
#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
|
||||
|
||||
#define AU_BRACKET_SCOPE(...) __VA_ARGS__
|
||||
|
@ -61,16 +61,16 @@ namespace _audetail {
|
||||
template <class>
|
||||
AuFalseType test(...);
|
||||
|
||||
template <typename B>
|
||||
std::true_type test_pre_ptr_convertible(const volatile B *);
|
||||
template <typename>
|
||||
std::false_type test_pre_ptr_convertible(const volatile void *);
|
||||
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(...)->std::true_type;
|
||||
template <typename B, typename D>
|
||||
auto test_pre_is_base_of(int) ->
|
||||
decltype(test_pre_ptr_convertible<B>(static_cast<D *>(nullptr)));
|
||||
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>
|
||||
@ -201,7 +201,6 @@ constexpr T &&AuForward(AuRemoveReference_t<T> &&arg) noexcept
|
||||
return static_cast<T &&>(arg);
|
||||
}
|
||||
|
||||
|
||||
#if !defined(AURORA_RUNTIME_AU_LIST)
|
||||
#define AURORA_RUNTIME_AU_LIST std::vector
|
||||
#endif
|
||||
@ -278,12 +277,27 @@ using AuWPtr = AURORA_RUNTIME_AU_WEAK_PTR<T>;
|
||||
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
|
||||
#endif
|
||||
|
||||
template<typename T, typename Deleter_t>
|
||||
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
|
||||
|
||||
#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
|
||||
|
||||
template<typename T, typename Deleter_t AURORA_RUNTIME_AU_DEFAULT_DELETER>
|
||||
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
|
||||
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()));
|
||||
}
|
||||
|
||||
#if !defined(AURORA_RUNTIME_AU_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)
|
||||
{
|
||||
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)
|
||||
@ -644,8 +644,8 @@ template<template<typename...> class base,typename derived>
|
||||
struct is_base_of_template_impl_au
|
||||
{
|
||||
template<typename... Ts>
|
||||
static constexpr std::true_type test(const base<Ts...> *);
|
||||
static constexpr std::false_type test(...);
|
||||
static constexpr AuTrueType test(const base<Ts...> *);
|
||||
static constexpr AuFalseType test(...);
|
||||
using type = decltype(test(std::declval<derived*>()));
|
||||
};
|
||||
|
||||
|
@ -885,7 +885,7 @@ namespace Aurora::Async
|
||||
auto pid = GetCurrentWorkerPId();
|
||||
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)
|
||||
{
|
||||
return std::static_pointer_cast<ThreadPool>(pool).get();
|
||||
return AuStaticPointerCast<ThreadPool>(pool).get();
|
||||
}
|
||||
|
||||
static auto GetWorkerInternal()
|
||||
|
@ -395,8 +395,8 @@ namespace Aurora::Compression
|
||||
|
||||
auto bufferSize = meta.internalStreamSize / 2;
|
||||
|
||||
auto bufferIn = AuSPtr<char>(new char[bufferSize], std::default_delete<char[]>());
|
||||
auto bufferOut = 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], AuDefaultDeleter<char[]>());
|
||||
|
||||
while (inputStat < input)
|
||||
{
|
||||
|
@ -518,9 +518,9 @@ namespace Aurora::Compression
|
||||
pref.compressionLevel = info.compressionLevel;
|
||||
|
||||
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 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());
|
||||
if (LZ4F_isError(err))
|
||||
@ -598,8 +598,8 @@ namespace Aurora::Compression
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bufferIn = AuSPtr<char>(new char[frameMaxSize / 2], std::default_delete<char[]>());
|
||||
bufferOut = 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], AuDefaultDeleter<char[]>());
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
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[1;31m",
|
||||
|
@ -299,7 +299,7 @@ namespace Aurora::IO::FS
|
||||
|
||||
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);
|
||||
@ -307,7 +307,7 @@ namespace Aurora::IO::FS
|
||||
#if 0
|
||||
for (const auto &file : files)
|
||||
{
|
||||
std::static_pointer_cast<NtAsyncFileTransaction>(file)->Complete();
|
||||
AuStaticPointerCast<NtAsyncFileTransaction>(file)->Complete();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -167,7 +167,7 @@ namespace Aurora::Memory
|
||||
if (!heap_) return nullptr;
|
||||
auto ptr = _FAlloc(length);
|
||||
if (!ptr) return nullptr;
|
||||
std::memset(ptr, 0, length);
|
||||
AuMemset(ptr, 0, length);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user