File src/impl/batch.h changed (mode: 100644) (index f4bf54c..ca98a2f) |
... |
... |
namespace control { |
19 |
19 |
|
|
20 |
20 |
~BatchImpl() override = default; |
~BatchImpl() override = default; |
21 |
21 |
agent_type hook(function_type) override; |
agent_type hook(function_type) override; |
|
22 |
|
agent_type hook_once(function_type) override; |
22 |
23 |
void invoke(T...) override; |
void invoke(T...) override; |
23 |
|
void invoke_once(T...) override; |
|
24 |
24 |
|
|
25 |
25 |
typedef std::weak_ptr<typename agent_type::element_type> pointer_type; |
typedef std::weak_ptr<typename agent_type::element_type> pointer_type; |
26 |
|
typedef circuit::CircuitQueue<pointer_type> batch_type; |
|
|
26 |
|
typedef std::tuple<pointer_type, bool> tuple_type; |
|
27 |
|
typedef circuit::CircuitQueue<tuple_type> batch_type; |
27 |
28 |
batch_type& elements(); |
batch_type& elements(); |
28 |
29 |
const batch_type& elements() const; |
const batch_type& elements() const; |
29 |
30 |
|
|
File src/impl/batch.hxx changed (mode: 100644) (index d2e3af4..3bac54b) |
... |
... |
namespace control { |
5 |
5 |
auto BatchImpl<T...>::hook(function_type callback) -> agent_type |
auto BatchImpl<T...>::hook(function_type callback) -> agent_type |
6 |
6 |
{ |
{ |
7 |
7 |
auto agent(std::make_shared<function_type>(callback)); |
auto agent(std::make_shared<function_type>(callback)); |
8 |
|
m_elements.push(agent); |
|
|
8 |
|
m_elements.push(std::make_tuple<pointer_type, bool>(agent, true)); |
9 |
9 |
return agent; |
return agent; |
10 |
10 |
} |
} |
11 |
11 |
|
|
12 |
12 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
13 |
13 |
template <typename... T> |
template <typename... T> |
14 |
|
void BatchImpl<T...>::invoke(T... arg) |
|
|
14 |
|
auto BatchImpl<T...>::hook_once(function_type callback) -> agent_type |
15 |
15 |
{ |
{ |
16 |
|
invoke([this](agent_type s) { |
|
17 |
|
elements().push(s); |
|
18 |
|
}, |
|
19 |
|
arg...); |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
///////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
template <typename... T> |
|
24 |
|
void BatchImpl<T...>::invoke_once(T... arg) |
|
25 |
|
{ |
|
26 |
|
invoke([](agent_type) {}, arg...); |
|
|
16 |
|
auto agent(std::make_shared<function_type>(callback)); |
|
17 |
|
m_elements.push(std::make_tuple<pointer_type, bool>(agent, false)); |
|
18 |
|
return agent; |
27 |
19 |
} |
} |
28 |
20 |
|
|
29 |
21 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
30 |
22 |
template <typename... T> |
template <typename... T> |
31 |
|
template <typename U> |
|
32 |
|
void BatchImpl<T...>::invoke(U cb, T... arg) |
|
|
23 |
|
void BatchImpl<T...>::invoke(T... arg) |
33 |
24 |
{ |
{ |
34 |
25 |
batch_type traverse; |
batch_type traverse; |
35 |
26 |
traverse.swap(elements()); |
traverse.swap(elements()); |
36 |
|
pointer_type agent; |
|
|
27 |
|
tuple_type agent; |
37 |
28 |
while (traverse.check_pop(agent)) { |
while (traverse.check_pop(agent)) { |
38 |
|
agent_type s(agent.lock()); |
|
|
29 |
|
agent_type s(std::get<0>(agent).lock()); |
39 |
30 |
if (s) { |
if (s) { |
40 |
31 |
(*s)(arg...); |
(*s)(arg...); |
41 |
32 |
} |
} |
42 |
|
s = agent.lock(); |
|
43 |
|
if (s) { |
|
44 |
|
cb(s); |
|
|
33 |
|
s = std::get<0>(agent).lock(); |
|
34 |
|
if (s && std::get<1>(agent)) { |
|
35 |
|
elements().push(std::move(agent)); |
45 |
36 |
} |
} |
46 |
37 |
} |
} |
47 |
38 |
} |
} |
File src/interface.h changed (mode: 100644) (index d8deeeb..7c7a13a) |
... |
... |
namespace control { |
15 |
15 |
|
|
16 |
16 |
virtual ~Batch() = default; |
virtual ~Batch() = default; |
17 |
17 |
virtual agent_type hook(function_type) = 0; |
virtual agent_type hook(function_type) = 0; |
|
18 |
|
virtual agent_type hook_once(function_type) = 0; |
18 |
19 |
virtual void invoke(T...) = 0; |
virtual void invoke(T...) = 0; |
19 |
|
virtual void invoke_once(T...) = 0; |
|
20 |
20 |
}; |
}; |
21 |
21 |
|
|
22 |
22 |
} // control |
} // control |