| 1 |
#ifndef INCLUDED_FIBO_ |
| 2 |
#define INCLUDED_FIBO_ |
| 3 |
|
| 4 |
#include "../types/types.h" |
| 5 |
#include "../../promisebase/promisebase.h" |
| 6 |
|
| 7 |
class Fibo |
| 8 |
{ |
| 9 |
class State: public PromiseBase<Fibo, State> |
| 10 |
{ |
| 11 |
Triplet d_start; |
| 12 |
Triplet &d_reset; |
| 13 |
|
| 14 |
Triplet d_value; |
| 15 |
size_t d_id; |
| 16 |
|
| 17 |
public: |
| 18 |
State(Triplet &start); |
| 19 |
|
| 20 |
std::suspend_always initial_suspend(); |
| 21 |
std::suspend_always yield_value(Triplet const &value); |
| 22 |
|
| 23 |
Triplet const &value() const; |
| 24 |
void reset(); // to Start |
| 25 |
}; |
| 26 |
// State ENDS |
| 27 |
|
| 28 |
using Handle = std::coroutine_handle<State>; |
| 29 |
public: |
| 30 |
Handle d_handle; |
| 31 |
|
| 32 |
// to access the State, call d_handle.promise() <<<<<<<<< |
| 33 |
|
| 34 |
public: |
| 35 |
using promise_type = State; |
| 36 |
|
| 37 |
explicit Fibo(std::coroutine_handle<State> handle); |
| 38 |
~Fibo(); |
| 39 |
|
| 40 |
Triplet const &next(); |
| 41 |
Triplet const &value() const; |
| 42 |
void reset(); |
| 43 |
|
| 44 |
// void setTriplet(Triplet const &value); |
| 45 |
// size_t id() const; |
| 46 |
}; |
| 47 |
|
| 48 |
inline Fibo::Fibo(std::coroutine_handle<State> handle) |
| 49 |
: |
| 50 |
d_handle(handle) |
| 51 |
{} |
| 52 |
|
| 53 |
inline Fibo::~Fibo() |
| 54 |
{ |
| 55 |
if (d_handle) |
| 56 |
d_handle.destroy(); |
| 57 |
} |
| 58 |
|
| 59 |
extern Fibo g_fibo; |
| 60 |
|
| 61 |
#endif |