cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | List of all members
cmnMultiplexerStreambufProxy< _element, _trait > Class Template Reference

Types for dynamic control of output messages. More...

#include <cmnForwardDeclarations.h>

Inheritance diagram for cmnMultiplexerStreambufProxy< _element, _trait >:

Public Types

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

Public Member Functions

 cmnMultiplexerStreambufProxy (ChannelType *output, cmnLogLevel level)
 
cmnLogLevel GetLOD (void) const
 
void SetLOD (cmnLogLevel level)
 
ChannelTypeGetOutput (void) const
 

Protected Member Functions

virtual std::streamsize xsputn (const _element *s, std::streamsize n)
 
virtual int sync (void)
 
virtual int_type overflow (int_type c=_trait::eof())
 

Detailed Description

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

Types for dynamic control of output messages.

This includes debugging information, error reporting, state logging etc. This file declares class cmnMultiplexerStreambufProxy. It is a templated class derived from the standard library's basic_streambuf. But is stores a Level Of Detail (LOD) descriptor that applies to each message that's output through it. The LOD descriptor is transferred to a cmnLODMultiplexerStreambuf object, that stores a list of LODed output channels, and decides which ones will be actually used. The proxy is implemented by overriding basic_streambuf output functions xsputn(), overflow() and sync().

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

Attach a cmnMultiplexerStreambufProxy object with an ostream. The output functions << , put(), write() etc will operate directly on the cmnMultiplexerStreambufProxy.

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_ALLOW_DEFAULT);
lodMultiplexerStreambuf.AddChannel(windowoutputstream.rdbuf(), CMN_LOG_ALLOW_ERRORS);
cmnLODMultiplexer multiplexerOutput(&lodMultiplexetStreambuf, CMN_LOG_LEVEL_INIT_DEBUG);
multiplexerStreambuf << "Hello, world" << endl; // channel the message only to 'log'

Notes:

  1. It is assumed that none of the output channels modifies the data arguments.
  2. cmnMultiplexerStreambufProxy 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 and cmnLODMultiplexerStreambuf.h

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<class _element, class _trait = std::char_traits<_element>>
cmnMultiplexerStreambufProxy< _element, _trait >::cmnMultiplexerStreambufProxy ( ChannelType output,
cmnLogLevel  level 
)
inline

Constructor: initialize the true output multiplexer and the current LOD.

Member Function Documentation

template<class _element, class _trait = std::char_traits<_element>>
cmnLogLevel cmnMultiplexerStreambufProxy< _element, _trait >::GetLOD ( void  ) const
inline

Returns the Level of Detail.

template<class _element, class _trait = std::char_traits<_element>>
ChannelType* cmnMultiplexerStreambufProxy< _element, _trait >::GetOutput ( void  ) const
inline

Returns a pointer to the output multiplexer.

template<class _element , class _trait >
cmnMultiplexerStreambufProxy< _element, _trait >::int_type cmnMultiplexerStreambufProxy< _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.

template<class _element, class _trait = std::char_traits<_element>>
void cmnMultiplexerStreambufProxy< _element, _trait >::SetLOD ( cmnLogLevel  level)
inline

Sets the Level of Detail.

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

Override the basic_streambuf sync for multiplexing.

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

Override the basic_streambuf xsputn to do the multiplexing.


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