ERC CISST - cisst software

cmnLODMultiplexerStreambuf< _element, _trait > Class Template Reference

#include <cmnLODMultiplexerStreambuf.h>

Inheritance diagram for cmnLODMultiplexerStreambuf< _element, _trait >:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class _element, class _trait = std::char_traits<_element>>
class cmnLODMultiplexerStreambuf< _element, _trait >

A Streambuffer class that allows output to multiple streambuf objects for Level of Detail information.

Types for dynamic control of output messages. This includes debugging information, error reporting, state logging etc. This file declares *class cmnLODMultiplexerStreambuf*. It is a templated class derived from the standard library's basic_streambuf, with the additional feature that enables channeling the output to multiple other streambuf objects, and each output channel is associated with a Level Of Detail (LOD) descriptor. The cmnLODMultiplexerStreambuf provides both the standard interface functions of basic_streambuf, and a substitute with an extra parameter, which is the output LOD. cmnLODMultiplexerStreambuf the extra-parameter methods should be called from a streambuf proxy that implements the standard basic_streambuf virtual methods, and wraps calls to the multiplexer. Note that the cmnLODMultiplexerStreambuf can be used independently as an output multiplexer withoud LOD, using the standard basic_streambuf interface.

Usage: Include the module in your application with: #include <cmnLODMultiplexerStreambuf.h>

Add output streambuf channels to the multiplexer using the AddChannel() method.

Remove output channels from the multiplexer using the RemoveChannel() method.

Set the output LOD of a channel using the SetChannelLOD() method.

Create proxy streambuf objects that store their LOD, and pass it to the cmnLODMultiplexerStreambuf to do the actual multiplexing. The proxy streambufs should be attached to an ostream object, which is then used by the client module.

Example of using a cmnLODOutputMultiplexer, which is an ostream that is attached to a proxy. Assume that the object lodMultiplexerStreambuf is a cmnLODMultiplexerStreambuf.

        // The multiple output channels
       ofstream log("logfile.txt");
       windowoutputstream display;    // hypothesized class

       lodMultiplexerStreambuf.AddChannel(&log.rdbuf(), CMN_LOG_LOD_RUN_ERROR);
       lodMultiplexerStreambuf.AddChannel(&windowoutputstream.rdbuf(), CMN_LOG_LOD_INIT_WARNING);

       cmnLODOutputMultiplexer multiplexerOutput(&lodMultiplexetStreambuf, CMN_LOG_LOD_INIT_VERBOSE);

       multiplexerStreambuf << "Hello, world" << endl;  // channel the message only to 'log'

Notes:

  1. cmnLODMultiplexerStreambuf 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 cmnLODMultiplexerStreambuf. The AddChannel() function checks for uniqueness.
  5. cmnLODMultiplexerStreambuf does not buffer data. Instead, whenever at attempt is made to use stream::put() on a stream with a multiplexer streambuf, the cmnLODMultiplexerStreambuf::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 109 of file cmnLODMultiplexerStreambuf.h.

Public Types

Public Member Functions

Protected Types

Protected Member Functions

Friends


Member Typedef Documentation

template<class _element, class _trait = std::char_traits<_element>>
typedef cmnLogLoD cmnLODMultiplexerStreambuf< _element, _trait >::LogLoDType

The type of Level of Detail

Definition at line 120 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait = std::char_traits<_element>>
typedef std::list<ElementType> cmnLODMultiplexerStreambuf< _element, _trait >::ChannelContainerType

Type of internal data structure storing the channels. I chose to use a list for efficiency in output iteration over the channels, rather than, for example, a map.

Definition at line 128 of file cmnLODMultiplexerStreambuf.h.


Constructor & Destructor Documentation

template<class _element, class _trait = std::char_traits<_element>>
cmnLODMultiplexerStreambuf< _element, _trait >::cmnLODMultiplexerStreambuf ( std::ofstream &  fileStream  )  [inline]

Create Multiplexer with a default output filestream

Parameters:
fileStream Default Filestream

Definition at line 136 of file cmnLODMultiplexerStreambuf.h.

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

Constructor: currently empty.

Definition at line 143 of file cmnLODMultiplexerStreambuf.h.


Member Function Documentation

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::AddChannel ( ChannelType channel,
LogLoDType  lod 
)

Add an output channel. See notes above.

Parameters:
channel A pointer to the output channel to be added.
lod Level Of Detail for the channel.
Returns:
true: if the channel was added successfully; false: if the channel was not added, e.g. if it is already in the container. Note that in this case, we don't change the LOD value.

Definition at line 282 of file cmnLODMultiplexerStreambuf.h.

Referenced by cmnLODMultiplexerStreambuf< char >::AddChannel(), and cmnLODMultiplexerStreambuf< char >::cmnLODMultiplexerStreambuf().

template<class _element, class _trait = std::char_traits<_element>>
bool cmnLODMultiplexerStreambuf< _element, _trait >::AddChannel ( std::ostream &  outstream,
LogLoDType  lod 
) [inline]

Add a channel defined by an output stream. This methods relies on the existence of a rdbuf() method and calls AddChannel(ChannelType, LoDtype).

Parameters:
outstream Output stream providing the rdbuf.
lod Level of Detail for the stream.

Definition at line 163 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait>
void cmnLODMultiplexerStreambuf< _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 295 of file cmnLODMultiplexerStreambuf.h.

Referenced by cmnLODMultiplexerStreambuf< char >::RemoveChannel().

template<class _element, class _trait = std::char_traits<_element>>
void cmnLODMultiplexerStreambuf< _element, _trait >::RemoveChannel ( std::ostream &  outstream  )  [inline]

Remove an output channel. This methods relies on the existence of a rdbuf() method and calls RemoveChannel(ChannelType).

Parameters:
outstream Output stream providing the rdbuf.

Definition at line 184 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait>
void cmnLODMultiplexerStreambuf< _element, _trait >::RemoveAllChannels ( void   ) 

Remove all output channels.

Definition at line 306 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::SetChannelLOD ( ChannelType channel,
LogLoDType  lod 
)

Set the output LOD of a channel

Parameters:
channel A pointer to the output channel to be added.
lod Level Of Detail for the channel
Returns:
true: if the LOD value was changed successfully; false: otherwise, e.g. if the channel is not in the container.

Definition at line 313 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::GetChannelLOD ( const ChannelType channel,
LogLoDType lod 
) const

Find the output LOD of a channel

Parameters:
channel,: a pointer to the output channel to be added.
lod,: Level Of Detail for the channel
Returns:
true: if the channel was found in the container; false: if the channel is not in the container.

Definition at line 325 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait = std::char_traits<_element>>
const ChannelContainerType& cmnLODMultiplexerStreambuf< _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.

Returns:
ChannelContainerType

Definition at line 220 of file cmnLODMultiplexerStreambuf.h.

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

Multiplexed and LODed version of basic_streambuf xsputn.

Definition at line 337 of file cmnLODMultiplexerStreambuf.h.

Referenced by cmnMultiplexerStreambufProxy< _element, _trait >::xsputn().

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

Override the basic_streambuf sync for multiplexing. Note that in this one we sync() all the channels, regardless of the LOD.

Definition at line 350 of file cmnLODMultiplexerStreambuf.h.

Referenced by cmnMultiplexerStreambufProxy< _element, _trait >::sync().

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::int_type cmnLODMultiplexerStreambuf< _element, _trait >::overflow ( int_type  c,
LogLoDType  lod 
) [protected, virtual]

Multiplexed and LODed version of 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 363 of file cmnLODMultiplexerStreambuf.h.

Referenced by cmnMultiplexerStreambufProxy< _element, _trait >::overflow().

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

Override the basic_streambuf xsputn to do the multiplexing

Definition at line 383 of file cmnLODMultiplexerStreambuf.h.

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::int_type cmnLODMultiplexerStreambuf< _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 396 of file cmnLODMultiplexerStreambuf.h.


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