libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
mx::TeeBuf Class Reference

A std::streambuf that writes every byte to two underlying buffers. More...

#include <tee_stream.hpp>

Inheritance diagram for mx::TeeBuf:
[legend]
Collaboration diagram for mx::TeeBuf:
[legend]

Public Member Functions

 TeeBuf (std::streambuf *buf1, std::streambuf *buf2)
 Construct a TeeBuf that mirrors output to buf1 and buf2.

Protected Member Functions

virtual int overflow (int c) override
 Write a single character to both buffers.
virtual int sync () override
 Flush both underlying buffers.

Private Attributes

std::streambuf * buf1 = nullptr
 First sink.
std::streambuf * buf2 = nullptr
 Second sink.

Detailed Description

A std::streambuf that writes every byte to two underlying buffers.

Attach two std::streambuf pointers at construction. Any character written through this buffer is forwarded to both sinks; overflow() and sync() are both propagated.

Definition at line 28 of file tee_stream.hpp.

Constructor & Destructor Documentation

◆ TeeBuf()

mx::TeeBuf::TeeBuf ( std::streambuf * buf1,
std::streambuf * buf2 )
inline

Construct a TeeBuf that mirrors output to buf1 and buf2.

Parameters
buf1First destination stream buffer (must outlive this object).
buf2Second destination stream buffer (must outlive this object).

Definition at line 35 of file tee_stream.hpp.

References buf1, and buf2.

Member Function Documentation

◆ overflow()

virtual int mx::TeeBuf::overflow ( int c)
inlineoverrideprotectedvirtual

Write a single character to both buffers.

Parameters
cCharacter to write (may be EOF).
Returns
The character written on success, or traits_type::eof() on failure.

Definition at line 43 of file tee_stream.hpp.

References buf1, buf2, and sync().

◆ sync()

virtual int mx::TeeBuf::sync ( )
inlineoverrideprotectedvirtual

Flush both underlying buffers.

Returns
0 if both flushes succeed, -1 otherwise.

Definition at line 68 of file tee_stream.hpp.

References buf1, and buf2.

Referenced by overflow().

Member Data Documentation

◆ buf1

std::streambuf* mx::TeeBuf::buf1 = nullptr
private

First sink.

Definition at line 78 of file tee_stream.hpp.

Referenced by overflow(), sync(), and TeeBuf().

◆ buf2

std::streambuf* mx::TeeBuf::buf2 = nullptr
private

Second sink.

Definition at line 79 of file tee_stream.hpp.

Referenced by overflow(), sync(), and TeeBuf().


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