-
Notifications
You must be signed in to change notification settings - Fork 1
/
doppl_state_member.hpp
80 lines (63 loc) · 1.84 KB
/
doppl_state_member.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _DOPPL_STATE_MEMBER
#define _DOPPL_STATE_MEMBER
#include "doppl_libs.hpp"
#include "doppl_forward_decl.hpp"
namespace doppl {
template<typename T, typename... Ts>
class task_member<semantic_action_specifier::state, T, Ts...> {
private:
std::function<void(std::promise<T>&, SM<T>&, SM<T>&, Ts...)> _state;
public:
//Get state
auto get() -> const decltype(_state) {
return _state;
};
//state = state
SM<T, Ts...>& set(SM<T, Ts...>& input) {
this->_state = input._state;
return *this;
};
//state = value
SM<T, Ts...>& set(decltype(_state) input) {
_state = input;
return *this;
};
task_member() {};
template<typename... As>
task_member(As... input) {
this->set(input...);
};
};
template<typename T>
class task_member<semantic_action_specifier::state, T> {
private:
std::function<void(std::promise<T>&, SM<T>&, SM<T>&)> _state;
public:
//Get state
auto get() -> const decltype(_state) {
return _state;
};
//state = state
template<typename... Ts, typename... As>
SM<T>& set(SM<T, Ts...>& input, As&... args) {
this->_state = [&] (std::promise<T>& p, SM<T>& n, SM<T>& f) {
input.get()(p, n, f, args...);
};
return *this;
};
SM<T>& set(SM<T>& input) {
this->_state = input._state;
return *this;
};
SM<T>& set(decltype(_state) input) {
_state = input;
return *this;
};
task_member() {};
template<typename... Ts>
task_member(Ts... input) {
this->set(input...);
};
};
};
#endif