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>
1068 #endif // __WVBUFFERBASE_H
bool iswritable() const
Returns true if the buffer supports writing.
void put(T &value)
Writes the element into the buffer at its tail.
virtual ~WvBufBaseCommonImpl()
Destroys the buffer.
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 setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...
void setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...
The WvConstInPlaceBuf storage class.
WvInPlaceBufBase(size_t _size)
Creates a new empty buffer backed by a new array.
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...
void unget(size_t count)
Ungets exactly the specified number of elements by returning them to the buffer for subsequent reads.
bool get_autofree() const
Returns the autofree flag.
T * alloc(size_t count)
Allocates exactly the specified number of elements and returns a pointer to an UNINITIALIZED storage ...
The WvDynBuf storage class.
void unalloc(size_t count)
Unallocates exactly the specified number of elements by removing them from the buffer and releasing t...
WvBufCursorBase(WvBufBase< T > &_buf, int _start, size_t _length)
Creates a new buffer.
size_t free() const
Returns the number of elements that the buffer can currently accept for writing.
size_t optgettable() const
Returns the optimal maximum number of elements in the buffer currently available for reading without ...
size_t ungettable() const
Returns the maximum number of elements that may be ungotten at this time.
WvBufStore * getstore()
Returns a pointer to the underlying storage class object.
T get()
Reads the next element from the buffer.
WvBufBaseCommonImpl(WvBufStore *store)
Initializes the buffer.
The generic buffer base type.
bool isreadable() const
Returns true if the buffer supports reading.
void set_autofree(bool _autofree)
Sets or clears the autofree flag.
void move(T *buf, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
A buffer that wraps a pre-allocated array and provides read-only access to its elements.
A buffer that provides a read-write view over another buffer with a different datatype.
void copy(T *buf, int offset, size_t count)
Efficiently copies the specified number of elements from the buffer to the specified UNINITIALIZED st...
WvInPlaceBufBase(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Creates a new buffer backed by the supplied array.
A buffer that wraps a pre-allocated array and provides read-write access to its elements.
void reset(const T *_data, size_t _avail)
Resets the underlying buffer pointer and properties.
A buffer that wraps a pre-allocated array and provides read-write access to its elements using a circ...
WvConstInPlaceBufBase()
Creates a new empty buffer with no backing array.
T * ptr() const
Returns the underlying array pointer.
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
The WvCircularBuf storage class.
void set_autofree(bool _autofree)
Sets or clears the autofree flag.
void merge(Buffer &inbuf)
Efficiently merges the entire contents of a buffer into this one.
size_t size() const
Returns the total size of the buffer.
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
void zap()
Clears the buffer.
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...
The abstract buffer storage base class.
WvCircularBufBase(size_t _size)
Creates a new empty circular buffer backed by a new array.
The WvInPlaceBuf storage class.
virtual ~WvConstInPlaceBufBase()
Destroys the buffer.
T peek(int offset=0)
Returns the element at the specified offset in the buffer.
WvConstInPlaceBufBase(const T *_data, size_t _avail)
Creates a new buffer backed by the supplied array.
void reset(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Resets the underlying buffer pointer and properties.
A buffer that is always empty.
A buffer that acts like a cursor over a portion of another buffer.
A buffer that dynamically grows and shrinks based on demand.
size_t size() const
Returns the total size of the buffer.
void skip(size_t count)
Skips exactly the specified number of elements.
virtual ~WvInPlaceBufBase()
Destroys the buffer.
bool get_autofree() const
Returns the autofree flag.
size_t used() const
Returns the number of elements in the buffer currently available for reading.
size_t unallocable() const
Returns the maximum number of elements that may be unallocated at this time.
WvNullBufBase()
Creates a new buffer.
virtual ~WvCircularBufBase()
Destroys the buffer.
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...
An abstract generic buffer template.
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...
WvCircularBufBase()
Creates a new empty buffer with no backing array.
void merge(Buffer &inbuf, size_t count)
Efficiently moves count bytes from the specified buffer into this one.
WvBufViewBase(WvBufBase< S > &_buf)
Creates a new buffer.
void poke(T &value, int offset)
Writes the element into the buffer at the specified offset.
T * ptr() const
Returns the underlying array pointer.
WvDynBufBase(size_t _minalloc=1024, size_t _maxalloc=1048576)
Creates a new buffer.
The WvNullBuf storage class.
void normalize()
Normalizes the arrangement of the data such that the contents of the buffer are stored at the beginni...
size_t optallocable() const
Returns the optimal maximum number of elements that the buffer can currently accept for writing witho...
const T * ptr() const
Returns the underlying array pointer.
WvInPlaceBufBase()
Creates a new empty buffer with no backing array.
WvCircularBufBase(T *_data, size_t _avail, size_t _size, bool _autofree=false)
Creates a new circular buffer backed by the supplied array.
The WvBufCursor storage class.
void setavail(size_t _avail)
Sets the amount of available data using the current buffer and resets the read index to the beginning...