43 _onNewLine = std::move(func);
88 const char *p =
static_cast<const char *
>(data);
112 if(!_line.
isEmpty() && _onNewLine) {
113 if(_onNewLine(_line)) _line.
clear();
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ AlreadyOpen
Resource is already open.
Definition error.h:81
Abstract base class for all I/O devices.
Definition iodevice.h:29
OpenMode openMode() const
Returns the current open mode.
Definition iodevice.h:160
bool isWritable() const
Returns true if the device is writable.
Definition iodevice.h:176
OpenMode
Mode flags controlling how a device is opened.
Definition iodevice.h:33
@ WriteOnly
Open for writing only.
Definition iodevice.h:36
@ NotOpen
Device is not open.
Definition iodevice.h:34
void setOpenMode(OpenMode mode)
Sets the open mode.
Definition iodevice.h:215
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
Write-only IODevice that intercepts writes, accumulates characters, and invokes a callback on newline...
Definition streamstring.h:26
bool isOpen() const override
Returns true if the device is open.
Definition streamstring.h:71
Error close() override
Closes the device.
Definition streamstring.h:65
int64_t write(const void *data, int64_t maxSize) override
Writes data, splitting on newlines and invoking the callback.
Definition streamstring.h:86
void clearLine()
Clears the accumulated line buffer.
Definition streamstring.h:53
void setOnNewLine(OnNewLineFunc func)
Sets the callback invoked when a line is complete.
Definition streamstring.h:42
const String & line() const
Returns the current (possibly incomplete) line buffer.
Definition streamstring.h:50
Error open(OpenMode mode) override
Opens the device in the specified mode.
Definition streamstring.h:58
int64_t read(void *, int64_t) override
Always returns -1 (write-only device).
Definition streamstring.h:76
std::function< bool(String &)> OnNewLineFunc
Callback type invoked for each completed line.
Definition streamstring.h:30
void flush() override
Flushes the current line buffer via the callback.
Definition streamstring.h:100
bool isSequential() const override
Returns true (this device is sequential).
Definition streamstring.h:105
StreamStringIODevice(ObjectBase *parent=nullptr)
Constructs a StreamStringIODevice.
Definition streamstring.h:36
Collects text output into a String, splitting on newlines.
Definition streamstring.h:136
std::function< bool(String &)> OnNewLineFunc
Callback type invoked for each completed line.
Definition streamstring.h:139
TextStream & stream()
Returns the TextStream associated with this buffer.
Definition streamstring.h:168
StreamString(OnNewLineFunc func)
Constructs a StreamString with a newline callback.
Definition streamstring.h:150
StreamString & operator=(const StreamString &)=delete
Deleted copy assignment operator.
StreamString & operator=(StreamString &&)=delete
Deleted move assignment operator.
StreamString(StreamString &&)=delete
Deleted move constructor.
const String & line() const
Returns the current (possibly incomplete) line buffer.
Definition streamstring.h:183
void clear()
Clears the accumulated line buffer.
Definition streamstring.h:186
void setOnNewLine(OnNewLineFunc func)
Sets or replaces the newline callback.
Definition streamstring.h:174
StreamString(const StreamString &)=delete
Deleted copy constructor.
StreamString()
Constructs a StreamString with no callback.
Definition streamstring.h:142
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
bool isEmpty() const
Returns true if the string has zero length.
Definition string.h:315
void clear()
Removes all characters from the string.
Definition string.h:449
Formatted text I/O with encoding awareness.
Definition textstream.h:54
#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