AuroraRuntime/Include/Aurora/Async/TaskFrom.hpp
J Reece Wilson b29f8ebf21 [*] Major fix -> vec wrapper w/o glm accessors were broken
[*] Preemptive linux/clang API fixes
[*] Fix clang equiv MSVC template bug (they're nice enough to throw an error instead of crashing)
2022-03-20 09:56:15 +00:00

87 lines
2.6 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: TaskFrom.hpp
Date: 2021-11-1
Author: Reece
***/
#pragma once
namespace Aurora::Async
{
template<typename Info_t = AVoid, typename Out_t = AVoid, class ClazzImpl>
FTask<Info_t, Out_t> TaskFromConsumerRefT(ClazzImpl &&func)
{
FTask<Info_t, Out_t> ret;
ret.onFrame = [callable = func](const Info_t &in) -> Out_t
{
if constexpr (AuIsSame_v<Out_t, AVoid>)
{
callable(in);
return {};
}
else
{
return callable(in);
}
};
return ret;
}
template<typename Out_t = AVoid, typename ... Args, typename Functor>
FTask<AuTuple<Args...>, Out_t> TaskFromTupleCallable(Functor &&func)
{
FTask<AuTuple<Args...>, Out_t> ret;
ret.onFrame = [callable = func](const AuTuple<Args...> &in) -> Out_t
{
return AuTupleApply(callable, in);
};
return ret;
}
template<typename Out_t = AVoid, typename Owner_t, typename ... Args>
FTask<AuTuple<Args...>, Out_t> TaskFromTupleCallableWithOwnerArg(AuFunction<Out_t(Args...)> &&func, const Owner_t &ownerToPin)
{
FTask<AuTuple<Owner_t, Args...>, Out_t> ret;
ret.onFrame = [ownerToPin, callable = func](const AuTuple<Args...> &in) -> Out_t
{
return AuTupleApply(callable, AuTupleCat(AuMakeTuple<Owner_t>(ownerToPin), in));
};
return ret;
}
template<typename Task_t, typename ReturnValue_t, typename ... Args, typename Functor>
Task_t TaskFromTupleCallableWithBindOwner(Functor &&func)
{
Task_t ret;
ret.onFrame = [callable = func](const auto &in) -> ReturnValue_t
{
return AuTupleApply(callable, AuTuplePopFront(in));
};
return ret;
}
template<typename Task_t, typename ReturnValue_t, typename Functor>
Task_t TaskFromTupleCallableWithBindOwner2(Functor func)
{
Task_t ret;
ret.onFrame = [callable = func](const auto &in) -> ReturnValue_t
{
return AuTupleApply(callable, AuTuplePopFront(in));
};
return ret;
}
template<typename Info_t = AVoid, typename Out_t = AVoid>
FTask<Info_t, Out_t> TaskFromVoidVoid(const AuVoidFunc &func)
{
FTask<Info_t, Out_t> ret;
ret.onFrame = [callable = func](const Info_t &in) -> Out_t
{
callable();
return {};
};
return ret;
}
}