#include <wvbufbase.h>
Inherited by WvBufBase< T >.
Collaboration diagram for WvBufBaseCommonImpl< T >:
Buffers are simple data queues designed to ease the construction of functions that must generate, consume, or transform large amount of data in pipeline fashion. Concrete buffer subclases define the actual storage mechanism and queuing machinery. In addition they may provide additional functionality for accomplishing particular tasks.
The base component is split into two parts, WvBufBaseCommonImpl that defines the common API for all buffer types, and WvBufBase that allows specializations to be defined to add functionality to the base type. When passing around buffer objects, you should use the WvBufBase<T> type rather than WvBufBaseCommonImpl<T>.
See WvBufBase<T> "T" is the type of object to store, must be a primitive or a struct without special initialization, copy, or assignment semantics
Definition at line 36 of file wvbufbase.h.
Public Member Functions | |
virtual | ~WvBufBaseCommonImpl () |
Destroys the buffer. | |
WvBufStore * | getstore () |
Returns a pointer to the underlying storage class object. | |
bool | isreadable () const |
Returns true if the buffer supports reading. | |
size_t | used () const |
Returns the number of elements in the buffer currently available for reading. | |
const T * | get (size_t count) |
Reads exactly the specified number of elements and returns a pointer to a storage location owned by the buffer. | |
void | skip (size_t count) |
Skips exactly the specified number of elements. | |
size_t | optgettable () const |
Returns the optimal maximum number of elements in the buffer currently available for reading without incurring significant overhead. | |
void | unget (size_t count) |
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads. | |
size_t | ungettable () const |
Returns the maximum number of elements that may be ungotten at this time. | |
const T * | peek (int offset, size_t count) |
Returns a const pointer into the buffer at the specified offset to the specified number of elements without actually adjusting the current get() index. | |
size_t | peekable (int offset) |
size_t | optpeekable (int offset) |
void | zap () |
Clears the buffer. | |
T | get () |
Reads the next element from the buffer. | |
T | peek (int offset=0) |
Returns the element at the specified offset in the buffer. | |
void | move (T *buf, size_t count) |
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED storage location and removes the elements from the buffer. | |
void | copy (T *buf, int offset, size_t count) |
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED storage location but does not remove the elements from the buffer. | |
bool | iswritable () const |
Returns true if the buffer supports writing. | |
size_t | free () const |
Returns the number of elements that the buffer can currently accept for writing. | |
T * | alloc (size_t count) |
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage location owned by the buffer. | |
size_t | optallocable () const |
Returns the optimal maximum number of elements that the buffer can currently accept for writing without incurring significant overhead. | |
void | unalloc (size_t count) |
Unallocates exactly the specified number of elements by removing them from the buffer and releasing their storage. | |
size_t | unallocable () const |
Returns the maximum number of elements that may be unallocated at this time. | |
T * | mutablepeek (int offset, size_t count) |
Returns a non-const pointer info the buffer at the specified offset to the specified number of elements without actually adjusting the current get() index. | |
void | put (const T *data, size_t count) |
Writes the specified number of elements from the specified storage location into the buffer at its tail. | |
void | poke (const T *data, int offset, size_t count) |
Efficiently copies the specified number of elements from the specified storage location into the buffer at a particular offset. | |
void | put (T &value) |
Writes the element into the buffer at its tail. | |
void | poke (T &value, int offset) |
Writes the element into the buffer at the specified offset. | |
void | merge (Buffer &inbuf, size_t count) |
Efficiently moves count bytes from the specified buffer into this one. | |
void | merge (Buffer &inbuf) |
Efficiently merges the entire contents of a buffer into this one. | |
Protected Types | |
typedef T | Elem |
typedef WvBufBase< T > | Buffer |
Protected Member Functions | |
WvBufBaseCommonImpl (const WvBufBaseCommonImpl &other) | |
WvBufBaseCommonImpl (WvBufStore *store) | |
Initializes the buffer. | |
Protected Attributes | |
WvBufStore * | store |
|
Definition at line 40 of file wvbufbase.h. |
|
|
Definition at line 45 of file wvbufbase.h. |
|
Initializes the buffer. Note: Does not take ownership of the storage object. "store" is the low-level storage object Definition at line 57 of file wvbufbase.h. |
|
Destroys the buffer.
Definition at line 62 of file wvbufbase.h. |
|
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage location owned by the buffer. The pointer is only valid until the next non-const buffer member is called. eg. alloc(size_t) If count == 0, a NULL pointer may be returned. It is an error for count to be greater than free(). For best results, call this function multiple times with count no greater than optallocable() each time. After this operation, at least count elements may be unallocated. "count" is the number of elements Returns: the element storage pointer Definition at line 376 of file wvbufbase.h. Referenced by WvFunctorEncoder< signed short int, float, WvPCMSigned16ToUnnormFloatFunctor >::_typedencode(), file_hack_end(), WvStream::getline(), main(), WvStream::read(), and WvDsp::uread(). |
|
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED storage location but does not remove the elements from the buffer. It is an error for count to be greater than peekable(offset). For maximum efficiency, choose as large a count as possible. The pointer buf may be NULL only if count == 0. "buf" is the buffer that will receive the elements "offset" is the buffer offset "count" is the number of elements Definition at line 327 of file wvbufbase.h. |
|
Returns the number of elements that the buffer can currently accept for writing. Returns: the number of elements Definition at line 350 of file wvbufbase.h. |
|
Reads the next element from the buffer. It is an error to invoke this method if used() == 0. After this operation, at least 1 element may be ungotten. Returns: the element Definition at line 269 of file wvbufbase.h. Referenced by WvBufBaseCommonImpl< unsigned >::get(), and WvBufBase< unsigned char >::getch(). |
|
Reads exactly the specified number of elements and returns a pointer to a storage location owned by the buffer. The pointer is only valid until the next non-const buffer member is called. eg. alloc(size_t) If count == 0, a NULL pointer may be returned. It is an error for count to be greater than used(). For maximum efficiency, call this function multiple times with count no greater than optgettable() each time. After this operation, at least count elements may be ungotten. Definition at line 113 of file wvbufbase.h. Referenced by WvSyslog::_end_line(), WvLogBuffer::_end_line(), WvFunctorEncoder< signed short int, float, WvPCMSigned16ToUnnormFloatFunctor >::_typedencode(), WvStream::flush_outbuf(), WvStream::getline(), WvProtoStream::next_token(), WvStream::read(), WvProtoStream::token_remaining(), and WvDsp::uwrite(). |
|
Returns a pointer to the underlying storage class object. Returns: the low-level storage class object pointer, non-null Definition at line 69 of file wvbufbase.h. |
|
Returns true if the buffer supports reading. Returns: true if reading is supported Definition at line 81 of file wvbufbase.h. |
|
Returns true if the buffer supports writing. Returns: true if writing is supported Definition at line 339 of file wvbufbase.h. |
|
Efficiently merges the entire contents of a buffer into this one. "inbuf" is the buffer from which to read Definition at line 565 of file wvbufbase.h. |
|
Efficiently moves count bytes from the specified buffer into this one. In some cases, this may be a zero-copy operation. It is an error for count to be greater than inbuf.used(). For maximum efficiency, choose as large a count as possible. After this operation, an indeterminate number of elements may be ungotten from inbuf. "inbuf" is the buffer from which to read "count" is the number of elements Definition at line 555 of file wvbufbase.h. Referenced by WvEncoderStream::finish_read(), WvEncoderStream::flush_read(), WvStream::unread(), and WvDsp::uread(). |
|
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED storage location and removes the elements from the buffer. It is an error for count to be greater than used(). For maximum efficiency, choose as large a count as possible. The pointer buf may be NULL only if count == 0. After this operation, an indeterminate number of elements may be ungotten. "buf" is the buffer that will receive the elements "count" is the number of elements Definition at line 306 of file wvbufbase.h. Referenced by WvEncoderStream::uread(), and WvDsp::uread(). |
|
Returns a non-const pointer info the buffer at the specified offset to the specified number of elements without actually adjusting the current get() index. Other than the fact that the returned storage is mutable, operates identically to peek(int, size_t). "offset" is the buffer offset "count" is the number of elements Returns: the element storage pointer Definition at line 458 of file wvbufbase.h. Referenced by WvStream::getline(). |
|
Returns the optimal maximum number of elements that the buffer can currently accept for writing without incurring significant overhead. Invariants:
Returns: the number of elements Definition at line 394 of file wvbufbase.h. Referenced by WvFunctorEncoder< signed short int, float, WvPCMSigned16ToUnnormFloatFunctor >::_typedencode(). |
|
Returns the optimal maximum number of elements in the buffer currently available for reading without incurring significant overhead. Invariants:
Returns: the number of elements Definition at line 151 of file wvbufbase.h. Referenced by WvFunctorEncoder< signed short int, float, WvPCMSigned16ToUnnormFloatFunctor >::_typedencode(). |
|
Definition at line 233 of file wvbufbase.h. |
|
Returns the element at the specified offset in the buffer. It is an error to invoke this method if used() == 0. "offset" is the offset, default 0 Returns: the element Definition at line 283 of file wvbufbase.h. |
|
Returns a const pointer into the buffer at the specified offset to the specified number of elements without actually adjusting the current get() index. The pointer is only valid until the next non-const buffer member is called. eg. alloc(size_t) If count == 0, a NULL pointer may be returned. If offset is greater than zero, then elements will be returned beginning with the with the offset'th element that would be returned by get(size_t). If offset equals zero, then elements will be returned beginning with the next one available for get(size_t). If offset is less than zero, then elements will be returned beginning with the first one that would be returned on a get(size_t) following an unget(-offset). It is an error for count to be greater than peekable(offset). For maximum efficiency, call this function multiple times with count no greater than that returned by optpeekable(size_t) at incremental offsets. "offset" is the buffer offset "count" is the number of elements Returns: the element storage pointer Definition at line 222 of file wvbufbase.h. Referenced by WvGdbmHash< K, D >::datumize< T >::datumize(), WvOakleyAuth::get_other_public_key(), and UniIniGen::refresh(). |
|
Definition at line 228 of file wvbufbase.h. |
|
Writes the element into the buffer at the specified offset. It is an error to invoke this method if free() == 0. After this operation, at least 1 element may be unallocated. "value" is the element "offset" is the buffer offset Definition at line 532 of file wvbufbase.h. |
|
Efficiently copies the specified number of elements from the specified storage location into the buffer at a particular offset. If offset <= used() and offset + count > used(), the remaining data is simply tacked onto the end of the buffer with put(). It is an error for count to be greater than free() - offset. "data" is the buffer that contains the elements "count" is the number of elements "offset" is the buffer offset, default 0 Definition at line 501 of file wvbufbase.h. |
|
Writes the element into the buffer at its tail. It is an error to invoke this method if free() == 0. After this operation, at least 1 element may be unallocated. "valid" is the element Definition at line 516 of file wvbufbase.h. |
|
Writes the specified number of elements from the specified storage location into the buffer at its tail. It is an error for count to be greater than free(). For maximum efficiency, choose as large a count as possible. The pointer buf may be NULL only if count == 0. After this operation, at least count elements may be unallocated. "data" is the buffer that contains the elements "count" is the number of elements Definition at line 480 of file wvbufbase.h. Referenced by WvSyslog::_begin_line(), WvSyslog::_end_line(), WvLogBuffer::_end_line(), WvSyslog::_mid_line(), WvLogBuffer::_mid_line(), WvOakleyAuth::create_secret(), fixnl(), WvStream::getline(), UniIniGen::refresh(), strreplace(), WvProtoStream::token_remaining(), WvProtoStream::tokline(), url_encode(), WvSSLStream::uwrite(), WvEncoderStream::uwrite(), WvDsp::uwrite(), WvBufStream::uwrite(), WvStream::write(), and wvtcl_encode(). |
|
Skips exactly the specified number of elements. This is equivalent to invoking get(size_t) with the count and discarding the result, but may be faster for certain types of buffers. As with get(size_t), the call may be followed up by an unget(size_t). "count" is the number of elements Definition at line 133 of file wvbufbase.h. |
|
Unallocates exactly the specified number of elements by removing them from the buffer and releasing their storage. This operation may always be safely performed with count less than or equal to that specified in the last alloc(size_t) or put(const T*, size_t) if no non-const buffer members have been called since then. If count == 0, nothing happens. It is an error for count to be greater than unallocable(). "count" is the number of elements Definition at line 418 of file wvbufbase.h. Referenced by file_hack_end(), WvStream::getline(), main(), WvStream::read(), UniIniGen::refresh(), and WvDsp::uread(). |
|
Returns the maximum number of elements that may be unallocated at this time. For all practical purposes, this number will always be at least as large as the amount currently in use. It is provided primarily for symmetry, but also to handle cases where buffer reading (hence used()) is not supported by the implementation. Invariants:
Returns: the number of elements Definition at line 440 of file wvbufbase.h. |
|
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads. This operation may always be safely performed with count less than or equal to that specified in the last get(size_t) if no non-const buffer members have been called since then. If count == 0, nothing happens. It is an error for count to be greater than ungettable(). "count" is the number of elements Definition at line 174 of file wvbufbase.h. Referenced by WvStream::flush_outbuf(). |
|
Returns the maximum number of elements that may be ungotten at this time. Returns: the number of elements Definition at line 185 of file wvbufbase.h. Referenced by WvStream::flush_outbuf(). |
|
Returns the number of elements in the buffer currently available for reading. This function could also be called gettable(). Definition at line 92 of file wvbufbase.h. Referenced by WvSyslog::_end_line(), WvLogBuffer::_end_line(), WvGdbmHash< K, D >::datumize< T >::datumize(), WvEncoderStream::flush_internal(), WvStream::flush_outbuf(), WvStream::flush_then_close(), WvBufBaseCommonImpl< unsigned >::get(), WvStream::getline(), WvBufBase< unsigned char >::getstr(), UniClientConn::isok(), WvFDStream::nowrite(), WvStreamClone::post_select(), WvFDStream::post_select(), WvStreamClone::pre_select(), WvStream::pre_select(), WvFDStream::pre_select(), WvEncoderStream::pre_select(), UniClientConn::pre_select(), WvStream::read(), UniIniGen::refresh(), WvBufBase< unsigned char >::strchr(), WvProtoStream::token_remaining(), WvEncoderStream::uread(), WvDsp::uread(), WvFDStream::uwrite(), WvDsp::uwrite(), WvStream::write(), and wvtcl_encode(). |
|
Clears the buffer. For many types of buffers, calling zap() will increased the amount of free space available for writing (see below) by an amount greater than used(). Hence it is wise to zap() a buffer just before writing to it to maximize free space. After this operation, used() == 0, and often ungettable() == 0. Definition at line 254 of file wvbufbase.h. Referenced by WvSyslog::_end_line(), WvLogBuffer::_end_line(), WvStream::flush_outbuf(), WvProtoStream::tokline(), and WvStream::unread(). |
|
Definition at line 42 of file wvbufbase.h. |