| IOLink 1.11.0

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
9 namespace iolink
10{
11
15 enum class StreamAccessCapability
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
27 extern template class IOLINK_API_IMPORT FlagSet<StreamAccessCapability>;
28
30 using StreamAccessCapabilitySet = FlagSet<StreamAccessCapability>;
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
59 class IOLINK_API StreamAccess : public DataAccess
60{
61 public:
62 virtual ~StreamAccess() = default;
63
67 virtual StreamAccessCapabilitySet capabilities() const = 0;
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
iolink::DataAccess
Parent interface of interfaces used to manipulate raw bytes.
Definition DataAccess.h:20
iolink::FlagSet
Template class to handle a flags system from an enum.
Definition FlagSet.h:43
iolink::StreamAccess
Mother interface for all stream-like data accessors.
Definition StreamAccess.h:60
iolink::StreamAccess::read
virtual size_t read(size_t size, void *dst)
Read data from cursor current position into destination buffer.
iolink::StreamAccess::good
virtual bool good() const
Checks if the stream is currently valid for reading (only) Default implementation returns true if nor...
iolink::StreamAccess::toString
std::string toString() const
Return a string representation.
iolink::StreamAccess::peek
virtual uint8_t peek()
Return the current byte without moving the cursor.
iolink::StreamAccess::flush
virtual void flush()
Assure that all data is written to the endpoint.
iolink::StreamAccess::eof
virtual bool eof() const =0
Checks if the cursor is at the end of the stream for reading For writing, this status is not relevant...
iolink::StreamAccess::buffer
virtual void * buffer()
Return a mutable pointer to the internal CPU memory buffer.
iolink::StreamAccess::capabilities
virtual StreamAccessCapabilitySet capabilities() const =0
iolink::StreamAccess::support
bool support(StreamAccessCapabilitySet flags)
Checks if the StreamAccess supports the given capabilities.
Definition StreamAccess.h:72
iolink::StreamAccess::bufferSize
virtual size_t bufferSize()
Size in bytes of the internal CPU buffer.
iolink::StreamAccess::write
virtual size_t write(size_t size, const void *src)
Write content of src buffer into StreamAccess.
iolink::StreamAccess::bufferReadOnly
virtual const void * bufferReadOnly() const
Return an immutable pointer to the internal CPU memory buffer.
iolink::StreamAccess::seek
virtual void seek(int64_t offset, SeekOrigin origin)
Move the cursor to the desired position.
iolink::StreamAccess::tell
virtual size_t tell()
Returns the current position of the cursor.
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8
iolink::StreamAccessCapability
StreamAccessCapability
Capabilities of a StreamAccess.
Definition StreamAccess.h:16
iolink::StreamAccessCapability::SEEK
@ SEEK
Cursor for read/write can be moved.
iolink::StreamAccessCapability::READ_SEEK
@ READ_SEEK
combination of READ and SEEK
iolink::StreamAccessCapability::WRITE_SEEK
@ WRITE_SEEK
combination of WRITE and SEEK
iolink::SeekOrigin
SeekOrigin
Position indicator for seek method.
Definition StreamAccess.h:39
iolink::SeekOrigin::BEGIN
@ BEGIN
Begining of the stream.
iolink::SeekOrigin::CURRENT
@ CURRENT
Current position of the stream.
iolink::SeekOrigin::END
@ END
End of the stream.
iolink::RandomAccessCapability::READ
@ READ
Data can be read.
iolink::RandomAccessCapability::MEMORY_ACCESS
@ MEMORY_ACCESS
Accessing internal CPU memory buffer.
iolink::RandomAccessCapability::WRITE
@ WRITE
Data can be written.