ERC CISST - cisst software

cmnMultiplexerStreambuf< _element, _trait > Class Template Reference

#include <cmnMultiplexerStreambuf.h>

Inheritance diagram for cmnMultiplexerStreambuf< _element, _trait >:

Inheritance graph
[legend]
Collaboration diagram for cmnMultiplexerStreambuf< _element, _trait >:

Collaboration graph
[legend]
List of all members.

Detailed Description

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;   // hypothesized class

  cmnOutputMultiplexer multiplexer;
  multiplexer.AddChannel(&log);
  multiplexer.AddChannel(&windowoutputstream);

  multiplexer << "Hello, world" << endl;  // channel the message to all streams.

Notes:

  1. cmnMultiplexerStreambuf does not OWN the output channels. They are created and destroyed externally.
  2. 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.
  3. It is assumed that none of the output channels modifies the data arguments.
  4. It is guaranteed that unique streambuf instances are stored in a single cmnMultiplexerStreambuf. The AddChannel() function checks for uniqueness.
  5. 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

Definition at line 95 of file cmnMultiplexerStreambuf.h.

Public Types

Public Member Functions

Protected Member Functions


Member Typedef Documentation

template<class _element, class _trait = std::char_traits<_element>>
typedef std::list<ChannelType *> cmnMultiplexerStreambuf< _element, _trait >::ChannelContainerType

Type of internal data structure storing the channels.

Definition at line 105 of file cmnMultiplexerStreambuf.h.


Constructor & Destructor Documentation

template<class _element, class _trait = std::char_traits<_element>>
cmnMultiplexerStreambuf< _element, _trait >::cmnMultiplexerStreambuf (  )  [inline]

Constructor: currently empty.

Definition at line 110 of file cmnMultiplexerStreambuf.h.


Member Function Documentation

template<class _element, class _trait>
void cmnMultiplexerStreambuf< _element, _trait >::AddChannel ( ChannelType channel  ) 

Add an output channel. See notes above.

Parameters:
channel A pointer to the output channel to be added.

Definition at line 167 of file cmnMultiplexerStreambuf.h.

template<class _element, class _trait>
void cmnMultiplexerStreambuf< _element, _trait >::RemoveChannel ( ChannelType channel  ) 

Remove an output channel.

Parameters:
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.

Definition at line 179 of file cmnMultiplexerStreambuf.h.

template<class _element, class _trait = std::char_traits<_element>>
const ChannelContainerType& cmnMultiplexerStreambuf< _element, _trait >::GetChannels (  )  const [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.

Definition at line 130 of file cmnMultiplexerStreambuf.h.

template<class _element, class _trait>
std::streamsize cmnMultiplexerStreambuf< _element, _trait >::xsputn ( const _element *  s,
std::streamsize  n 
) [protected, virtual]

Override the basic_streambuf xsputn to do the multiplexing.

Definition at line 186 of file cmnMultiplexerStreambuf.h.

template<class _element, class _trait>
int cmnMultiplexerStreambuf< _element, _trait >::sync (  )  [protected, virtual]

Override the basic_streambuf sync for multiplexing.

Definition at line 198 of file cmnMultiplexerStreambuf.h.

template<class _element, class _trait>
cmnMultiplexerStreambuf< _element, _trait >::int_type cmnMultiplexerStreambuf< _element, _trait >::overflow ( int_type  c = _trait::eof()  )  [protected, virtual]

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.

Definition at line 211 of file cmnMultiplexerStreambuf.h.


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu