AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AStrongByteBufferInputStream.h
    1#pragma once
    2
    3#include "ISeekableInputStream.h"
    4#include "AUI/Common/AByteBuffer.h"
    5#include "AUI/Url/AUrl.h"
    6
   11class API_AUI_CORE AStrongByteBufferInputStream: public ISeekableInputStream {
   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, ASeekDir seekDir) override;
   31
   32    [[nodiscard]] std::streampos tell() noexcept 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
size_t read(char *dst, size_t size) override
Reads up to size bytes from stream. Blocking (waiting for new data) is allowed.
std::streampos tell() noexcept override
return current reading position
void seek(std::streamoff offset, ASeekDir seekDir) override
change reading position, a way of changing depends on seekDir parameter
bool isEof() override
returns true if end of stream has been reached
Uniform Resource Locator implementation.
Definition AUrl.h:31
Represents an input stream with updating reading position.
Definition ISeekableInputStream.h:27
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition callables.h:36