ucommon
|
Common buffer protocol class. More...
#include <protocols.h>
Public Types | |
enum | mode_t { RDONLY, WRONLY, RDWR } |
Public Member Functions | |
const char * | endl (void) |
bool | eof (void) |
Check if at end of input. | |
int | err (void) |
bool | flush (void) |
Flush buffered memory to physical I/O. | |
size_t | get (void *address, size_t count) |
Get memory from the buffer. | |
bool | is_input (void) |
See if input active. | |
bool | is_open (void) |
See if buffer open. | |
bool | is_output (void) |
See if output active. | |
bool | is_pending (void) |
See if pending input. | |
operator bool () | |
See if buffer open. | |
bool | operator! () |
See if buffer closed. | |
size_t | printf (const char *format,...) |
Print formatted string to the buffer. | |
void | purge (void) |
Purge any pending input or output buffer data. | |
size_t | put (const void *address, size_t count) |
Put memory into the buffer. | |
template<typename T > | |
size_t | read (T &data) |
template<typename T > | |
size_t | read (T *data, unsigned count) |
void | reset (void) |
Reset input buffer state. | |
void | seteof (void) |
Set eof flag. | |
template<typename T > | |
size_t | write (const T &data) |
template<typename T > | |
size_t | write (const T *data, unsigned count) |
Protected Member Functions | |
virtual bool | _blocking (void) |
Return true if blocking. | |
virtual void | _clear (void)=0 |
Method to clear low level i/o error. | |
virtual int | _err (void) const =0 |
Method to get low level i/o error. | |
virtual bool | _flush (void) |
Flush buffer to physical i/o. | |
virtual int | _getch (void) |
Get the next character. | |
virtual bool | _pending (void) |
Check if data is pending. | |
virtual size_t | _pull (char *address, size_t size)=0 |
Method to pull buffer from physical i/o (read). | |
virtual size_t | _push (const char *address, size_t size)=0 |
Method to push buffer into physical i/o (write). | |
virtual int | _putch (int ch) |
Put the next character. | |
void | allocate (size_t size, mode_t access=RDWR) |
Allocate I/O buffer(s) of specified size. | |
BufferProtocol () | |
Construct an empty (unallocated) buffer. | |
BufferProtocol (size_t size, mode_t access=RDWR) | |
Construct a buffer of pre-allocated size and access type. | |
virtual void | fault (void) const |
Allocation error handler. | |
char * | gather (size_t size) |
Gather returns a pointer to contiguous input of specified size. | |
size_t | input_pending (void) |
Get current input position. | |
size_t | output_waiting (void) |
Get current output position. | |
void | release (void) |
Release (free) buffer memory. | |
char * | request (size_t size) |
Request workspace in output buffer. | |
virtual | ~BufferProtocol () |
Destroy object by releasing buffer memory. | |
Protected Attributes | |
const char * | format |
Common buffer protocol class.
This is used to create objects which will stream character data as needed. This class can support bidirectional streaming as may be needed for serial devices, sockets, and pipes. The buffering mechanisms are hidden from derived classes, and two virtuals are used to communicate with the physical transport.
Definition at line 291 of file protocols.h.
ucommon::BufferProtocol::BufferProtocol | ( | size_t | size, |
mode_t | access = RDWR |
||
) | [protected] |
Construct a buffer of pre-allocated size and access type.
size | of buffer to allocate. |
access | mode of buffer. |
virtual int ucommon::BufferProtocol::_err | ( | void | ) | const [protected, pure virtual] |
Method to get low level i/o error.
Implemented in ucommon::TCPBuffer.
virtual int ucommon::BufferProtocol::_getch | ( | void | ) | [protected, virtual] |
virtual size_t ucommon::BufferProtocol::_pull | ( | char * | address, |
size_t | size | ||
) | [protected, pure virtual] |
Method to pull buffer from physical i/o (read).
The address is passed to this virtual since it is hidden as private.
address | of buffer to pull data into. |
size | of buffer area being pulled.. |
Implemented in ucommon::SSLBuffer, and ucommon::TCPBuffer.
virtual size_t ucommon::BufferProtocol::_push | ( | const char * | address, |
size_t | size | ||
) | [protected, pure virtual] |
Method to push buffer into physical i/o (write).
The address is passed to this virtual since it is hidden as private.
address | of data to push. |
size | of data to push. |
Implemented in ucommon::SSLBuffer, and ucommon::TCPBuffer.
virtual int ucommon::BufferProtocol::_putch | ( | int | code | ) | [protected, virtual] |
Put the next character.
code | to put. |
Implements ucommon::CharacterProtocol.
void ucommon::BufferProtocol::allocate | ( | size_t | size, |
mode_t | access = RDWR |
||
) | [protected] |
Allocate I/O buffer(s) of specified size.
If a buffer is currently allocated, it is released.
size | of buffer to allocate. |
access | mode of buffer. |
bool ucommon::BufferProtocol::eof | ( | void | ) |
Check if at end of input.
bool ucommon::BufferProtocol::flush | ( | void | ) | [inline] |
Flush buffered memory to physical I/O.
Definition at line 453 of file protocols.h.
char* ucommon::BufferProtocol::gather | ( | size_t | size | ) | [protected] |
Gather returns a pointer to contiguous input of specified size.
This may require moving the input data in memory.
size | of gather space. |
size_t ucommon::BufferProtocol::get | ( | void * | address, |
size_t | count | ||
) |
Get memory from the buffer.
address | of characters save from buffer. |
count | of characters to get from buffer. |
size_t ucommon::BufferProtocol::input_pending | ( | void | ) | [inline, protected] |
Get current input position.
Sometimes used to help compute and report a "tell" offset.
Definition at line 410 of file protocols.h.
bool ucommon::BufferProtocol::is_input | ( | void | ) | [inline] |
bool ucommon::BufferProtocol::is_open | ( | void | ) | [inline] |
bool ucommon::BufferProtocol::is_output | ( | void | ) | [inline] |
bool ucommon::BufferProtocol::is_pending | ( | void | ) | [inline] |
ucommon::BufferProtocol::operator bool | ( | ) | [inline] |
bool ucommon::BufferProtocol::operator! | ( | ) | [inline] |
size_t ucommon::BufferProtocol::output_waiting | ( | void | ) | [inline, protected] |
Get current output position.
Sometimes used to help compute a "trunc" operation.
Definition at line 417 of file protocols.h.
size_t ucommon::BufferProtocol::printf | ( | const char * | format, |
... | |||
) |
Print formatted string to the buffer.
The maximum output size is the buffer size, and the operation flushes the buffer.
format | string. |
size_t ucommon::BufferProtocol::put | ( | const void * | address, |
size_t | count | ||
) |
Put memory into the buffer.
If count is 0 then put as NULL terminated string.
address | of characters to put into buffer. |
count | of characters to put into buffer. |
char* ucommon::BufferProtocol::request | ( | size_t | size | ) | [protected] |
Request workspace in output buffer.
This returns a pointer to memory from the output buffer and advances the output position. This is sometimes used for a form of zero copy write.
size | of request area. |
void ucommon::BufferProtocol::reset | ( | void | ) |
Reset input buffer state.
Drops any pending input.