Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvInPlaceBuf Class Reference

#include <wvbuf.h>

Inherits WvInPlaceBufBase< unsigned char >.

Collaboration diagram for WvInPlaceBuf:

[legend]
List of all members.

Detailed Description

The in place raw memory buffer type.

Refines the interface to add support for untyped pointers.

Definition at line 164 of file wvbuf.h.

Public Member Functions

 WvInPlaceBuf (void *_data, size_t _avail, size_t _size, bool _autofree=false)
 WvInPlaceBuf (size_t _size)
 WvInPlaceBuf ()
void reset (void *_data, size_t _avail, size_t _size, bool _autofree=false)
unsignedptr () const
 Returns the underlying array pointer.

size_t size () const
 Returns the total size of the buffer.

bool autofree () const
 Returns the autofree flag.

void setautofree (bool _autofree)
 Sets or clears the auto_free flag.

void reset (unsigned *_data, size_t _avail, size_t _size, bool _autofree=false)
 Resets the underlying buffer pointer and properties.

void setavail (size_t _avail)
 Sets the amount of available data using the current buffer and resets the read index to the beginning of the buffer.

WvBufStoregetstore ()
 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 unsignedget (size_t count)
 Reads exactly the specified number of elements and returns a pointer to a storage location owned by the buffer.

unsigned get ()
 Reads the next element from 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 unsignedpeek (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.

unsigned peek (int offset=0)
 Returns the element at the specified offset in the buffer.

size_t peekable (int offset)
size_t optpeekable (int offset)
void zap ()
 Clears the buffer.

void move (unsigned *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 (unsigned *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.

unsignedalloc (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.

unsignedmutablepeek (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 unsigned *data, size_t count)
 Writes the specified number of elements from the specified storage location into the buffer at its tail.

void put (unsigned &value)
 Writes the element into the buffer at its tail.

void poke (const unsigned *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 poke (unsigned &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 unsigned Elem
typedef WvBufBase< unsignedBuffer

Protected Attributes

WvInPlaceBufStore mystore
WvBufStorestore


Member Typedef Documentation

typedef WvBufBase<unsigned > WvBufBaseCommonImpl< unsigned >::Buffer [protected, inherited]
 

Definition at line 40 of file wvbufbase.h.

typedef unsigned WvInPlaceBufBase< unsigned >::Elem [protected, inherited]
 

Reimplemented from WvBufBaseCommonImpl< unsigned >.

Definition at line 603 of file wvbufbase.h.


Constructor & Destructor Documentation

WvInPlaceBuf::WvInPlaceBuf void *  _data,
size_t  _avail,
size_t  _size,
bool  _autofree = false
[inline]
 

Definition at line 167 of file wvbuf.h.

WvInPlaceBuf::WvInPlaceBuf size_t  _size  )  [inline, explicit]
 

Definition at line 171 of file wvbuf.h.

WvInPlaceBuf::WvInPlaceBuf  )  [inline]
 

Definition at line 173 of file wvbuf.h.


Member Function Documentation

unsigned * WvBufBaseCommonImpl< unsigned >::alloc size_t  count  )  [inline, inherited]
 

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.

References WvBufStore::alloc().

Referenced by WvSSLStream::uread().

bool WvInPlaceBufBase< unsigned >::autofree  )  const [inline, inherited]
 

Returns the autofree flag.

Returns: the autofree flag

Definition at line 669 of file wvbufbase.h.

References WvInPlaceBufStore::autofree().

void WvBufBaseCommonImpl< unsigned >::copy unsigned buf,
int  offset,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::copy().

size_t WvBufBaseCommonImpl< unsigned >::free  )  const [inline, inherited]
 

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.

References WvBufStore::free().

Referenced by WvSSLStream::uread(), and WvSSLStream::uwrite().

unsigned WvBufBaseCommonImpl< unsigned >::get  )  [inline, inherited]
 

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.

References WvBufBaseCommonImpl< T >::get().

const unsigned * WvBufBaseCommonImpl< unsigned >::get size_t  count  )  [inline, inherited]
 

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.

References WvBufStore::get(), and WvBufBaseCommonImpl< T >::used().

Referenced by main(), and WvSSLStream::uwrite().

WvBufStore* WvBufBaseCommonImpl< unsigned >::getstore  )  [inline, inherited]
 

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.

bool WvBufBaseCommonImpl< unsigned >::isreadable  )  const [inline, inherited]
 

Returns true if the buffer supports reading.

Returns: true if reading is supported

Definition at line 81 of file wvbufbase.h.

References WvBufStore::isreadable().

bool WvBufBaseCommonImpl< unsigned >::iswritable  )  const [inline, inherited]
 

Returns true if the buffer supports writing.

Returns: true if writing is supported

Definition at line 339 of file wvbufbase.h.

void WvBufBaseCommonImpl< unsigned >::merge Buffer inbuf  )  [inline, inherited]
 

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.

References WvBufBaseCommonImpl< unsigned >::used().

void WvBufBaseCommonImpl< unsigned >::merge Buffer inbuf,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::merge(), and WvBufBaseCommonImpl< unsigned >::store.

void WvBufBaseCommonImpl< unsigned >::move unsigned buf,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::move().

Referenced by WvSSLStream::uread().

unsigned * WvBufBaseCommonImpl< unsigned >::mutablepeek int  offset,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::mutablepeek().

size_t WvBufBaseCommonImpl< unsigned >::optallocable  )  const [inline, inherited]
 

Returns the optimal maximum number of elements that the buffer can currently accept for writing without incurring significant overhead.

Invariants:

  • optallocable() <= free()
  • optallocable() != 0 if free() != 0

Returns: the number of elements

Definition at line 394 of file wvbufbase.h.

References WvBufStore::free(), and WvBufStore::optallocable().

size_t WvBufBaseCommonImpl< unsigned >::optgettable  )  const [inline, inherited]
 

Returns the optimal maximum number of elements in the buffer currently available for reading without incurring significant overhead.

Invariants:

  • optgettable() <= used()
  • optgettable() != 0 if used() != 0

Returns: the number of elements

Definition at line 151 of file wvbufbase.h.

References WvBufStore::optgettable(), and WvBufStore::used().

size_t WvBufBaseCommonImpl< unsigned >::optpeekable int  offset  )  [inline, inherited]
 

Definition at line 233 of file wvbufbase.h.

References WvBufStore::optpeekable(), and WvBufStore::peekable().

unsigned WvBufBaseCommonImpl< unsigned >::peek int  offset = 0  )  [inline, inherited]
 

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.

const unsigned * WvBufBaseCommonImpl< unsigned >::peek int  offset,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::peek().

Referenced by UniIniGen::refresh().

size_t WvBufBaseCommonImpl< unsigned >::peekable int  offset  )  [inline, inherited]
 

Definition at line 228 of file wvbufbase.h.

References WvBufStore::peekable().

void WvBufBaseCommonImpl< unsigned >::poke unsigned value,
int  offset
[inline, inherited]
 

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.

void WvBufBaseCommonImpl< unsigned >::poke const unsigned data,
int  offset,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::poke().

unsigned * WvInPlaceBufBase< unsigned >::ptr  )  const [inline, inherited]
 

Returns the underlying array pointer.

Returns: the element pointer

Definition at line 649 of file wvbufbase.h.

References WvInPlaceBufStore::ptr().

Referenced by WvOggSpeexEncoder::_typedencode().

void WvBufBaseCommonImpl< unsigned >::put unsigned value  )  [inline, inherited]
 

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.

References WvBufStore::fastput().

void WvBufBaseCommonImpl< unsigned >::put const unsigned data,
size_t  count
[inline, inherited]
 

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.

References WvBufStore::put().

Referenced by main(), and WvSSLStream::uwrite().

void WvInPlaceBufBase< unsigned >::reset unsigned _data,
size_t  _avail,
size_t  _size,
bool  _autofree = false
[inline, inherited]
 

Resets the underlying buffer pointer and properties.

If the old and new buffer pointers differ and the old buffer was specified as auto_free, the old buffer is destroyed.

"_data" is the array of data to wrap "_avail" is the amount of data available for reading "_size" is the size of the array "_autofree" is if true, the array will be freed when discarded

Definition at line 695 of file wvbufbase.h.

References WvInPlaceBufStore::reset().

void WvInPlaceBuf::reset void *  _data,
size_t  _avail,
size_t  _size,
bool  _autofree = false
[inline]
 

Definition at line 175 of file wvbuf.h.

References reset().

Referenced by reset().

void WvInPlaceBufBase< unsigned >::setautofree bool  _autofree  )  [inline, inherited]
 

Sets or clears the auto_free flag.

"_autofree" is if true, the array will be freed when discarded

Definition at line 679 of file wvbufbase.h.

References WvInPlaceBufStore::setautofree().

void WvInPlaceBufBase< unsigned >::setavail size_t  _avail  )  [inline, inherited]
 

Sets the amount of available data using the current buffer and resets the read index to the beginning of the buffer.

"_avail" is the amount of data available for reading

Definition at line 708 of file wvbufbase.h.

References WvInPlaceBufStore::setavail().

size_t WvInPlaceBufBase< unsigned >::size  )  const [inline, inherited]
 

Returns the total size of the buffer.

Returns: the number of elements

Definition at line 659 of file wvbufbase.h.

References WvInPlaceBufStore::size().

void WvBufBaseCommonImpl< unsigned >::skip size_t  count  )  [inline, inherited]
 

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.

References WvBufStore::skip().

void WvBufBaseCommonImpl< unsigned >::unalloc size_t  count  )  [inline, inherited]
 

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.

References WvBufStore::unalloc().

Referenced by WvBackslashDecoder::_encode(), and WvSSLStream::uread().

size_t WvBufBaseCommonImpl< unsigned >::unallocable  )  const [inline, inherited]
 

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:

  • unallocable() >= used()

Returns: the number of elements

Definition at line 440 of file wvbufbase.h.

References WvBufStore::unallocable().

void WvBufBaseCommonImpl< unsigned >::unget size_t  count  )  [inline, inherited]
 

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.

References WvBufStore::unget().

Referenced by WvSSLStream::uwrite().

size_t WvBufBaseCommonImpl< unsigned >::ungettable  )  const [inline, inherited]
 

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.

References WvBufStore::ungettable().

size_t WvBufBaseCommonImpl< unsigned >::used  )  const [inline, inherited]
 

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.

References WvBufStore::used().

Referenced by WvOggSpeexEncoder::_typedencode(), WvEncoder::encodebufmem(), WvBufBaseCommonImpl< unsigned >::merge(), WvSSLStream::pre_select(), WvSSLStream::uread(), WvSSLStream::uwrite(), and wvtcl_decode().

void WvBufBaseCommonImpl< unsigned >::zap  )  [inline, inherited]
 

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.

References WvBufStore::zap().

Referenced by WvBackslashDecoder::_reset(), WvOggSpeexEncoder::_typedencode(), WvSSLStream::uread(), and WvSSLStream::uwrite().


Member Data Documentation

WvInPlaceBufStore WvInPlaceBufBase< unsigned >::mystore [protected, inherited]
 

Definition at line 605 of file wvbufbase.h.

WvBufStore* WvBufBaseCommonImpl< unsigned >::store [protected, inherited]
 

Definition at line 42 of file wvbufbase.h.

Referenced by WvBufBaseCommonImpl< unsigned >::merge().


The documentation for this class was generated from the following file:
Generated on Tue Oct 5 01:09:27 2004 for WvStreams by doxygen 1.3.7