libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
bufferiodevice.h
Go to the documentation of this file.
1
8#pragma once
9
12#include <promeki/core/buffer.h>
13
15
37class BufferIODevice : public IODevice {
38 PROMEKI_OBJECT(BufferIODevice, IODevice)
39 public:
47
55 explicit BufferIODevice(ObjectBase *parent = nullptr);
56
58 ~BufferIODevice() override;
59
67
72 Buffer *buffer() const { return _buffer; }
73
74 Error open(OpenMode mode) override;
75 Error close() override;
76 bool isOpen() const override;
77 int64_t read(void *data, int64_t maxSize) override;
78 int64_t write(const void *data, int64_t maxSize) override;
79 int64_t bytesAvailable() const override;
80 bool isSequential() const override;
81 Error seek(int64_t pos) override;
82 int64_t pos() const override;
83 Result<int64_t> size() const override;
84 bool atEnd() const override;
85
86 private:
87 Buffer *_buffer = nullptr;
88 int64_t _pos = 0;
89};
90
IODevice backed by an in-memory Buffer.
Definition bufferiodevice.h:37
bool atEnd() const override
Returns true if the current position is at the end.
int64_t read(void *data, int64_t maxSize) override
Reads up to maxSize bytes into data.
BufferIODevice(Buffer *buffer, ObjectBase *parent=nullptr)
Constructs a BufferIODevice with an external Buffer.
bool isSequential() const override
Returns true if the device is sequential (non-seekable).
int64_t pos() const override
Returns the current read/write position.
Error seek(int64_t pos) override
Seeks to the given byte offset from the beginning.
~BufferIODevice() override
Destructor.
Buffer * buffer() const
Returns the underlying Buffer, or nullptr.
Definition bufferiodevice.h:72
int64_t bytesAvailable() const override
Returns the number of bytes available for reading.
bool isOpen() const override
Returns true if the device is open.
BufferIODevice(ObjectBase *parent=nullptr)
Constructs a BufferIODevice with no buffer.
void setBuffer(Buffer *buffer)
Sets the underlying Buffer.
int64_t write(const void *data, int64_t maxSize) override
Writes up to maxSize bytes from data.
Error open(OpenMode mode) override
Opens the device with the specified mode.
Result< int64_t > size() const override
Returns the total size of the device in bytes.
Error close() override
Closes the device.
Generic memory buffer descriptor with alignment and memory space support.
Definition buffer.h:85
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Abstract base class for all I/O devices.
Definition iodevice.h:29
OpenMode
Mode flags controlling how a device is opened.
Definition iodevice.h:33
Dynamic array container wrapping std::vector.
Definition list.h:40
Base object for promeki.
Definition objectbase.h:129
ObjectBase * parent() const
Returns the parent object, if one. nullptr if none.
Definition objectbase.h:258
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19