AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AStrongByteBufferInputStream.h
1#pragma once
2
3#include "ISeekableInputStream.h"
4#include "AUI/Common/AByteBuffer.h"
5#include "AUI/Url/AUrl.h"
6
12private:
13 std::variant<AByteBuffer, _<AByteBuffer>> mRef;
14 size_t mReadPos = 0;
15
16public:
17 static _<AStrongByteBufferInputStream> fromUrl(const AUrl& url);
18
19 explicit AStrongByteBufferInputStream(AByteBuffer buffer) noexcept: mRef(std::move(buffer)) {
20
21 }
22
23 explicit AStrongByteBufferInputStream(_<AByteBuffer> buffer) noexcept: mRef(std::move(buffer)) {
24
25 }
26 ~AStrongByteBufferInputStream() override = default;
27
28 bool isEof() override;
29
30 void seek(std::streamoff offset, std::ios::seekdir seekDir) override;
31
32 size_t tell() override;
33
34 size_t read(char* dst, size_t size) override;
35
36 [[nodiscard]]
37 AByteBuffer& buffer() noexcept {
38 return std::visit(aui::lambda_overloaded {
39 [](AByteBuffer& b) -> AByteBuffer& {
40 return b;
41 },
42 [](_<AByteBuffer>& b) -> AByteBuffer& {
43 return *b;
44 },
45 }, mRef);
46 }
47};
std::vector-like growing array for byte storage.
Definition: AByteBuffer.h:31
Input stream based on AByteBuffer with memory control, clears byte buffer on destruction.
Definition: AStrongByteBufferInputStream.h:11
Uniform Resource Locator implementation.
Definition: AUrl.h:31
virtual size_t read(char *dst, size_t size)=0
Reads up to size bytes from stream. Blocking (waiting for new data) is allowed.
Represents an input stream with updating reading position.
Definition: ISeekableInputStream.h:9
virtual size_t tell()=0
return current reading position
virtual bool isEof()=0
returns true if end of stream has been reached
virtual void seek(std::streamoff offset, std::ios::seekdir seekDir)=0
change reading position, a way of changing depends on seekDir parameter
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: callables.h:34