cisst-saw
|
A Streambuffer class that allows output to multiple streambuf objects. More...
#include <cmnMultiplexerStreambuf.h>
Public Types | |
typedef std::basic_streambuf < _element, _trait > | ChannelType |
typedef std::basic_streambuf < _element, _trait >::int_type | int_type |
typedef std::list< ChannelType * > | ChannelContainerType |
Public Member Functions | |
cmnMultiplexerStreambuf () | |
void | AddChannel (ChannelType *channel) |
void | RemoveChannel (ChannelType *channel) |
const ChannelContainerType & | GetChannels () const |
Protected Member Functions | |
virtual std::streamsize | xsputn (const _element *s, std::streamsize n) |
virtual int | sync () |
virtual int_type | overflow (int_type c=_trait::eof()) |
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):
Notes:
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.
typedef std::list<ChannelType *> cmnMultiplexerStreambuf< _element, _trait >::ChannelContainerType |
Type of internal data structure storing the channels.
typedef std::basic_streambuf<_element, _trait> cmnMultiplexerStreambuf< _element, _trait >::ChannelType |
typedef std::basic_streambuf<_element, _trait>::int_type cmnMultiplexerStreambuf< _element, _trait >::int_type |
|
inline |
Constructor: currently empty.
void cmnMultiplexerStreambuf< _element, _trait >::AddChannel | ( | ChannelType * | channel | ) |
Add an output channel. See notes above.
channel | A pointer to the output channel to be added. |
|
inline |
Enable access to the channel storage, without addition or removal of channels. Elements of the container can be accessed using the standard const_iterator interfaces. Note that the channels themselves are non-const, so individual manipulation of each is enabled.
|
protectedvirtual |
Override the basic_streambuf overflow for multiplexing. overflow() is called when sputc() discovers it does not have space in the storage buffer. In our case, it's always. See more on it in the basic_streambuf documentation.
void cmnMultiplexerStreambuf< _element, _trait >::RemoveChannel | ( | ChannelType * | channel | ) |
Remove an output channel.
channel | A pointer to the output channel to be removed. No change occurs if the pointer is not on the list of channels for this multiplexer. |
|
protectedvirtual |
Override the basic_streambuf sync for multiplexing.
|
protectedvirtual |
Override the basic_streambuf xsputn to do the multiplexing.