File: reader.h

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (77 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download | duplicates (2)
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
#ifndef INCLUDED_READER_
#define INCLUDED_READER_

    // use return_value if an expression is passed to co_return

//interface
#include <iostream>
#include <optional>

#include "../../promisebase/promisebase.h"

struct Reader
{
    using ValueType = std::optional<float>;

    private:
        class State: public PromiseBase<Reader, State>
        {
            ValueType d_value;

            public:
                std::suspend_always yield_value(float value);
                void return_void();
                ValueType const &value() const;
        };

        std::coroutine_handle<State> d_handle;

    public:
        using promise_type = State;

        explicit Reader(std::coroutine_handle<State> handle);
        ~Reader();

        ValueType const &next();
};
//=

// OK (declaration)  std::suspend_always await_transform(float value);

// OK inline std::suspend_always Reader::State::await_transform(float value)
// OK {
// OK     d_value = value;
// OK     return {};
// OK }


//defs
inline std::suspend_always Reader::State::yield_value(float value)
{
    d_value = value;
    return {};
}

inline void Reader::State::return_void()
{
    d_value = ValueType{};
}

inline Reader::ValueType const &Reader::State::value() const
{
    return d_value;
}

inline Reader::Reader(std::coroutine_handle<State> handle)
:
    d_handle(handle)
{}

inline Reader::~Reader()
{
    if (d_handle)
        d_handle.destroy();
}
//=

#endif