libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
StreamStringIODevice Class Reference

Write-only IODevice that intercepts writes, accumulates characters, and invokes a callback on newlines or flush. More...

#include <streamstring.h>

Inheritance diagram for StreamStringIODevice:
Collaboration diagram for StreamStringIODevice:

Public Types

using OnNewLineFunc = std::function< bool(String &)>
 Callback type invoked for each completed line.
 
- Public Types inherited from IODevice
enum  OpenMode {
  NotOpen = 0x00 , ReadOnly = 0x01 , WriteOnly = 0x02 , ReadWrite = ReadOnly | WriteOnly ,
  Append = 0x04 | WriteOnly
}
 Mode flags controlling how a device is opened. More...
 
- Public Types inherited from ObjectBase
using SlotVariantFunc = std::function< void(const VariantList &)>
 Function type for invoking a slot with a list of Variants.
 

Public Member Functions

 StreamStringIODevice (ObjectBase *parent=nullptr)
 Constructs a StreamStringIODevice.
 
void setOnNewLine (OnNewLineFunc func)
 Sets the callback invoked when a line is complete.
 
const Stringline () const
 Returns the current (possibly incomplete) line buffer.
 
void clearLine ()
 Clears the accumulated line buffer.
 
Error open (OpenMode mode) override
 Opens the device in the specified mode.
 
Error close () override
 Closes the device.
 
bool isOpen () const override
 Returns true if the device is open.
 
int64_t read (void *, int64_t) override
 Always returns -1 (write-only device).
 
int64_t write (const void *data, int64_t maxSize) override
 Writes data, splitting on newlines and invoking the callback.
 
void flush () override
 Flushes the current line buffer via the callback.
 
bool isSequential () const override
 Returns true (this device is sequential).
 
- Public Member Functions inherited from IODevice
 IODevice (ObjectBase *parent=nullptr)
 Constructs an IODevice.
 
virtual ~IODevice ()
 Destructor.
 
virtual int64_t bytesAvailable () const
 Returns the number of bytes available for reading.
 
virtual bool waitForReadyRead (unsigned int timeoutMs=0)
 Waits until data is available for reading or timeout.
 
virtual bool waitForBytesWritten (unsigned int timeoutMs=0)
 Waits until all pending data has been written or timeout.
 
virtual Error seek (int64_t pos)
 Seeks to the given byte offset from the beginning.
 
virtual int64_t pos () const
 Returns the current read/write position.
 
virtual Result< int64_tsize () const
 Returns the total size of the device in bytes.
 
virtual bool atEnd () const
 Returns true if the current position is at the end.
 
OpenMode openMode () const
 Returns the current open mode.
 
bool isReadable () const
 Returns true if the device is readable.
 
bool isWritable () const
 Returns true if the device is writable.
 
Error error () const
 Returns the current error state.
 
void clearError ()
 Clears the error state to Ok.
 
 PROMEKI_SIGNAL (readyRead)
 Emitted when data is available for reading.
 
 PROMEKI_SIGNAL (bytesWritten, int64_t)
 Emitted when bytes have been written.
 
 PROMEKI_SIGNAL (errorOccurred, Error)
 Emitted when an error occurs.
 
 PROMEKI_SIGNAL (aboutToClose)
 Emitted just before the device is closed.
 
- Public Member Functions inherited from ObjectBase
 ObjectBase (ObjectBase *p=nullptr)
 Default ObjectBase constructor.
 
virtual ~ObjectBase ()
 Destructor. Emits aboutToDestroy, detaches from parent, and destroys children.
 
ObjectBaseparent () const
 Returns the parent object, if one. nullptr if none.
 
void setParent (ObjectBase *p)
 Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one.
 
const ObjectBaseListchildList () const
 Returns a list of children of this object.
 
template<typename... Args>
int registerSlot (Slot< Args... > *slot)
 Registers a slot with this object and assigns it an ID.
 
EventLoopeventLoop () const
 Returns the EventLoop this object is affiliated with.
 
void moveToThread (EventLoop *loop)
 Changes the EventLoop affinity of this object.
 
int startTimer (unsigned int intervalMs, bool singleShot=false)
 Starts a timer on this object's EventLoop.
 
void stopTimer (int timerId)
 Stops a timer previously started with startTimer().
 
template<typename... Args>
PROMEKI_NAMESPACE_BEGIN void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 

Additional Inherited Members

- Static Public Member Functions inherited from ObjectBase
static const MetaInfometaInfo ()
 Returns the MetaInfo for the ObjectBase class.
 
template<typename... Args>
static void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object
 
- Public Attributes inherited from ObjectBase
Signal< ObjectBase * > aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName)
 
- Static Public Attributes inherited from ObjectBase
static constexpr const charaboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")"
 
static SignalMeta aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName)
 
- Protected Member Functions inherited from IODevice
void setOpenMode (OpenMode mode)
 Sets the open mode.
 
void setError (const Error &err)
 Sets the error state and emits errorOccurred.
 
- Protected Member Functions inherited from ObjectBase
ObjectBasesignalSender ()
 Returns the ObjectBase that emitted the signal currently being handled.
 
virtual void event (Event *e)
 Called by EventLoop to deliver events to this object.
 
virtual void timerEvent (TimerEvent *e)
 Called when a timer fires for this object.
 

Detailed Description

Write-only IODevice that intercepts writes, accumulates characters, and invokes a callback on newlines or flush.

This is an implementation detail of StreamString and should not be used directly.

Constructor & Destructor Documentation

◆ StreamStringIODevice()

StreamStringIODevice::StreamStringIODevice ( ObjectBase parent = nullptr)
inline

Constructs a StreamStringIODevice.

Parameters
parentThe parent object, or nullptr.

Member Function Documentation

◆ close()

Error StreamStringIODevice::close ( )
inlineoverridevirtual

Closes the device.

Implements IODevice.

◆ flush()

void StreamStringIODevice::flush ( )
inlineoverridevirtual

Flushes the current line buffer via the callback.

Reimplemented from IODevice.

◆ isOpen()

bool StreamStringIODevice::isOpen ( ) const
inlineoverridevirtual

Returns true if the device is open.

Implements IODevice.

◆ isSequential()

bool StreamStringIODevice::isSequential ( ) const
inlineoverridevirtual

Returns true (this device is sequential).

Reimplemented from IODevice.

◆ line()

const String & StreamStringIODevice::line ( ) const
inline

Returns the current (possibly incomplete) line buffer.

Returns
Const reference to the accumulated line.

◆ open()

Error StreamStringIODevice::open ( OpenMode  mode)
inlineoverridevirtual

Opens the device in the specified mode.

Implements IODevice.

◆ read()

int64_t StreamStringIODevice::read ( void ,
int64_t   
)
inlineoverridevirtual

Always returns -1 (write-only device).

Implements IODevice.

◆ setOnNewLine()

void StreamStringIODevice::setOnNewLine ( OnNewLineFunc  func)
inline

Sets the callback invoked when a line is complete.

Parameters
funcCallback to invoke on each complete line.

◆ write()

int64_t StreamStringIODevice::write ( const void data,
int64_t  maxSize 
)
inlineoverridevirtual

Writes data, splitting on newlines and invoking the callback.

Parameters
dataPointer to the data to write.
maxSizeNumber of bytes to write.
Returns
The number of bytes written, or -1 on error.

Implements IODevice.


The documentation for this class was generated from the following file: