|
libcommonc++
0.7
|
A buffer for storing a contiguous sequence of elements. More...
#include <Buffer.h++>


Public Member Functions | |
| Buffer (uint_t size) | |
| Construct a new Buffer with the given size. More... | |
| Buffer (T *data, size_t size, bool takeOwnership=true) | |
| Construct a new Buffer that will wrap the given array. More... | |
| virtual | ~Buffer () |
| Destructor. More... | |
| virtual void | clear () |
| Clear the buffer. More... | |
| void | flip () |
| Flip the buffer. More... | |
| void | rewind () |
| Rewind the buffer. More... | |
| void | setLimit (uint_t limit) |
| Set the limit. More... | |
| void | setPosition (uint_t pos) |
| Set the position. More... | |
| uint_t | bump (uint_t delta) |
| Bump (advance) the position by the given number of elements, or to the limit, whichever occurs first. More... | |
| uint_t | skip (uint_t delta) |
| Advance the position by the given number of elements, or to the limit, whichever occurs first, filling the "skipped" elements with zeroes. More... | |
| bool | put (const T &item) |
| Copy an item into the buffer at the current position and bump the position by 1. More... | |
| bool | get (T *item) |
| Copy an item from the buffer at the current position and bump the position by 1. More... | |
| bool | put (const T *items, uint_t count) |
| Copy an array of items into the buffer starting at the current position, and bump the position by the number of items. More... | |
| void | fill (const T &item, uint_t count=0) |
| Fill the buffer with a given item. More... | |
| bool | get (T *items, uint_t count) |
| Copy an array of items from the buffer starting at the current position, and bump the position by the number of items. More... | |
| int | peek (const T &item) const |
| Scan forward from the current position for an element equal to the given value. More... | |
| T * | getPointer () |
| Get a pointer to the element at the current position. More... | |
| const T * | getPointer () const |
| Get a pointer to the next element to be read or written. More... | |
| uint_t | getLimit () const |
| Get the limit. More... | |
| uint_t | getRemaining () const |
| Get the number of elements available to be read or written. More... | |
| bool | hasRemaining () const |
| Test if there are any elements available to be read or written. More... | |
| uint_t | getPosition () const |
| Get the position of the next element to be read or written. More... | |
| T & | operator[] (int index) |
| Get a reference to the element at the specified index. More... | |
| T | operator[] (int index) const |
| Get a copy of the element at the specified index. More... | |
| virtual void | setSize (uint_t newSize) |
| Resize the buffer. More... | |
| uint_t | getSize () const |
| Get the size of the buffer. More... | |
| T * | getBase () |
| Get a pointer to the base of the buffer. More... | |
| const T * | getBase () const |
| Get a pointer to the base of the buffer. More... | |
Protected Attributes | |
| uint_t | _limit |
| The limit. More... | |
| uint_t | _pos |
| The position. More... | |
| T * | _data |
| A pointer to the raw buffer. More... | |
| uint_t | _size |
| The size of the buffer. More... | |
| bool | _owner |
| Whether this object owns the raw buffer. More... | |
A buffer for storing a contiguous sequence of elements.
The buffer has a limit, which defines a subrange of the entire buffer that is available for reading or writing, and a position, which is the offset of the next element to be read or written.
Construct a new Buffer with the given size.
| size | The capacity of the buffer, in elements. |
| Buffer | ( | T * | data, |
| size_t | size, | ||
| bool | takeOwnership = true |
||
| ) |
|
virtual |
Destructor.
Bump (advance) the position by the given number of elements, or to the limit, whichever occurs first.
| delta | The number of elements. |
|
virtual |
Clear the buffer.
Sets the position to 0 and the limit to the end of the buffer.
Reimplemented from AbstractBuffer< T >.
| void fill | ( | const T & | item, |
| uint_t | count = 0 |
||
| ) |
Fill the buffer with a given item.
| item | The item to fill with. |
| count | The number of elements to fill. If 0 or greater than the number of elements before the limit, the buffer is filled up to the limit. |
| void flip | ( | ) |
Flip the buffer.
Sets the limit to the current position, and the position to 0.
| bool get | ( | T * | item | ) |
Copy an item from the buffer at the current position and bump the position by 1.
| item | The item. |
| bool get | ( | T * | items, |
| uint_t | count | ||
| ) |
Copy an array of items from the buffer starting at the current position, and bump the position by the number of items.
| items | The items to copy into. |
| count | The number of items. |
|
inlineinherited |
Get a pointer to the base of the buffer.
|
inlineinherited |
Get a pointer to the base of the buffer.
|
inline |
Get the limit.
|
inline |
Get a pointer to the element at the current position.
|
inline |
Get a pointer to the next element to be read or written.
|
inline |
Get the position of the next element to be read or written.
|
inlinevirtual |
Get the number of elements available to be read or written.
Implements AbstractBuffer< T >.
|
inlineinherited |
Get the size of the buffer.
|
inlinevirtual |
Test if there are any elements available to be read or written.
Reimplemented from AbstractBuffer< T >.
| T& operator[] | ( | int | index | ) |
Get a reference to the element at the specified index.
| index | The index of the element. |
| OutOfBoundsException | If the index is out of bounds. |
| T operator[] | ( | int | index | ) | const |
Get a copy of the element at the specified index.
| index | The index of the element. |
| OutOfBoundsException | If the index is out of bounds. |
| int peek | ( | const T & | item | ) | const |
Scan forward from the current position for an element equal to the given value.
| item | The item to scan for. |
| bool put | ( | const T & | item | ) |
Copy an item into the buffer at the current position and bump the position by 1.
| item | The item. |
| bool put | ( | const T * | items, |
| uint_t | count | ||
| ) |
Copy an array of items into the buffer starting at the current position, and bump the position by the number of items.
| items | The items to place in the buffer. |
| count | The number of items. |
| void rewind | ( | ) |
Rewind the buffer.
Sets the position to 0.
| void setLimit | ( | uint_t | limit | ) |
Set the limit.
| void setPosition | ( | uint_t | pos | ) |
Set the position.
|
virtualinherited |
Resize the buffer.
| newSize | The new size, in elements. |
| UnsupportedOperationException | If this object does not own the underlying byte buffer. |
Reimplemented in CircularBuffer< T >, CircularBuffer< C >, and CircularBuffer< byte_t >.
Advance the position by the given number of elements, or to the limit, whichever occurs first, filling the "skipped" elements with zeroes.
| delta | The number of elements. |
|
protectedinherited |
A pointer to the raw buffer.
|
protected |
The limit.
|
protectedinherited |
Whether this object owns the raw buffer.
|
protected |
The position.
|
protectedinherited |
The size of the buffer.