Debian Codegraph @

yo/coroutines/demo/fsa/digit/digit.h.0

raw
1 #ifndef INCLUDED_DIGIT_
2 #define INCLUDED_DIGIT_
3
4 #include "../../promisebase/promisebase.h"
5 #include "../awaiter/awaiter.h"
6
7 #include "../start/start.h"
8 #include "../letter/letter.h"
9 #include "../done/done.h"
10
11 class Digit: public Awaiter
12 {
13 struct State: public PromiseBase<Digit, State>
14 {
15 template <typename NextState> // see Start
16 NextState &await_transform(NextState &nextState) const;
17 };
18
19 std::coroutine_handle<State> d_handle;
20
21 public:
22 using promise_type = State;
23 using Handle = std::coroutine_handle<State>;
24
25 explicit Digit(Handle handle);
26 ~Digit();
27
28 template <typename HandleType>
29 std::coroutine_handle<State> await_suspend(HandleType const &handle);
30 };
31
32 template <typename HandleType>
33 std::coroutine_handle<Digit::State> Digit::await_suspend(
34 HandleType const &handle)
35 {
36 auto ret = d_handle;
37 d_handle = 0;
38 return ret;
39 }
40
41 template <typename NextState>
42 inline NextState &Digit::State::await_transform(NextState &nextState) const
43 {
44 return nextState;
45 }
46
47 extern Digit g_digit;
48
49 #endif