| IOLink 1.11.0

Loading...
Searching...
No Matches
RandomAccess.h
1#pragma once
2
3#include <iolink/FlagSet.h>
4#include <iolink/IOLinkAPI.h>
5#include <iolink/storage/DataAccess.h>
6
7#include <cstdint>
8
9 namespace iolink
10{
11
15 enum class RandomAccessCapability
16{
17 READ = 0x1,
18 WRITE = 0x2,
19 RESIZE = 0x4,
20 MEMORY_ACCESS = 0x8,
21
22 READ_WRITE = 0x3,
23 WRITE_RESIZE = 0x6,
24};
25
26 extern template class IOLINK_API_IMPORT FlagSet<RandomAccessCapability>;
27
29 using RandomAccessCapabilitySet = FlagSet<RandomAccessCapability>;
30
31// Define bitwise operators for RandomAccessCapability
32IOLINK_DEFINE_ENUM_BITWISE_OPERATORS(RandomAccessCapability)
33
34
45class IOLINK_API RandomAccess : public DataAccess
46{
47 public:
48 virtual ~RandomAccess() = default;
49
53 virtual RandomAccessCapabilitySet capabilities() const = 0;
54
58 inline bool support(RandomAccessCapabilitySet flags) { return this->capabilities().has(flags); }
59
63 virtual size_t size() const = 0;
64
68 std::string toString() const;
69
70 // ==== //
71 // READ //
72 // ==== //
73
87 virtual size_t read(size_t offset, size_t size, void* dst);
88
89 // ===== //
90 // WRITE //
91 // ===== //
92
106 virtual size_t write(size_t offset, size_t size, const void* src);
107
108 // ====== //
109 // RESIZE //
110 // ====== //
111
119 virtual void resize(size_t newSize);
120
121 // ============= //
122 // MEMORY_ACCESS //
123 // ============= //
124
132 virtual void* buffer();
133
141 virtual const void* bufferReadOnly() const;
142
150 virtual size_t bufferSize();
151};
152
153} // 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::RandomAccess
Interface representing a generic array-like accessor.
Definition RandomAccess.h:46
iolink::RandomAccess::read
virtual size_t read(size_t offset, size_t size, void *dst)
Read content of data into given buffer.
iolink::RandomAccess::bufferSize
virtual size_t bufferSize()
Size in bytes of the internal CPU buffer.
iolink::RandomAccess::bufferReadOnly
virtual const void * bufferReadOnly() const
Return an immutable pointer to the internal CPU memory buffer.
iolink::RandomAccess::buffer
virtual void * buffer()
Return a mutable pointer to the internal CPU memory buffer.
iolink::RandomAccess::write
virtual size_t write(size_t offset, size_t size, const void *src)
Write content of src buffer into data.
iolink::RandomAccess::support
bool support(RandomAccessCapabilitySet flags)
Checks if the RandomAccess supports the given capabilities.
Definition RandomAccess.h:58
iolink::RandomAccess::toString
std::string toString() const
Return a string representation.
iolink::RandomAccess::size
virtual size_t size() const =0
Return the number of bytes of the resource accessed.
iolink::RandomAccess::capabilities
virtual RandomAccessCapabilitySet capabilities() const =0
iolink::RandomAccess::resize
virtual void resize(size_t newSize)
Resize content data.
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8
iolink::RandomAccessCapability
RandomAccessCapability
Capabilities of a RandomAccess.
Definition RandomAccess.h:16
iolink::RandomAccessCapability::RESIZE
@ RESIZE
Data can be resized.
iolink::RandomAccessCapability::WRITE_RESIZE
@ WRITE_RESIZE
combination of WRITE and RESIZE
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.