cisst-saw
Loading...
Searching...
No Matches
cmnLODMultiplexerStreambuf< _element, _trait > Class Template Reference

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

#include <cmnLODMultiplexerStreambuf.h>

Inheritance diagram for cmnLODMultiplexerStreambuf< _element, _trait >:

Public Types

typedef cmnLODMultiplexerStreambuf< _element, _trait > ThisType
typedef std::basic_streambuf< _element, _trait > BaseClassType
typedef std::basic_streambuf< _element, _trait > ChannelType
typedef std::pair< ChannelType *, cmnLogMaskElementType
typedef std::list< ElementTypeChannelContainerType
typedef ChannelContainerType::iterator IteratorType
typedef ChannelContainerType::const_iterator ConstIteratorType
typedef std::list< ThisType * > MultiplexerContainerType
typedef MultiplexerContainerType::iterator MultiplexerIteratorType
typedef MultiplexerContainerType::const_iterator MultiplexerConstIteratorType

Public Member Functions

 cmnLODMultiplexerStreambuf (std::ofstream &fileStream)
 cmnLODMultiplexerStreambuf ()
bool AddChannel (ChannelType *channel, cmnLogMask mask)
bool AddChannel (std::ostream &outstream, cmnLogMask mask)
bool AddMultiplexer (ThisType *multiplexer)
void RemoveChannel (ChannelType *channel)
void RemoveMultiplexer (ThisType *multiplexer)
void RemoveChannel (std::ostream &outstream)
void RemoveAllChannels (void)
bool SetChannelMask (ChannelType *channel, cmnLogMask mask)
bool GetChannelMask (const ChannelType *channel, cmnLogMask &mask) const
const ChannelContainerTypeGetChannels (void) const

Protected Types

typedef std::basic_streambuf< _element, _trait >::int_type int_type

Protected Member Functions

virtual std::streamsize xsputn (const _element *s, std::streamsize n, cmnLogLevel level)
virtual int sync ()
virtual int_type overflow (int_type c, cmnLogLevel level)
virtual std::streamsize xsputn (const _element *s, std::streamsize n)
virtual int_type overflow (int_type c=_trait::eof())
IteratorType FindChannel (const ChannelType *channel)
ConstIteratorType FindChannel (const ChannelType *channel) const
MultiplexerIteratorType FindMultiplexer (const ThisType *multiplexer)
MultiplexerConstIteratorType FindMultiplexer (const ThisType *multiplexer) const

Protected Attributes

ChannelContainerType Channels
MultiplexerContainerType Multiplexers

Friends

class cmnMultiplexerStreambufProxy< _element, _trait >

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 SetChannelMask() 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, CMN_LOG_ALLOW_ALL);
lodMultiplexerStreambuf.AddChannel(&windowoutputstream, CMN_LOG_ALLOW_ERRORS_AND_WARNINGS);
cmnLODOutputMultiplexer multiplexerOutput(&lodMultiplexetStreambuf, CMN_LOG_LEVEL_INIT_DEBUG);
multiplexerStreambuf << "Hello, world" << endl; // channel the message only to 'log'
Types for dynamic control of output messages.
Definition cmnLODOutputMultiplexer.h:72
#define CMN_LOG_LEVEL_INIT_DEBUG
Definition cmnLogLoD.h:61
#define CMN_LOG_ALLOW_ERRORS_AND_WARNINGS
Definition cmnLogLoD.h:72
#define CMN_LOG_ALLOW_ALL
Definition cmnLogLoD.h:75

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

Member Typedef Documentation

◆ BaseClassType

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

◆ ChannelContainerType

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.

◆ ChannelType

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

◆ ConstIteratorType

template<class _element, class _trait = std::char_traits<_element>>
typedef ChannelContainerType::const_iterator cmnLODMultiplexerStreambuf< _element, _trait >::ConstIteratorType

◆ ElementType

template<class _element, class _trait = std::char_traits<_element>>
typedef std::pair<ChannelType *, cmnLogMask> cmnLODMultiplexerStreambuf< _element, _trait >::ElementType

◆ int_type

template<class _element, class _trait = std::char_traits<_element>>
typedef std::basic_streambuf<_element,_trait>::int_type cmnLODMultiplexerStreambuf< _element, _trait >::int_type
protected

◆ IteratorType

template<class _element, class _trait = std::char_traits<_element>>
typedef ChannelContainerType::iterator cmnLODMultiplexerStreambuf< _element, _trait >::IteratorType

◆ MultiplexerConstIteratorType

template<class _element, class _trait = std::char_traits<_element>>
typedef MultiplexerContainerType::const_iterator cmnLODMultiplexerStreambuf< _element, _trait >::MultiplexerConstIteratorType

◆ MultiplexerContainerType

template<class _element, class _trait = std::char_traits<_element>>
typedef std::list<ThisType *> cmnLODMultiplexerStreambuf< _element, _trait >::MultiplexerContainerType

◆ MultiplexerIteratorType

template<class _element, class _trait = std::char_traits<_element>>
typedef MultiplexerContainerType::iterator cmnLODMultiplexerStreambuf< _element, _trait >::MultiplexerIteratorType

◆ ThisType

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

Constructor & Destructor Documentation

◆ cmnLODMultiplexerStreambuf() [1/2]

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
fileStreamDefault Filestream

◆ cmnLODMultiplexerStreambuf() [2/2]

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

Constructor: currently empty.

Member Function Documentation

◆ AddChannel() [1/2]

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::AddChannel ( ChannelType * channel,
cmnLogMask mask )

Add an output channel. See notes above.

Parameters
channelA pointer to the output channel to be added.
lodLevel 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.

◆ AddChannel() [2/2]

template<class _element, class _trait = std::char_traits<_element>>
bool cmnLODMultiplexerStreambuf< _element, _trait >::AddChannel ( std::ostream & outstream,
cmnLogMask mask )
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
outstreamOutput stream providing the rdbuf.
lodLevel of Detail for the stream.

◆ AddMultiplexer()

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::AddMultiplexer ( ThisType * multiplexer)

◆ FindChannel() [1/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::IteratorType cmnLODMultiplexerStreambuf< _element, _trait >::FindChannel ( const ChannelType * channel)
protected

Find a channel in the container and return the container's iterator for the element with that channel.

◆ FindChannel() [2/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::ConstIteratorType cmnLODMultiplexerStreambuf< _element, _trait >::FindChannel ( const ChannelType * channel) const
protected

Find a channel in the container and return the container's iterator for the element with that channel.

◆ FindMultiplexer() [1/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::MultiplexerIteratorType cmnLODMultiplexerStreambuf< _element, _trait >::FindMultiplexer ( const ThisType * multiplexer)
protected

Find a multiplexer in the container and return the container's iterator for the element with that multiplexer.

◆ FindMultiplexer() [2/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::MultiplexerConstIteratorType cmnLODMultiplexerStreambuf< _element, _trait >::FindMultiplexer ( const ThisType * multiplexer) const
protected

Find a multiplexer in the container and return the container's iterator for the element with that multiplexer.

◆ GetChannelMask()

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::GetChannelMask ( const ChannelType * channel,
cmnLogMask & mask ) const

Find the output LOD of a channel

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

◆ GetChannels()

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

◆ overflow() [1/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::int_type cmnLODMultiplexerStreambuf< _element, _trait >::overflow ( int_type c,
cmnLogLevel level )
protectedvirtual

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.

Reimplemented in mtsLODMultiplexerStreambuf.

◆ overflow() [2/2]

template<class _element, class _trait>
cmnLODMultiplexerStreambuf< _element, _trait >::int_type cmnLODMultiplexerStreambuf< _element, _trait >::overflow ( int_type c = _trait::eof())
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.

Reimplemented in mtsLODMultiplexerStreambuf.

◆ RemoveAllChannels()

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

Remove all output channels.

◆ RemoveChannel() [1/2]

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

Remove an output channel.

Parameters
channelA pointer to the output channel to be removed. No change occurs if the pointer is not on the list of channels for this multiplexer.

◆ RemoveChannel() [2/2]

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
outstreamOutput stream providing the rdbuf.

◆ RemoveMultiplexer()

template<class _element, class _trait>
void cmnLODMultiplexerStreambuf< _element, _trait >::RemoveMultiplexer ( ThisType * multiplexer)

◆ SetChannelMask()

template<class _element, class _trait>
bool cmnLODMultiplexerStreambuf< _element, _trait >::SetChannelMask ( ChannelType * channel,
cmnLogMask mask )

Set the output LOD of a channel

Parameters
channelA pointer to the output channel to be added.
lodLevel 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.

◆ sync()

template<class _element, class _trait>
int cmnLODMultiplexerStreambuf< _element, _trait >::sync ( void )
protectedvirtual

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

Reimplemented in mtsLODMultiplexerStreambuf.

◆ xsputn() [1/2]

template<class _element, class _trait>
std::streamsize cmnLODMultiplexerStreambuf< _element, _trait >::xsputn ( const _element * s,
std::streamsize n )
protectedvirtual

Override the basic_streambuf xsputn to do the multiplexing

Reimplemented in mtsLODMultiplexerStreambuf.

◆ xsputn() [2/2]

template<class _element, class _trait>
std::streamsize cmnLODMultiplexerStreambuf< _element, _trait >::xsputn ( const _element * s,
std::streamsize n,
cmnLogLevel level )
protectedvirtual

Multiplexed and LODed version of basic_streambuf xsputn.

Reimplemented in mtsLODMultiplexerStreambuf.

◆ cmnMultiplexerStreambufProxy< _element, _trait >

template<class _element, class _trait = std::char_traits<_element>>
friend class cmnMultiplexerStreambufProxy< _element, _trait >
friend

Member Data Documentation

◆ Channels

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

The actual container that stores channel addresses.

◆ Multiplexers

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

The actual container that stores multiplexers addresses.


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