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

Collects text output into a String, splitting on newlines. More...

#include <streamstring.h>

Public Types

using OnNewLineFunc = std::function< bool(String &)>
 Callback type invoked for each completed line.
 

Public Member Functions

 StreamString ()
 Constructs a StreamString with no callback.
 
 StreamString (OnNewLineFunc func)
 Constructs a StreamString with a newline callback.
 
 StreamString (const StreamString &)=delete
 Deleted copy constructor.
 
StreamStringoperator= (const StreamString &)=delete
 Deleted copy assignment operator.
 
 StreamString (StreamString &&)=delete
 Deleted move constructor.
 
StreamStringoperator= (StreamString &&)=delete
 Deleted move assignment operator.
 
TextStreamstream ()
 Returns the TextStream associated with this buffer.
 
void setOnNewLine (OnNewLineFunc func)
 Sets or replaces the newline callback.
 
const Stringline () const
 Returns the current (possibly incomplete) line buffer.
 
void clear ()
 Clears the accumulated line buffer.
 

Detailed Description

Collects text output into a String, splitting on newlines.

StreamString accumulates characters written to it. When a newline or flush is encountered, it invokes the onNewLine callback with the accumulated line. The callback returns true to clear the line buffer, or false to keep accumulating.

Example usage (routing stream output to the logger):

promekiInfo("%s", line.cstr());
return true;
});
ss.stream() << "Hello " << 42 << promeki::endl;
Dynamic array container wrapping std::vector.
Definition list.h:40
Collects text output into a String, splitting on newlines.
Definition streamstring.h:136
const String & line() const
Returns the current (possibly incomplete) line buffer.
Definition streamstring.h:183
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35

Constructor & Destructor Documentation

◆ StreamString()

StreamString::StreamString ( OnNewLineFunc  func)
inline

Constructs a StreamString with a newline callback.

Parameters
funcCallback invoked when a complete line is available.

Member Function Documentation

◆ line()

const String & StreamString::line ( ) const
inline

Returns the current (possibly incomplete) line buffer.

Returns
Const reference to the accumulated line.

◆ setOnNewLine()

void StreamString::setOnNewLine ( OnNewLineFunc  func)
inline

Sets or replaces the newline callback.

Parameters
funcNew callback to invoke on each complete line.

◆ stream()

TextStream & StreamString::stream ( )
inline

Returns the TextStream associated with this buffer.

Returns
Reference to the text stream.

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