Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

ucc::IOBuffer Class Reference

Common buffered I/O class. More...

#include <buffer.h>

Inheritance diagram for ucc::IOBuffer:
Inheritance graph
[legend]

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 (const 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 (const char *string)
 Put a string as a line of output to the buffer.
size_t putstr (const char *address, size_t count=0)
 Put memory into the buffer.
size_t read (String &string)
 Method to read a line of input from the buffer.
size_t read (char *address, size_t size)
 Method to read input data 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 (const char *address, size_t size)
 Method to write memory to the buffer.
size_t writeln (const char *string)
 Method to write a null terminated string.
size_t writes (const 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 (const 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 ()
 Construct an empty (unallocated) buffer.
 IOBuffer (size_t size, type_t access=BUF_RDWR)
 Construct a buffer of pre-allocated size and access type.
void release (void)
 Release (free) buffer memory.
char * request (size_t size)
 Request workspace in output buffer.
void seteol (const char *string)
 Set end of line marker.
 ~IOBuffer ()
 Destroy object by releasing buffer memory.

Protected Attributes

const char * format
int ioerror
timeout_t timeout

Detailed Description

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.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 54 of file buffer.h.


Constructor & Destructor Documentation

ucc::IOBuffer::IOBuffer ( size_t  size,
type_t  access = BUF_RDWR 
) [protected]

Construct a buffer of pre-allocated size and access type.

Parameters:
size of buffer to allocate.
access mode of buffer.

Member Function Documentation

size_t ucc::IOBuffer::_pending ( void   )  [inline, protected]

Get current input position.

Sometimes used to help compute and report a "tell" offset.

Returns:
offset of input buffer.

Definition at line 151 of file buffer.h.

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.

Parameters:
address of buffer to pull data into.
size of buffer area being pulled..
Returns:
number of read written, 0 on error or end of data.
virtual size_t ucc::IOBuffer::_push ( const 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.

Parameters:
address of data to push.
size of data to push.
Returns:
number of bytes written, 0 on error.
size_t ucc::IOBuffer::_waiting ( void   )  [inline, protected]

Get current output position.

Sometimes used to help compute a "trunc" operation.

Definition at line 158 of file buffer.h.

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.

Parameters:
size of buffer to allocate.
access mode of buffer.
bool ucc::IOBuffer::eof (  ) 

Check if at end of input.

Returns:
true if end of data, false if input still buffered.
int ucc::IOBuffer::err ( void   )  [inline]

Get last error associated with a failed operation.

Returns:
last error.

Definition at line 311 of file buffer.h.

virtual bool ucc::IOBuffer::flush ( void   )  [virtual]

Flush buffered memory to physical I/O.

Returns:
true on success, false if not active or fails.
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.

Parameters:
size of gather space.
Returns:
data pointer to gathered data or NULL if not available.
int ucc::IOBuffer::getch ( void   ) 

Get a character from the buffer.

If no data is available, return EOF.

Returns:
character from buffer or 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.

Parameters:
string to save input into.
size limit of string to save.
Returns:
count of characters read or 0 if at end of data.
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.

Parameters:
address of characters save from buffer.
count of characters to get from buffer.
Returns:
number of characters actually copied.
bool ucc::IOBuffer::isinput ( void   )  [inline]

See if input active.

Returns:
true if input active.

Definition at line 345 of file buffer.h.

bool ucc::IOBuffer::isopen ( void   )  [inline]

See if buffer open.

Returns:
true if buffer active.

Definition at line 338 of file buffer.h.

bool ucc::IOBuffer::isoutput ( void   )  [inline]

See if output active.

Returns:
true if output active.

Definition at line 352 of file buffer.h.

ucc::IOBuffer::operator bool (  )  [inline]

See if buffer open.

Returns:
true if buffer active.

Definition at line 324 of file buffer.h.

bool ucc::IOBuffer::operator! (  )  [inline]

See if buffer closed.

Returns:
true if buffer inactive.

Definition at line 331 of file buffer.h.

virtual bool ucc::IOBuffer::pending ( void   )  [virtual]

See if data is pending.

Returns:
true if data is pending.
size_t ucc::IOBuffer::printf ( const char *  format,
  ... 
)

Print formatted string to the buffer.

The maximum output size is the buffer size, and the operation flushes the buffer.

Parameters:
format string.
Returns:
number of bytes written.
int ucc::IOBuffer::putch ( int  ch  ) 

Put a character into the buffer.

Returns:
character put into buffer or eof.
size_t ucc::IOBuffer::putline ( const char *  string  ) 

Put a string as a line of output to the buffer.

The eol character is appended to the end.

Parameters:
string to write.
Returns:
total characters successfully written, including eol chars.
size_t ucc::IOBuffer::putstr ( const 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.

Parameters:
address of characters to put into buffer.
count of characters to put into buffer.
Returns:
number of characters actually written.
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.

Parameters:
string buffer to use.
Returns:
number of characters actually read.
size_t ucc::IOBuffer::read ( char *  address,
size_t  size 
) [inline]

Method to read input data from the buffer.

Parameters:
address of buffer to use.
size of buffer to request.
Returns:
number of characters actually read.

Definition at line 257 of file buffer.h.

size_t ucc::IOBuffer::readln ( char *  address,
size_t  size 
) [inline]

Method to read a line of input from the buffer.

This uses the current newline character sequence to mark the end of line input.

Parameters:
address of string buffer to use.
size of string buffer.
Returns:
number of characters actually read.

Definition at line 240 of file buffer.h.

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.

Parameters:
size of request area.
Returns:
data pointer or NULL if not available.
void ucc::IOBuffer::reset ( void   ) 

Reset input buffer state.

Drops any pending input.

void ucc::IOBuffer::seteol ( const 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().

Parameters:
string for eol for getline and putline.

Definition at line 95 of file buffer.h.

size_t ucc::IOBuffer::write ( const char *  address,
size_t  size 
) [inline]

Method to write memory to the buffer.

Parameters:
address of memory to write.
size of memory to write.
Returns:
number of character bytes written.

Definition at line 212 of file buffer.h.

size_t ucc::IOBuffer::write ( String string  )  [inline]

Method to write a string object.

This adds the current newline character sequence to the output.

Parameters:
string to write.
Returns:
number of characters actually written.

Definition at line 230 of file buffer.h.

size_t ucc::IOBuffer::writeln ( const char *  string  )  [inline]

Method to write a null terminated string.

This adds the current newline character sequence to the output.

Parameters:
string to write.
Returns:
number of characters actually written.

Definition at line 221 of file buffer.h.

size_t ucc::IOBuffer::writes ( const char *  string  )  [inline]

Method to write a null terminated string.

Parameters:
string to write.

Definition at line 203 of file buffer.h.


The documentation for this class was generated from the following file: