score
Home
Classes
Namespaces
Files
ExecutionTransaction.hpp
1
#pragma once
2
#include <Process/ExecutionCommand.hpp>
3
#include <Process/ExecutionContext.hpp>
4
5
#include <memory>
6
#include <verdigris>
7
8
namespace
Execution
9
{
10
struct
Context;
11
template
<
typename
T>
12
inline
constexpr
auto
gc(T&& t) noexcept
13
{
14
return
[gced = std::move(t)] {};
15
}
16
17
struct
Transaction
18
{
19
const
Context
& context;
20
std::vector<ExecutionCommand> commands;
21
explicit
Transaction
(
const
Context
& ctx) noexcept
22
: context{ctx}
23
{
24
}
25
26
Transaction
(
Transaction
&& other) noexcept
27
: context{other.context}
28
, commands(std::move(other.commands))
29
{
30
}
31
32
Transaction
& operator=(
Transaction
&& other) noexcept
33
{
34
commands = std::move(other.commands);
35
return
*
this
;
36
}
37
void
reserve(std::size_t sz) noexcept { commands.reserve(sz); }
38
bool
empty()
const
noexcept {
return
commands.empty(); }
39
template
<
typename
T>
40
void
push_back(T&& t) noexcept
41
{
42
commands.push_back(std::move(t));
43
}
44
45
void
run_all()
46
{
47
context.
executionQueue
.enqueue(
48
[t = std::move(*
this
)]()
mutable
{ t.run_all_in_exec(); });
49
}
50
51
void
run_all_in_exec()
52
{
53
for
(
auto
& cmd : commands)
54
cmd();
55
}
56
};
57
58
}
59
Q_DECLARE_METATYPE(
Execution::Transaction
*)
60
W_REGISTER_ARGTYPE(
Execution::Transaction
*)
Execution
Components used for the execution of a score.
Definition:
ProcessComponent.cpp:12
Execution::Context
Definition:
ExecutionContext.hpp:76
Execution::Context::executionQueue
ExecutionCommandQueue & executionQueue
Definition:
ExecutionContext.hpp:91
Execution::Transaction
Definition:
ExecutionTransaction.hpp:18