ERC CISST - cisst software

cmnCallbackStreambuf< _element, _trait > Class Template Reference

#include <cmnCallbackStreambuf.h>

Inheritance diagram for cmnCallbackStreambuf< _element, _trait >:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

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

A Streambuffer class that outputs via a callback function.

This file declares *class cmnCallbackStreambuf*. It is a templated class derived from the standard library's basic_streambuf, with the additional feature that it outputs to a user-specified callback function. This is implemented by overriding the basic_streambuf output functions xsputn(), overflow() and sync().

Usage: Include the module in your application with: #include <cisstCommon/cmnCallbackStreambuf.h>

Specify the callback function in the constructor. Note that the callback function should accept two parameters:

  1. an array of elements to be printed (e.g., a character array)
  2. the number of elements to be printed

The callback function is invoked when a newline character is encountered or when the internal buffer is full.

This class could be used, for example, to redirect *cmnLogger* output to a GUI text window, assuming that the GUI text window provides a "WriteText" function. This class would not be needed, however, if the GUI text window is derived from the streambuf class.

Note: It is not clear whether the comparison to '
' (for the newline) will work if ElementType is not a char.

See also:
C++ manual on basic_ostream and basic_streambuf.

Definition at line 66 of file cmnCallbackStreambuf.h.

Public Types

Public Member Functions

Protected Member Functions

Protected Attributes


Member Typedef Documentation

template<class _element, class _trait = std::char_traits<_element>>
typedef _element cmnCallbackStreambuf< _element, _trait >::ElementType

Type of the array, e.g., char.

Definition at line 71 of file cmnCallbackStreambuf.h.

template<class _element, class _trait = std::char_traits<_element>>
typedef void(*) cmnCallbackStreambuf< _element, _trait >::CallbackType(const ElementType *, int len)

Type of the callback function, e.g., void func(char *line, int len).

Definition at line 73 of file cmnCallbackStreambuf.h.


Constructor & Destructor Documentation

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

Constructor: Sets the callback function.

Parameters:
func The callback function.

Definition at line 80 of file cmnCallbackStreambuf.h.


Member Function Documentation

template<class _element, class _trait = std::char_traits<_element>>
virtual void cmnCallbackStreambuf< _element, _trait >::PrintLine (  )  [inline, protected, virtual]

Protected function to print the buffer (call the callback function).

Definition at line 89 of file cmnCallbackStreambuf.h.

References cmnCallbackStreambuf< _element, _trait >::Buffer, cmnCallbackStreambuf< _element, _trait >::Callback, and cmnCallbackStreambuf< _element, _trait >::Idx.

Referenced by cmnCallbackStreambuf< _element, _trait >::overflow(), cmnCallbackStreambuf< _element, _trait >::sync(), and cmnCallbackStreambuf< _element, _trait >::xsputn().

template<class _element, class _trait = std::char_traits<_element>>
virtual int_type cmnCallbackStreambuf< _element, _trait >::overflow ( int_type  c  )  [inline, protected, virtual]

Override the basic_streambuf overflow to store the character in the buffer. The buffer is printed if the character is a newline or if it is full.

Definition at line 93 of file cmnCallbackStreambuf.h.

References cmnCallbackStreambuf< _element, _trait >::Buffer, cmnCallbackStreambuf< _element, _trait >::Idx, and cmnCallbackStreambuf< _element, _trait >::PrintLine().

template<class _element, class _trait = std::char_traits<_element>>
virtual std::streamsize cmnCallbackStreambuf< _element, _trait >::xsputn ( const ElementType s,
std::streamsize  n 
) [inline, protected, virtual]

Override the basic_streambuf xsputn to store the characters in the buffer. The buffer is printed every time a newline is encountered or the buffer becomes full.

Definition at line 113 of file cmnCallbackStreambuf.h.

References cmnCallbackStreambuf< _element, _trait >::Buffer, cmnCallbackStreambuf< _element, _trait >::Idx, and cmnCallbackStreambuf< _element, _trait >::PrintLine().

template<class _element, class _trait = std::char_traits<_element>>
virtual int cmnCallbackStreambuf< _element, _trait >::sync ( void   )  [inline, protected, virtual]

Override the basic_streambuf sync to flush (print) the buffer.

Definition at line 136 of file cmnCallbackStreambuf.h.

References cmnCallbackStreambuf< _element, _trait >::Idx, and cmnCallbackStreambuf< _element, _trait >::PrintLine().


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