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