-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfifo.hpp
More file actions
76 lines (61 loc) · 2.37 KB
/
Copy pathfifo.hpp
File metadata and controls
76 lines (61 loc) · 2.37 KB
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
/* File: /lib/impl/stream/fifo.hpp
*
* This file is a part of cpplib project which is distributed under MIT License.
* See file LICENSE for full license details.
*
* Copyright (c) 2020-present Nikita Zuev (V.Slavski!) <[email protected]>
*/
#ifndef CPPLIB__lib__impl__stream__fifo__hpp
#define CPPLIB__lib__impl__stream__fifo__hpp
#include <vector>
#include "../../../lib/types.hpp"
#include "../../../lib/data/stream.hpp"
// DECLARATION lib::stream::impl::fifo
namespace lib::stream::impl {
/**
* ,-- read_flush() --, ,--- read_size() ---,
* read_buff [. . . . . . . . . . |....read_cbuffer()....]
* \ | \
* \ read_pos() read_buff.size()
* (same object)
* /
* / ,--- write_flush() ---, ,-- write_size() --...
* write_buff [.....write_buffer()....] . . . . . . . . . ...
* / \
* write_buff.size() RAM limit
* write_pos()
*/
class fifo final
: public data::rwstream_t
{
public:
fifo() = default;
virtual ~fifo() = default;
// IMPLEMENTATION lib::data::rstream_t
data::result_t read( const data::buffer_t & buffer ) override;
data::result_t peek( const data::buffer_t & buffer ) override;
bool read_flush() override;
data::result_t read_size() override;
data::result_t read_pos( usize position ) override;
data::result_t read_pos() override;
data::cbuffer_t read_cbuffer( bool flush ) override;
::std::error_condition read_error() const override { return error(); }
// IMPLEMENTATION lib::data::wstream_t
data::result_t write( const data::cbuffer_t & buffer ) override;
bool write_flush() override;
data::result_t write_size() override;
data::result_t write_pos( usize position ) override;
data::result_t write_pos() override;
data::buffer_t write_buffer( bool flush ) override;
::std::error_condition write_error() const override { return error(); }
// IMPLEMENTATION lib::data::rwstream_t
bool flush() override;
data::result_t size() override;
::std::error_condition error() const override { return {}; }
private:
/// @todo Implement ::lib::ringfifo<> with interface like ::std::vector<>.
::std::vector<u8> buffer_;
usize read_pos_ = 0;
};
} // namespace lib::stream::impl
#endif // CPPLIB__lib__impl__stream__fifo__hpp