Base module

StreamWriter

Packet stream writer class.

StreamWriter

#include <icy/packetio.h>

Inherits: PacketProcessor

Packet stream writer class.

This class can be connected to a [PacketStream](icy-PacketStream.html#packetstream) to write output to any class that derives from std::ostream. It's most regularly used for writing output files.

Public Attributes

ReturnNameDescription
PacketSignalemitter

emitter

PacketSignal emitter

Public Methods

ReturnNameDescription
StreamWriter inline#### Parameters
~StreamWriter virtual inlineCloses any open std::ofstream and deletes the owned stream.
voidprocess virtual inlineSerializes the packet via write(), flushes it to the output stream, then forwards the packet to the next processor.
StreamT &stream inlineReturns the internal output stream cast to StreamT.
voidonStreamStateChange virtual inlineCloses the output file on Closed or [Error](icy-Error.html#error) stream state transitions.
std::ostream &stream inline#### Returns

StreamWriter

inline

inline StreamWriter(std::ostream * stream)

Parameters

  • stream Output stream to write to; takes ownership.

~StreamWriter

virtual inline

virtual inline ~StreamWriter()

Closes any open std::ofstream and deletes the owned stream.


process

virtual inline

virtual inline void process(IPacket & packet)

Serializes the packet via write(), flushes it to the output stream, then forwards the packet to the next processor.

Parameters

  • packet Incoming packet to process.

stream

inline

template<class StreamT> inline StreamT & stream()

Returns the internal output stream cast to StreamT.

Parameters

  • StreamT Target stream type derived from std::ostream.

Returns

Reference to the cast stream.

Exceptions

  • std::runtime_error if the cast fails.

onStreamStateChange

virtual inline

virtual inline void onStreamStateChange(const PacketStreamState & state)

Closes the output file on Closed or [Error](icy-Error.html#error) stream state transitions.

Parameters

  • state New stream state.

stream

inline

inline std::ostream & stream()

Returns

Reference to the underlying output stream.

Exceptions

  • std::runtime_error if the stream pointer is null.

Protected Attributes

ReturnNameDescription
std::ostream *_ostream

_ostream

std::ostream * _ostream