template<class _element, class _trait = std::char_traits<_element>>
class cmnMultiplexerStreambuf< _element, _trait >
A Streambuffer class that allows output to multiple streambuf objects.
Types for dynamic control of output messages. This includes debugging information, error reporting, state logging etc. This file declares class cmnMultiplexerStreambuf. It is a templated class derived from the standard library's basic_streambuf, with the main additional feature that enables channeling the output to multiple other streambuf objects. The multiplexing is implemented by overriding basic_streambuf output functions xsputn(), overflow() and sync().
Usage: Include the module in your application with: #include "cmnMultiplexerStreambuf.h"
Add output streambuf channels to the multiplexer using the AddChannel() method.
Remove output channels from the multiplexer using the RemoveChannel() method.
Attach a cmnMultiplexerStreambuf object with an ostream. The output functions << , put(), write() etc will operate directly on the cmnMultiplexerStreambuf.
Example of using a cmnOutputMultiplexer, which is an ostream using a cmnMultiplexerStrembuf (an output stream with multiplexer streambuf):
ofstream log("logfile.txt");
windowoutputstream display;
multiplexer << "Hello, world" << endl;
Creates a collection of objects that channels output to multiple sinks.
Definition cmnOutputMultiplexer.h:81
ChannelType & AddChannel(ChannelType *channel)
Notes:
- cmnMultiplexerStreambuf does not OWN the output channels. They are created and destroyed externally.
- The initial implementation uses a list to store the addresses of the output channels. There is no guarantee on the order of storage or the order of output channelling.
- It is assumed that none of the output channels modifies the data arguments.
- It is guaranteed that unique streambuf instances are stored in a single cmnMultiplexerStreambuf. The AddChannel() function checks for uniqueness.
cmnMultiplexerStreambuf does not buffer data. Instead, whenever at attempt is made to use stream::put() on a stream with a multiplexer streambuf, the cmnMultiplexerStreambuf::overflow() is called automatically, and it forwards the character to the output channels.
- See also
- C++ manual on basic_ostream and basic_streambuf. cmnOutputMultiplexer.h