Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions aether/actions/actions_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,47 @@ class ActionsQueue final : public Action<ActionsQueue> {
on_finished); // subscribe to the action finished
};

using Factory = std::function<std::pair<VTable*, void*>()>;
using Factory = std::function<std::pair<VTable const*, void*>()>;

template <typename TStageRunner>
explicit StageFactory(TStageRunner runner)
: factory_([runner{std::move(runner)}]() mutable {
runner.Run();
auto action = runner.action();

using ActionType = std::decay_t<decltype(*action)>;
static VTable vtable = [&]() {
VTable vt;
vt.stop = [](void* obj) {
template <typename ActionType>
static VTable const* MakeVTable() {
static constexpr VTable vtable{
.stop =
[](void* obj) {
if (obj == nullptr) {
return;
}
if constexpr (ActionStoppable<ActionType>::value) {
auto* a = static_cast<ActionType*>(obj);
a->Stop();
}
};
vt.finished_event =
[](void* obj,
SmallFunction<void(), sizeof(void*)> on_finished)
-> Subscription {
if (obj == nullptr) {
return Subscription{};
}
auto* a = static_cast<ActionType*>(obj);
return a->FinishedEvent().Subscribe(
[on_finished{std::move(on_finished)}]() { on_finished(); });
};
return vt;
}();

return std::make_pair(&vtable, action ? &*action : nullptr);
},
.finished_event =
[](void* obj,
[[maybe_unused]] SmallFunction<void(), sizeof(void*)>
on_finished) -> Subscription {
if (obj == nullptr) {
return Subscription{};
}

auto* a = static_cast<ActionType*>(obj); // 70

return a->FinishedEvent().Subscribe( // 72
[on_finished{std::move(on_finished)}]() { on_finished(); });
},
};
return &vtable;
}

template <typename TStageRunner>
explicit StageFactory(TStageRunner runner)
: factory_([runner{std::move(runner)}]() mutable {
runner.Run();
auto action = runner.action();
using TypeOfAction = std::decay_t<decltype(*action)>;

return std::make_pair(MakeVTable<TypeOfAction>(),
action ? &*action : nullptr);
}) {}

template <typename TFunc>
Expand All @@ -90,7 +96,7 @@ class ActionsQueue final : public Action<ActionsQueue> {

private:
Factory factory_;
VTable* vtable_{};
VTable const* vtable_{};
void* action_obj_{};
};

Expand Down
Loading