IOLink IOL_v1.8.0_release
Loading...
Searching...
No Matches
StreamAccess.h
1#pragma once
2
3#include <cstdint>
4
5#include <iolink/FlagSet.h>
6#include <iolink/IOLinkAPI.h>
7#include <iolink/storage/DataAccess.h>
8
9namespace iolink
10{
11
16{
17 READ = 0x1,
18 WRITE = 0x2,
19 SEEK = 0x4,
20 MEMORY_ACCESS = 0x8,
21
22 READ_WRITE = 0x3,
23 READ_SEEK = 0x5,
24 WRITE_SEEK = 0x6,
25};
26
27extern template class IOLINK_API_IMPORT FlagSet<StreamAccessCapability>;
28
31
32// Define bitwise operators for RandomAccessCapability
33IOLINK_DEFINE_ENUM_BITWISE_OPERATORS(StreamAccessCapability)
34
35
38enum class SeekOrigin
39{
41 BEGIN = 1,
43 CURRENT = 2,
45 END = 3,
46};
47
59class IOLINK_API StreamAccess : public DataAccess
60{
61public:
62 virtual ~StreamAccess() = default;
63
68
72 inline bool support(StreamAccessCapabilitySet flags) { return this->capabilities().has(flags); }
73
80 virtual bool good() const;
81
88 virtual bool eof() const = 0;
89
90 /*
91 * Checks if an error occured on the stream which forbids its use
92 * Remark: 'end of file' is not considered as an error
93 *
94 * Default implementation returns false.
95 *
96 * @return true if an error occured, false otherwise
97 */
98 virtual bool fail() const = 0;
99
103 std::string toString() const;
104
105 // ==== //
106 // READ //
107 // ==== //
108
120 virtual size_t read(size_t size, void* dst);
121
129 virtual uint8_t peek();
130
131 // ===== //
132 // WRITE //
133 // ===== //
134
148 virtual size_t write(size_t size, const void* src);
149
155 virtual void flush();
156
157 // ==== //
158 // SEEK //
159 // ==== //
160
166 virtual size_t tell();
167
185 virtual void seek(int64_t offset, SeekOrigin origin);
186
187 // ============= //
188 // MEMORY_ACCESS //
189 // ============= //
190
198 virtual void* buffer();
199
207 virtual const void* bufferReadOnly() const;
208
216 virtual size_t bufferSize();
217};
218
219} // namespace iolink