Common buffered I/O class. More...
#include <buffer.h>
Public Types | |
enum | type_t { BUF_RD, BUF_WR, BUF_RDWR } |
Public Member Functions | |
void | clear (void) |
Clear last error state. | |
bool | eof () |
Check if at end of input. | |
int | err (void) |
Get last error associated with a failed operation. | |
virtual bool | flush (void) |
Flush buffered memory to physical I/O. | |
int | getch (void) |
Get a character from the buffer. | |
size_t | getline (char *string, size_t size) |
Get a string as a line of input from the buffer. | |
size_t | getstr (char *address, size_t count) |
Get memory from the buffer. | |
bool | isinput (void) |
See if input active. | |
bool | isopen (void) |
See if buffer open. | |
bool | isoutput (void) |
See if output active. | |
operator bool () | |
See if buffer open. | |
bool | operator! () |
See if buffer closed. | |
virtual bool | pending (void) |
See if data is pending. | |
size_t | printf (char *format,...) |
Print formatted string to the buffer. | |
void | purge (void) |
Purge any pending input or output buffer data. | |
int | putch (int ch) |
Put a character into the buffer. | |
size_t | putline (char *string) |
Put a string as a line of output to the buffer. | |
size_t | putstr (char *address, size_t count=0) |
Put memory into the buffer. | |
size_t | read (char *address, size_t size) |
Method to read input data from the buffer. | |
size_t | read (String &string) |
Method to read a line of input from the buffer. | |
size_t | readln (char *address, size_t size) |
Method to read a line of input from the buffer. | |
void | reset (void) |
Reset input buffer state. | |
void | seteof (void) |
Set eof flag. | |
size_t | write (String &string) |
Method to write a string object. | |
size_t | write (char *address, size_t size) |
Method to write memory to the buffer. | |
size_t | writeln (char *string) |
Method to write a null terminated string. | |
size_t | writes (char *string) |
Method to write a null terminated string. | |
Protected Member Functions | |
size_t | _buffering (void) |
Get size of the I/O buffer. | |
size_t | _pending (void) |
Get current input position. | |
virtual size_t | _pull (char *address, size_t size) |
Method to pull buffer from physical i/o (read). | |
virtual size_t | _push (char *address, size_t size) |
Method to push buffer into physical i/o (write). | |
size_t | _waiting (void) |
Get current output position. | |
void | allocate (size_t size, type_t access=BUF_RDWR) |
Allocate I/O buffer(s) of specified size. | |
char * | gather (size_t size) |
Gather returns a pointer to contigues input of specified size. | |
IOBuffer (size_t size, type_t access=BUF_RDWR) | |
Construct a buffer of pre-allocated size and access type. | |
IOBuffer () | |
Construct an empty (unallocated) buffer. | |
void | release (void) |
Release (free) buffer memory. | |
char * | request (size_t size) |
Request workspace in output buffer. | |
void | seteol (char *string) |
Set end of line marker. | |
~IOBuffer () | |
Destroy object by releasing buffer memory. | |
Protected Attributes | |
char * | format |
int | ioerror |
timeout_t | timeout |
Common buffered I/O class.
This is used to create objects which will stream character data as needed. This class can support bidrectionalal 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 54 of file buffer.h.
ucc::IOBuffer::IOBuffer | ( | size_t | size, | |
type_t | access = BUF_RDWR | |||
) | [protected] |
Construct a buffer of pre-allocated size and access type.
size | of buffer to allocate. | |
access | mode of buffer. |
size_t ucc::IOBuffer::_pending | ( | void | ) | [inline, protected] |
virtual size_t ucc::IOBuffer::_pull | ( | char * | address, | |
size_t | size | |||
) | [protected, 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.. |
Reimplemented in ucc::fbuf, ucc::TCPSocket, ucc::SSocket, and ucc::shell::iobuf.
virtual size_t ucc::IOBuffer::_push | ( | char * | address, | |
size_t | size | |||
) | [protected, 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. |
Reimplemented in ucc::fbuf, ucc::TCPSocket, ucc::SSocket, and ucc::shell::iobuf.
size_t ucc::IOBuffer::_waiting | ( | void | ) | [inline, protected] |
void ucc::IOBuffer::allocate | ( | size_t | size, | |
type_t | access = BUF_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 ucc::IOBuffer::eof | ( | ) |
Check if at end of input.
int ucc::IOBuffer::err | ( | void | ) | [inline] |
virtual bool ucc::IOBuffer::flush | ( | void | ) | [virtual] |
Flush buffered memory to physical I/O.
Reimplemented in ucc::SSocket.
char* ucc::IOBuffer::gather | ( | size_t | size | ) | [protected] |
Gather returns a pointer to contigues input of specified size.
This may require moving the input data in memory.
size | of gather space. |
int ucc::IOBuffer::getch | ( | void | ) |
Get a character from the buffer.
If no data is available, return EOF.
size_t ucc::IOBuffer::getline | ( | char * | string, | |
size_t | size | |||
) |
Get a string as a line of input from the buffer.
The eol character(s) are used to mark the end of a line.
string | to save input into. | |
size | limit of string to save. |
size_t ucc::IOBuffer::getstr | ( | char * | address, | |
size_t | count | |||
) |
Get memory from the buffer.
This method will become "get()" in abi 4 and may become a protected method.
address | of characters save from buffer. | |
count | of characters to get from buffer. |
bool ucc::IOBuffer::isinput | ( | void | ) | [inline] |
bool ucc::IOBuffer::isopen | ( | void | ) | [inline] |
bool ucc::IOBuffer::isoutput | ( | void | ) | [inline] |
ucc::IOBuffer::operator bool | ( | ) | [inline] |
bool ucc::IOBuffer::operator! | ( | ) | [inline] |
virtual bool ucc::IOBuffer::pending | ( | void | ) | [virtual] |
See if data is pending.
Reimplemented in ucc::TCPSocket, and ucc::SSocket.
size_t ucc::IOBuffer::printf | ( | char * | format, | |
... | ||||
) |
Print formatted string to the buffer.
The maximum output size is the buffer size, and the operation flushes the buffer.
format | string. |
int ucc::IOBuffer::putch | ( | int | ch | ) |
Put a character into the buffer.
size_t ucc::IOBuffer::putline | ( | char * | string | ) |
Put a string as a line of output to the buffer.
The eol character is appended to the end.
string | to write. |
size_t ucc::IOBuffer::putstr | ( | char * | address, | |
size_t | count = 0 | |||
) |
Put memory into the buffer.
If count is 0 then put as NULL terminated string. This method will become "put()" in abi 4 and may become a protected method.
address | of characters to put into buffer. | |
count | of characters to put into buffer. |
size_t ucc::IOBuffer::read | ( | char * | address, | |
size_t | size | |||
) | [inline] |
size_t ucc::IOBuffer::read | ( | String & | string | ) |
Method to read a line of input from the buffer.
This saves the result into an already allocated string object.
string | buffer to use. |
size_t ucc::IOBuffer::readln | ( | char * | address, | |
size_t | size | |||
) | [inline] |
char* ucc::IOBuffer::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 ucc::IOBuffer::reset | ( | void | ) |
Reset input buffer state.
Drops any pending input.
void ucc::IOBuffer::seteol | ( | char * | string | ) | [inline, protected] |
Set end of line marker.
Normally this is set to cr & lf, which actually supports both lf alone and cr/lf termination of lines. However, putline() will always add the full cr/lf if this mode is used. This option only effects getline() and putline().
string | for eol for getline and putline. |
size_t ucc::IOBuffer::write | ( | String & | string | ) | [inline] |
size_t ucc::IOBuffer::write | ( | char * | address, | |
size_t | size | |||
) | [inline] |
size_t ucc::IOBuffer::writeln | ( | char * | string | ) | [inline] |
size_t ucc::IOBuffer::writes | ( | char * | string | ) | [inline] |