Wheefun I/O Library  0.0.5
Useful I/O Primitives.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
wfio::IOBuf Class Reference

A C++ wrapper for a wfio_iobuf_t. More...

#include <iobuf.h>

Public Types

typedef ::wfio_iobuf_tCType
 The C type from which an IOBuf is derived.
 
typedef ::wfio_iobuf_source_callback_t SourceCallback
 A callback used to implement a source operation.
 
typedef ::wfio_iobuf_sink_callback_t SinkCallback
 A callback used to implement a sink operation.
 

Public Member Functions

 IOBuf ()
 Construct the default IOBuf. More...
 
 IOBuf (::wfio_iobuf_t *buf, bool acquire=true)
 Wrap a wfio_iobuf_t. More...
 
 IOBuf (const IOBuf &buf)
 Copy-construct an IOBuf. More...
 
 IOBuf (size_t size, int *error=NULL)
 Construct a new exclusive buffer of length size. More...
 
 IOBuf (size_t read, size_t write, int *error=NULL)
 Construct a new split buffer. More...
 
 ~IOBuf ()
 Release this IOBuf. More...
 
int flags () const throw ()
 Obtain this IOBuf's flags.
 
size_t capacity () const throw ()
 Obtain this IOBuf's total capacity.
 
size_t facet () const throw ()
 Obtain the capacity of this IOBuf's current facet.
 
size_t avail () const throw ()
 The number of characters available for consumption in this IOBuf.
 
size_t remain () const throw ()
 Obtain the space remaining in the current facet of this buffer. More...
 
size_t remainElem (size_t sz) const throw ()
 Obtain the space remaining in the current facet of this buffer for elements of size sz. More...
 
size_t start () const throw ()
 Obtain the starting index for this IOBuf's current facet. More...
 
size_t end () const throw ()
 Obtain the end index for this IOBuf's current facet. More...
 
void * base () throw ()
 Obtain the base address of this IOBuf's current facet. More...
 
const void * base () const throw ()
 Obtain the base address of this IOBuf's current facet in a constant context. More...
 
size_t read (void *dest, size_t sz, size_t elem, int *error=NULL) throw ()
 Consume elements from this IOBuf. More...
 
size_t readbV (void *dest, size_t len, int *error=NULL) throw ()
 Consume bytes from this IOBuf. More...
 
int readb (int *error=NULL) throw ()
 Consume bytes from this IOBuf. More...
 
size_t write (const void *src, size_t sz, size_t elem, int *error=NULL) throw ()
 Emplace elements into this IOBuf. More...
 
size_t writebV (const void *src, size_t len, int *error=NULL) throw ()
 Emplace bytes into this IOBuf. More...
 
size_t writeb (char c, int *error=NULL) throw ()
 Emplace bytes into this IOBuf. More...
 
size_t source (size_t sz, size_t elem, void *src, SourceCallback cb, int *error=NULL) throw ()
 Source new elements into this IOBuf from src. More...
 
size_t fill (void *src, SourceCallback cb, int *error=NULL) throw ()
 Fill this IOBuf from src. More...
 
size_t sink (size_t sz, size_t elem, void *src, SinkCallback cb, int *error=NULL) throw ()
 Sink new elements from this IOBuf into dest. More...
 
size_t empty (void *src, SinkCallback cb, int *error=NULL) throw ()
 Empty this buffer into src. More...
 
bool flip (int *error=NULL) throw ()
 Flip this IOBuf. More...
 
bool notRead () const throw ()
 Whether or not this IOBuf is shared and not using the read facet. More...
 
bool notWrite () const throw ()
 Whether or not this IOBuf is shared and not using the write facet. More...
 
bool ensureRead (int *error=NULL) throw ()
 Ensure that this IOBuf is using the read buffer. More...
 
bool ensureWrite (int *error=NULL) throw ()
 Ensure that this IOBuf is using the write buffer. More...
 
bool forceReorganize (int *error=NULL) throw ()
 Force the reorganization of this IOBuf. More...
 
int clear (int *error=NULL) throw ()
 Clear the contents of this IOBuf's current facet. More...
 
bool valid () const throw ()
 Determine if this IOBuf is valid. More...
 
 operator bool () const
 Synonymous with this->valid(). More...
 
 operator::wfio_iobuf_t * ()
 Implicitly convert this IOBuf into it's C equivalent.
 
WFIO_CXX_DLL IOBufoperator= (const IOBuf &rhs)
 Perform assignment on this IOBuf. More...
 

Static Public Member Functions

static IOBuf allocShared (size_t capacity, int *error=NULL)
 Allocate a new shared IOBuf. More...
 

Detailed Description

A C++ wrapper for a wfio_iobuf_t.

Constructor & Destructor Documentation

◆ IOBuf() [1/5]

wfio::IOBuf::IOBuf ( )
inline

Construct the default IOBuf.

This constructor creates an invalid IOBuf.

◆ IOBuf() [2/5]

wfio::IOBuf::IOBuf ( ::wfio_iobuf_t buf,
bool  acquire = true 
)
inline

Wrap a wfio_iobuf_t.

Parameters
bufThe buffer to wrap.
acquireWhether or not the buffer should be acquired as a consequence of constructing this object.
Note
If you want to disown the previous ownership of buf from the context in which it is called, then acquire should be false.

◆ IOBuf() [3/5]

wfio::IOBuf::IOBuf ( const IOBuf buf)
inline

Copy-construct an IOBuf.

This method acquires the underlying buffer so that it is shared. The buffer provided by buf is then shared with this one.

Parameters
bufThe buffer to copy-construct.

◆ IOBuf() [4/5]

wfio::IOBuf::IOBuf ( size_t  size,
int *  error = NULL 
)
inline

Construct a new exclusive buffer of length size.

Parameters
sizeThe total number of bytes to allocate for this buffer.
errorAn optional error indicator.

◆ IOBuf() [5/5]

wfio::IOBuf::IOBuf ( size_t  read,
size_t  write,
int *  error = NULL 
)
inline

Construct a new split buffer.

Parameters
readThe size of the read facet of the new buffer.
writeThe size of the write facet of the new buffer.
errorAn optional error indicator.

◆ ~IOBuf()

wfio::IOBuf::~IOBuf ( )
inline

Release this IOBuf.

This method releases the underlying CType if this object is valid.

Member Function Documentation

◆ allocShared()

static IOBuf wfio::IOBuf::allocShared ( size_t  capacity,
int *  error = NULL 
)
inlinestatic

Allocate a new shared IOBuf.

Parameters
capacityThe shared capacity of the new buffer.
errorAn optional error indicator.
Returns
A valid IOBuf on success; otherwise, an invalid IOBuf.

◆ base() [1/2]

void* wfio::IOBuf::base ( )
throw (
)
inline

Obtain the base address of this IOBuf's current facet.

Returns
A mutable pointer to the memory where the data is stored.
Note
It is better to use read() or write() to manage this buffer rather than manage it directly.

◆ base() [2/2]

const void* wfio::IOBuf::base ( ) const
throw (
)
inline

Obtain the base address of this IOBuf's current facet in a constant context.

Returns
A constant pointer to the memory where the data is stored.
Note
It is better to use read() or write() to manage this buffer rather than manage it directly.

◆ clear()

int wfio::IOBuf::clear ( int *  error = NULL)
throw (
)
inline

Clear the contents of this IOBuf's current facet.

Parameters
errorAn optional error indicator.

◆ empty()

size_t wfio::IOBuf::empty ( void *  src,
SinkCallback  cb,
int *  error = NULL 
)
throw (
)
inline

Empty this buffer into src.

Parameters
destThe source object to write to.
cbThe callback to invoke on writing.
errorAn optional error indicator.
Returns
sz The total number of bytes written into this IOBuf on success; otherwise, WFIO_NPOS.

◆ end()

size_t wfio::IOBuf::end ( ) const
throw (
)
inline

Obtain the end index for this IOBuf's current facet.

Returns
The index in the current facet where available data ends.
Note
It is better to use read() or write() to manage this buffer rather than manage it directly.

◆ ensureRead()

bool wfio::IOBuf::ensureRead ( int *  error = NULL)
throw (
)
inline

Ensure that this IOBuf is using the read buffer.

Parameters
errorAn optional error indicator.
Returns
Nonzero iff the read buffer is now active; otherwise, zero.

◆ ensureWrite()

bool wfio::IOBuf::ensureWrite ( int *  error = NULL)
throw (
)
inline

Ensure that this IOBuf is using the write buffer.

Parameters
errorAn optional error indicator.
Returns
Nonzero iff the write buffer is now active; otherwise, zero.

◆ fill()

size_t wfio::IOBuf::fill ( void *  src,
SourceCallback  cb,
int *  error = NULL 
)
throw (
)
inline

Fill this IOBuf from src.

Parameters
srcThe source object to read from.
cbThe callback to invoke on reading.
errorAn optional error indicator.
Returns
sz The total number of bytes read into this IOBUF on success; otherwise, WFIO_NPOS.

◆ flip()

bool wfio::IOBuf::flip ( int *  error = NULL)
throw (
)
inline

Flip this IOBuf.

This does nothing for an unshared buffer; otherwise, this function swaps the current facet in use by the buffer.

Parameters
errorAn optional error indicator.
Returns
True iff the buffer was successfully flipped.

◆ forceReorganize()

bool wfio::IOBuf::forceReorganize ( int *  error = NULL)
throw (
)
inline

Force the reorganization of this IOBuf.

Parameters
errorAn optional error indicator.
Returns
True iff reorganization was successful.

◆ notRead()

bool wfio::IOBuf::notRead ( ) const
throw (
)
inline

Whether or not this IOBuf is shared and not using the read facet.

Returns
Whether or not the write buffer is currently in use.

◆ notWrite()

bool wfio::IOBuf::notWrite ( ) const
throw (
)
inline

Whether or not this IOBuf is shared and not using the write facet.

Returns
Whether or not the read buffer is currently in use.

◆ operator bool()

wfio::IOBuf::operator bool ( ) const
inline

Synonymous with this->valid().

Returns
True if this object is valid.

◆ operator=()

WFIO_CXX_DLL IOBuf& wfio::IOBuf::operator= ( const IOBuf rhs)

Perform assignment on this IOBuf.

Parameters
rhsThe IOBuf to assign to this one.

If rhs does not refer to the same CType as this one, then the current CType is released, rhs's CType is acquired. Thereafter, this IOBuf shall refer to the same CType as rhs,

Returns
This device.

◆ read()

size_t wfio::IOBuf::read ( void *  dest,
size_t  sz,
size_t  elem,
int *  error = NULL 
)
throw (
)
inline

Consume elements from this IOBuf.

Parameters
destThe data into which te IOBuf will read.
szThe size of each element.
elemThe maximum number of elements to read.
errorAn optional error indicator.
Returns
The number of elements read on success; otherwise, WFIO_NPOS.

◆ readb()

int wfio::IOBuf::readb ( int *  error = NULL)
throw (
)
inline

Consume bytes from this IOBuf.

Parameters
destThe data into which te IOBuf will read.
errorAn optional error indicator.
Returns
The number of bytes read on success; otherwise, WFIO_NPOS.

◆ readbV()

size_t wfio::IOBuf::readbV ( void *  dest,
size_t  len,
int *  error = NULL 
)
throw (
)
inline

Consume bytes from this IOBuf.

Parameters
destThe data into which te IOBuf will read.
lenThe number of bytes to read.
errorAn optional error indicator.
Returns
The number of bytes read on success; otherwise, WFIO_NPOS.

◆ remain()

size_t wfio::IOBuf::remain ( ) const
throw (
)
inline

Obtain the space remaining in the current facet of this buffer.

Parameters
Thenumber of bytes which may be placed in the current facet in this buffer.

◆ remainElem()

size_t wfio::IOBuf::remainElem ( size_t  sz) const
throw (
)
inline

Obtain the space remaining in the current facet of this buffer for elements of size sz.

Parameters
szThe size of the element to scale the count to.
Returns
The number of elements which may be placed in the current facet for buffer.

◆ sink()

size_t wfio::IOBuf::sink ( size_t  sz,
size_t  elem,
void *  src,
SinkCallback  cb,
int *  error = NULL 
)
throw (
)
inline

Sink new elements from this IOBuf into dest.

Parameters
szThe size of each element.
elemThe number of elements to write out.
destThe source object to write to.
cbThe callback to invoke on writing.
errorAn optional error indicator.
Returns
sz The total number of bytes written into this IOBuf on success; otherwise, WFIO_NPOS.

◆ source()

size_t wfio::IOBuf::source ( size_t  sz,
size_t  elem,
void *  src,
SourceCallback  cb,
int *  error = NULL 
)
throw (
)
inline

Source new elements into this IOBuf from src.

Parameters
szThe size of each element.
elemThe number of elements to read in.
srcThe source object to read from.
cbThe callback to invoke on reading.
errorAn optional error indicator.
Returns
sz The total number of bytes read into this IOBuf on success; otherwise, WFIO_NPOS.

◆ start()

size_t wfio::IOBuf::start ( ) const
throw (
)
inline

Obtain the starting index for this IOBuf's current facet.

Returns
The index in the current facet where available data starts.
Note
It is better to use read() or write() to manage this buffer rather than manage it directly.

◆ valid()

bool wfio::IOBuf::valid ( ) const
throw (
)
inline

Determine if this IOBuf is valid.

This function determines whether or not this IOBuf can be operated on. It is valid iff its underlying pointer is not null.

Returns
True if this object is valid.

◆ write()

size_t wfio::IOBuf::write ( const void *  src,
size_t  sz,
size_t  elem,
int *  error = NULL 
)
throw (
)
inline

Emplace elements into this IOBuf.

Parameters
srcThe data from which to populate this IOBuf.
szThe size of each element.
elemThe maximum number of elements to write.
errorAn optional error indicator.
Returns
The number of elements written on success; otherwise, WFIO_NPOS.

◆ writeb()

size_t wfio::IOBuf::writeb ( char  c,
int *  error = NULL 
)
throw (
)
inline

Emplace bytes into this IOBuf.

Parameters
srcThe data from which to populate this IOBuf.
errorAn optional error indicator.
Returns
The number of bytes written on success; otherwise, WFIO_NPOS.

◆ writebV()

size_t wfio::IOBuf::writebV ( const void *  src,
size_t  len,
int *  error = NULL 
)
throw (
)
inline

Emplace bytes into this IOBuf.

Parameters
srcThe data from which to populate this IOBuf.
lenThe maximum number of bytes to write.
errorAn optional error indicator.
Returns
The number of bytes written on success; otherwise, WFIO_NPOS.

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