libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
stringiodevice.h
Go to the documentation of this file.
1
8#pragma once
9
12#include <promeki/core/string.h>
13
15
33class StringIODevice : public IODevice {
34 PROMEKI_OBJECT(StringIODevice, IODevice)
35 public:
42 explicit StringIODevice(String *string, ObjectBase *parent = nullptr);
43
51 explicit StringIODevice(ObjectBase *parent = nullptr);
52
54 ~StringIODevice() override;
55
62 void setString(String *string);
63
68 String *string() const { return _string; }
69
70 Error open(OpenMode mode) override;
71 Error close() override;
72 bool isOpen() const override;
73 int64_t read(void *data, int64_t maxSize) override;
74 int64_t write(const void *data, int64_t maxSize) override;
75 int64_t bytesAvailable() const override;
76 bool isSequential() const override;
77 Error seek(int64_t pos) override;
78 int64_t pos() const override;
79 Result<int64_t> size() const override;
80 bool atEnd() const override;
81
82 private:
83 String *_string = nullptr;
84 int64_t _pos = 0;
85};
86
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
IODevice backed by a promeki String.
Definition stringiodevice.h:33
StringIODevice(ObjectBase *parent=nullptr)
Constructs a StringIODevice with no string.
Error open(OpenMode mode) override
Opens the device with the specified mode.
void setString(String *string)
Sets the underlying String.
int64_t pos() const override
Returns the current read/write position.
int64_t bytesAvailable() const override
Returns the number of bytes available for reading.
int64_t write(const void *data, int64_t maxSize) override
Writes up to maxSize bytes from data.
int64_t read(void *data, int64_t maxSize) override
Reads up to maxSize bytes into data.
StringIODevice(String *string, ObjectBase *parent=nullptr)
Constructs a StringIODevice with an external String.
bool atEnd() const override
Returns true if the current position is at the end.
bool isOpen() const override
Returns true if the device is open.
Result< int64_t > size() const override
Returns the total size of the device in bytes.
Error close() override
Closes the device.
Error seek(int64_t pos) override
Seeks to the given byte offset from the beginning.
~StringIODevice() override
Destructor.
String * string() const
Returns the underlying String, or nullptr.
Definition stringiodevice.h:68
bool isSequential() const override
Returns true if the device is sequential (non-seekable).
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#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