9 #ifndef __WVBUFFERBASE_H
10 #define __WVBUFFERBASE_H
12 #include "wvbufstore.h"
83 return store->isreadable();
94 return store->used() /
sizeof(Elem);
114 const T *
get(
size_t count)
119 return static_cast<const T*
>(
120 store->get(count *
sizeof(Elem)));
138 store->skip(count *
sizeof(Elem));
156 size_t avail = store->optgettable();
157 size_t elems = avail /
sizeof(Elem);
158 if (elems != 0)
return elems;
159 return avail != 0 && store->used() >=
sizeof(Elem) ? 1 : 0;
179 store->unget(count *
sizeof(Elem));
190 return store->ungettable() /
sizeof(Elem);
225 const T *
peek(
int offset,
size_t count)
227 return static_cast<const T*
>(store->peek(
228 offset *
sizeof(Elem), count *
sizeof(Elem)));
231 size_t peekable(
int offset)
233 return store->peekable(offset *
sizeof(Elem)) /
sizeof(Elem);
236 size_t optpeekable(
int offset)
238 offset *=
sizeof(Elem);
239 size_t avail = store->optpeekable(offset);
240 size_t elems = avail /
sizeof(Elem);
241 if (elems != 0)
return elems;
243 store->peekable(offset) >=
sizeof(Elem) ? 1 : 0;
288 return *
peek(offset *
sizeof(Elem),
sizeof(Elem));
309 void move(T *buf,
size_t count)
311 store->move(buf, count *
sizeof(Elem));
330 void copy(T *buf,
int offset,
size_t count)
332 store->copy(buf, offset *
sizeof(Elem), count *
sizeof(Elem));
355 return store->free() /
sizeof(Elem);
381 return static_cast<T*
>(store->alloc(count *
sizeof(Elem)));
399 size_t avail = store->optallocable();
400 size_t elems = avail /
sizeof(Elem);
401 if (elems != 0)
return elems;
402 return avail != 0 && store->free() >=
sizeof(Elem) ? 1 : 0;
423 return store->unalloc(count *
sizeof(Elem));
445 return store->unallocable() /
sizeof(Elem);
463 return static_cast<T*
>(store->mutablepeek(
464 offset *
sizeof(Elem), count *
sizeof(Elem)));
483 void put(
const T *data,
size_t count)
485 store->put(data, count *
sizeof(Elem));
504 void poke(
const T *data,
int offset,
size_t count)
506 store->poke(data, offset *
sizeof(Elem), count *
sizeof(Elem));
521 store->fastput(& value,
sizeof(Elem));
535 void poke(T &value,
int offset)
537 poke(& value, offset, 1);
560 store->merge(*inbuf.store, count *
sizeof(Elem));
620 bool _autofree =
false) :
622 mystore(sizeof(Elem), _data, _avail * sizeof(Elem),
623 _size * sizeof(Elem), _autofree) { }
632 mystore(sizeof(Elem), _size * sizeof(Elem)) { }
637 mystore(sizeof(Elem), NULL, 0, 0, false) { }
654 return static_cast<T*
>(mystore.ptr());
664 return mystore.size() /
sizeof(Elem);
674 return mystore.get_autofree();
684 mystore.set_autofree(_autofree);
698 void reset(T *_data,
size_t _avail,
size_t _size,
699 bool _autofree =
false)
701 mystore.reset(_data, _avail *
sizeof(Elem),
702 _size *
sizeof(Elem), _autofree);
713 mystore.setavail(_avail *
sizeof(Elem));
743 mystore(sizeof(Elem), _data, _avail * sizeof(Elem)) { }
748 mystore(sizeof(Elem), NULL, 0) { }
765 return static_cast<const T*
>(mystore.ptr());
777 void reset(
const T *_data,
size_t _avail)
779 mystore.reset(_data, _avail *
sizeof(Elem));
790 mystore.setavail(_avail *
sizeof(Elem));
831 bool _autofree =
false) :
833 mystore(sizeof(Elem), _data, _avail * sizeof(Elem),
834 _size * sizeof(Elem), _autofree) { }
843 mystore(sizeof(Elem), _size * sizeof(Elem)) { }
848 mystore(sizeof(Elem), NULL, 0, 0, false) { }
865 return static_cast<T*
>(mystore.ptr());
875 return mystore.size() /
sizeof(Elem);
885 return mystore.get_autofree();
895 mystore.set_autofree(_autofree);
910 void reset(T *_data,
size_t _avail,
size_t _size,
911 bool _autofree =
false)
913 mystore.reset(_data, _avail *
sizeof(Elem),
914 _size *
sizeof(Elem), _autofree);
926 mystore.setavail(_avail *
sizeof(Elem));
974 size_t _maxalloc = 1048576) :
976 mystore(sizeof(Elem), _minalloc * sizeof(Elem),
977 _maxalloc * sizeof(Elem)) { }
1000 mystore(sizeof(Elem)) { }
1035 mystore(sizeof(Elem), _buf.
getstore(),
1036 _start * sizeof(Elem), _length * sizeof(Elem)) { }
1063 template<
typename S>
An abstract generic buffer template.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
size_t optgettable() const
Returns the optimal maximum number of elements in the buffer currently available for reading without ...
WvBufBaseCommonImpl(WvBufStore *store)
Initializes the buffer.
void poke(const T *data, int offset, size_t count)
Efficiently copies the specified number of elements from the specified storage location into the buff...
T peek(int offset=0)
Returns the element at the specified offset in the buffer.
T * mutablepeek(int offset, size_t count)
Returns a non-const pointer info the buffer at the specified offset to the specified number of elemen...
size_t ungettable() const
Returns the maximum number of elements that may be ungotten at this time.
virtual ~WvBufBaseCommonImpl()
Destroys the buffer.
bool iswritable() const
Returns true if the buffer supports writing.
void merge(Buffer &inbuf)
Efficiently merges the entire contents of a buffer into this one.
void put(const T *data, size_t count)
Writes the specified number of elements from the specified storage location into the buffer at its ta...
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 w...
void unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads.
T get()
Reads the next element from the buffer.
size_t unallocable() const
Returns the maximum number of elements that may be unallocated at this time.
const T * get(size_t count)
Reads exactly the specified number of elements and returns a pointer to a storage location owned by t...
void unalloc(size_t count)
Unallocates exactly the specified number of elements by removing them from the buffer and releasing t...
size_t free() const
Returns the number of elements that the buffer can currently accept for writing.
WvBufStore * getstore()
Returns a pointer to the underlying storage class object.
void skip(size_t count)
Skips exactly the specified number of elements.
void move(T *buf, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
size_t optallocable() const
Returns the optimal maximum number of elements that the buffer can currently accept for writing witho...
void put(T &value)
Writes the element into the buffer at its tail.
bool isreadable() const
Returns true if the buffer supports reading.
void zap()
Clears the buffer.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
T * alloc(size_t count)
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage ...
void copy(T *buf, int offset, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
void poke(T &value, int offset)
Writes the element into the buffer at the specified offset.
The generic buffer base type.
A buffer that acts like a cursor over a portion of another buffer.
WvBufCursorBase(WvBufBase< T > &_buf, int _start, size_t _length)
Creates a new buffer.
The WvBufCursor storage class.
The abstract buffer storage base class.
A buffer that provides a read-write view over another buffer with a different datatype.
WvBufViewBase(WvBufBase< S > &_buf)
Creates a new buffer.
A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circ...
WvCircularBufBase(size_t _size)
Creates a new empty circular buffer backed by a new array.
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
WvCircularBufBase(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Creates a new circular buffer backed by the supplied array.
WvCircularBufBase()
Creates a new empty buffer with no backing array.
void normalize()
Normalizes the arrangement of the data such that the contents of the buffer are stored at the beginni...
bool get_autofree() const
Returns the autofree flag.
T * ptr() const
Returns the underlying array pointer.
size_t size() const
Returns the total size of the buffer.
void setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...
virtual ~WvCircularBufBase()
Destroys the buffer.
void set_autofree(bool _autofree)
Sets or clears the autofree flag.
The WvCircularBuf storage class.
A buffer that wraps a pre-allocated array and provides read-only access to its elements.
virtual ~WvConstInPlaceBufBase()
Destroys the buffer.
void setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...
const T * ptr() const
Returns the underlying array pointer.
void reset(const T *_data, size_t _avail)
Resets the underlying buffer pointer and properties.
WvConstInPlaceBufBase()
Creates a new empty buffer with no backing array.
WvConstInPlaceBufBase(const T *_data, size_t _avail)
Creates a new buffer backed by the supplied array.
The WvConstInPlaceBuf storage class.
A buffer that dynamically grows and shrinks based on demand.
WvDynBufBase(size_t _minalloc=1024, size_t _maxalloc=1048576)
Creates a new buffer.
The WvDynBuf storage class.
A buffer that wraps a pre-allocated array and provides read-write access to its elements.
bool get_autofree() const
Returns the autofree flag.
void set_autofree(bool _autofree)
Sets or clears the autofree flag.
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
WvInPlaceBufBase(size_t _size)
Creates a new empty buffer backed by a new array.
virtual ~WvInPlaceBufBase()
Destroys the buffer.
WvInPlaceBufBase()
Creates a new empty buffer with no backing array.
T * ptr() const
Returns the underlying array pointer.
WvInPlaceBufBase(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Creates a new buffer backed by the supplied array.
size_t size() const
Returns the total size of the buffer.
void setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...
The WvInPlaceBuf storage class.
A buffer that is always empty.
WvNullBufBase()
Creates a new buffer.
The WvNullBuf storage class.