WvStreams
Public Member Functions | Protected Types | Protected Attributes | List of all members
WvCircularBufBase< T > Class Template Reference

A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circular buffering scheme rather than a purely linear one, as used by WvInPlaceBuf. More...

#include <wvbufbase.h>

Inheritance diagram for WvCircularBufBase< T >:
Inheritance graph
[legend]

Public Member Functions

 WvCircularBufBase (T *_data, size_t _avail, size_t _size, bool _autofree=false)
 Creates a new circular buffer backed by the supplied array. More...
 
 WvCircularBufBase (size_t _size)
 Creates a new empty circular buffer backed by a new array. More...
 
 WvCircularBufBase ()
 Creates a new empty buffer with no backing array.
 
virtual ~WvCircularBufBase ()
 Destroys the buffer. More...
 
T * ptr () const
 Returns the underlying array pointer. More...
 
size_t size () const
 Returns the total size of the buffer. More...
 
bool get_autofree () const
 Returns the autofree flag. More...
 
void set_autofree (bool _autofree)
 Sets or clears the autofree flag. More...
 
void reset (T *_data, size_t _avail, size_t _size, bool _autofree=false)
 Resets the underlying buffer pointer and properties. More...
 
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. More...
 
void normalize ()
 Normalizes the arrangement of the data such that the contents of the buffer are stored at the beginning of the array starting with the next element that would be returned by get(size_t). More...
 

Protected Types

typedef T Elem
 

Protected Attributes

WvCircularBufStore mystore
 

Detailed Description

template<class T>
class WvCircularBufBase< T >

A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circular buffering scheme rather than a purely linear one, as used by WvInPlaceBuf.


When there is insufficient contigous free/used space to satisfy a read or write request, the data is automatically reordered in-place to coalesce the free/used spaces into sufficiently large chunks. The process may also be manually triggered to explicitly renormalize the array and shift its contents to the front.

"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 813 of file wvbufbase.h.

Constructor & Destructor Documentation

◆ WvCircularBufBase() [1/2]

template<class T >
WvCircularBufBase< T >::WvCircularBufBase ( T *  _data,
size_t  _avail,
size_t  _size,
bool  _autofree = false 
)
inline

Creates a new circular buffer backed by the supplied array.

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

Definition at line 830 of file wvbufbase.h.

◆ WvCircularBufBase() [2/2]

template<class T >
WvCircularBufBase< T >::WvCircularBufBase ( size_t  _size)
inlineexplicit

Creates a new empty circular buffer backed by a new array.

"_size" is the size of the array

Definition at line 841 of file wvbufbase.h.

◆ ~WvCircularBufBase()

template<class T >
virtual WvCircularBufBase< T >::~WvCircularBufBase ( )
inlinevirtual

Destroys the buffer.

Frees the underlying array if autofree().

Definition at line 856 of file wvbufbase.h.

Member Function Documentation

◆ ptr()

template<class T >
T* WvCircularBufBase< T >::ptr ( ) const
inline

Returns the underlying array pointer.

Returns: the element pointer

Definition at line 863 of file wvbufbase.h.

◆ size()

template<class T >
size_t WvCircularBufBase< T >::size ( ) const
inline

Returns the total size of the buffer.

Returns: the number of elements

Definition at line 873 of file wvbufbase.h.

◆ get_autofree()

template<class T >
bool WvCircularBufBase< T >::get_autofree ( ) const
inline

Returns the autofree flag.

Returns: the autofree flag

Definition at line 883 of file wvbufbase.h.

◆ set_autofree()

template<class T >
void WvCircularBufBase< T >::set_autofree ( bool  _autofree)
inline

Sets or clears the autofree flag.

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

Definition at line 893 of file wvbufbase.h.

◆ reset()

template<class T >
void WvCircularBufBase< T >::reset ( T *  _data,
size_t  _avail,
size_t  _size,
bool  _autofree = false 
)
inline

Resets the underlying buffer pointer and properties.

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

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

Definition at line 910 of file wvbufbase.h.

◆ setavail()

template<class T >
void WvCircularBufBase< T >::setavail ( size_t  _avail)
inline

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 at the beginning of the buffer

Definition at line 924 of file wvbufbase.h.

◆ normalize()

template<class T >
void WvCircularBufBase< T >::normalize ( )
inline

Normalizes the arrangement of the data such that the contents of the buffer are stored at the beginning of the array starting with the next element that would be returned by get(size_t).

After invocation, ungettable() may equal 0.

Definition at line 938 of file wvbufbase.h.


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