#include <cmnCallbackStreambuf.h>
Inheritance diagram for cmnCallbackStreambuf< _element, _trait >:


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.
Definition at line 66 of file cmnCallbackStreambuf.h.
| typedef _element cmnCallbackStreambuf< _element, _trait >::ElementType |
Type of the array, e.g., char.
Definition at line 71 of file cmnCallbackStreambuf.h.
| 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.
| cmnCallbackStreambuf< _element, _trait >::cmnCallbackStreambuf | ( | CallbackType | func | ) | [inline] |
Constructor: Sets the callback function.
| func | The callback function. |
Definition at line 80 of file cmnCallbackStreambuf.h.
| 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().
| 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().
| 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().
| 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().