| cisst-saw
    | 
A Streambuffer class that outputs via a callback function. More...
#include <cmnCallbackStreambuf.h>
 
  
 | Public Types | |
| typedef std::basic_streambuf < _element, _trait >::int_type | int_type | 
| typedef _element | ElementType | 
| typedef void(* | CallbackType )(const ElementType *, int len) | 
| Public Member Functions | |
| cmnCallbackStreambuf (CallbackType func) | |
| Protected Member Functions | |
| virtual void | PrintLine () | 
| virtual int_type | overflow (int_type c) | 
| virtual std::streamsize | xsputn (const ElementType *s, std::streamsize n) | 
| virtual int | sync () | 
| Protected Attributes | |
| ElementType | Buffer [256] | 
| unsigned int | Idx | 
| CallbackType | Callback | 
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:
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.
| typedef void(* cmnCallbackStreambuf< _element, _trait >::CallbackType)(const ElementType *, int len) | 
Type of the callback function, e.g., void func(char *line, int len).
| typedef _element cmnCallbackStreambuf< _element, _trait >::ElementType | 
Type of the array, e.g., char.
| typedef std::basic_streambuf<_element, _trait>::int_type cmnCallbackStreambuf< _element, _trait >::int_type | 
| 
 | inline | 
Constructor: Sets the callback function.
| func | The callback function. | 
| 
 | inlineprotectedvirtual | 
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.
| 
 | inlineprotectedvirtual | 
Protected function to print the buffer (call the callback function).
| 
 | inlineprotectedvirtual | 
Override the basic_streambuf sync to flush (print) the buffer.
| 
 | inlineprotectedvirtual | 
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.
| 
 | protected | 
| 
 | protected | 
| 
 | protected | 
 1.8.6
 1.8.6