#include <CircularBuffer.h++>


Public Member Functions | |
| CircularBuffer (size_t size) | |
| Construct a new CircularBuffer with the given size. | |
| ~CircularBuffer () throw () | |
| Destructor. | |
| void | clear () throw () |
| Clear the buffer. | |
| virtual void | setSize (size_t newSize) |
| Resize the buffer. | |
| size_t | write (const T *buf, size_t count) throw () |
| Write data from an array into the buffer. | |
| size_t | write (Buffer< T > &buffer, size_t count=0) throw () |
| Write data from a Buffer into the buffer. | |
| size_t | write (Stream &stream, size_t count=0) throw (IOException) |
| Read data from a stream and write it into the buffer. | |
| size_t | read (T *buf, size_t count) throw () |
| Read data from the buffer into an array. | |
| size_t | read (Buffer< T > &buffer, size_t count=0) throw () |
| Read data from the buffer into a Buffer. | |
| size_t | read (Stream &stream, size_t count=0) throw (IOException) |
| Read data from the buffer and write it to a stream. | |
| size_t | peek (const T &value, size_t maxlen, bool &found, bool resetPeek=true) throw () |
| Scan forward from the current peek position for an element equal to the given value. | |
| size_t | fill (const T &value, size_t count) throw () |
| Fill the buffer with the given value. | |
| size_t | getReadExtent () const throw () |
| Get the read extent. | |
| size_t | getWriteExtent () const throw () |
| Get the write extent. | |
| size_t | getRemaining () const throw () |
| Get the number of elements available to be read from the buffer. | |
| size_t | getPeekRemaining () const throw () |
| Get the number of elements available to be peeked, that is, the number of elements between the peek position and the write position. | |
| bool | isEmpty () const throw () |
| Determine if the buffer is empty. | |
| bool | isFull () const throw () |
| Determine if the buffer is full. | |
| size_t | getFree () const throw () |
| Get the number of elements available to be written to the buffer. | |
| T * | getReadPos () throw () |
| Get the current read position. | |
| T * | getWritePos () throw () |
| Get the current write position. | |
| T * | getPeekPos () throw () |
| Get the current peek position. | |
| T * | advanceReadPos (size_t count) throw () |
| Advance the read position by the given number of elements. | |
| T * | advanceWritePos (size_t count) throw () |
| Advance the write position by the given number of elements. | |
| T * | advanceReadPos () throw () |
| Advance the read position by the number of elements in the read extent, wrapping to the beginning of the buffer if necessary. | |
| T * | advanceWritePos () throw () |
| Advance the write position by the number of elements in the write extent, wrapping to the beginning of the buffer if necessary. | |
| T * | advancePeekPos (size_t count) throw () |
| Advance the peek position by the given number of elements, wrapping to the beginning of the buffer if necessary. | |
| void | resetPeekPos () throw () |
| Reset the peek position to the read position. | |
| bool | isPartialWrite () const throw () |
| Determine if a partially-written element is in the buffer. | |
| bool | isPartialRead () const throw () |
| Determine if a partially-read element is in the buffer. | |
| size_t | getSize () const throw () |
| Get the size of the buffer. | |
| virtual bool | hasRemaining () const throw () |
| Test if the buffer has elements available to be read or written. | |
| T * | getBase () throw () |
| Get a pointer to the base of the buffer. | |
| const T * | getBase () const throw () |
| Get a pointer to the base of the buffer. | |
Protected Attributes | |
| T * | _data |
| A pointer to the raw buffer. | |
| size_t | _size |
| The size of the buffer. | |
The buffer has a read position and a write position, as well as a peek position. When either the read position or the write position reaches the end of the buffer, it wraps around to the beginning, but the read position can never overtake the write position. The peek position is always between the read position and the write position, and is used to "look ahead" for a specific value.
| CircularBuffer | ( | size_t | size | ) | [inline] |
Construct a new CircularBuffer with the given size.
| size | The capacity of the buffer, in elements. |
| ~CircularBuffer | ( | ) | throw () [inline] |
Destructor.
| T * advancePeekPos | ( | size_t | count | ) | throw () [inline] |
Advance the peek position by the given number of elements, wrapping to the beginning of the buffer if necessary.
If there are not enough elements between the current peek position and the write position, the peek position is not moved.
| count | The number of elements to advance. |
| T* advanceReadPos | ( | ) | throw () [inline] |
Advance the read position by the number of elements in the read extent, wrapping to the beginning of the buffer if necessary.
| T * advanceReadPos | ( | size_t | count | ) | throw () [inline] |
Advance the read position by the given number of elements.
| count | The number of elements to advance. If the value is greater than the number of bytes available to be read, the read position is left unchanged. |
| T* advanceWritePos | ( | ) | throw () [inline] |
Advance the write position by the number of elements in the write extent, wrapping to the beginning of the buffer if necessary.
| T * advanceWritePos | ( | size_t | count | ) | throw () [inline] |
Advance the write position by the given number of elements.
| count | The number of elements to advance. If the value is greater than the number of elements available to be written, the write position is left unchanged. |
| void clear | ( | ) | throw () [inline, virtual] |
| size_t fill | ( | const T & | value, | |
| size_t | count | |||
| ) | throw () [inline] |
Fill the buffer with the given value.
Fills the requested number of items. If the requested count exceeds the number of items available to be written, only the available (free) items are filled.
| value | The value to fill with. | |
| count | The number of items to fill. |
| const T * getBase | ( | ) | const throw () [inline, inherited] |
Get a pointer to the base of the buffer.
| T * getBase | ( | ) | throw () [inline, inherited] |
Get a pointer to the base of the buffer.
| size_t getFree | ( | ) | const throw () [inline] |
Get the number of elements available to be written to the buffer.
| T* getPeekPos | ( | ) | throw () [inline] |
Get the current peek position.
| size_t getPeekRemaining | ( | ) | const throw () [inline] |
Get the number of elements available to be peeked, that is, the number of elements between the peek position and the write position.
| size_t getReadExtent | ( | ) | const throw () [inline] |
Get the read extent.
| T* getReadPos | ( | ) | throw () [inline] |
Get the current read position.
| size_t getRemaining | ( | ) | const throw () [inline, virtual] |
| size_t getSize | ( | ) | const throw () [inline, inherited] |
Get the size of the buffer.
| size_t getWriteExtent | ( | ) | const throw () [inline] |
Get the write extent.
| T* getWritePos | ( | ) | throw () [inline] |
Get the current write position.
| virtual bool hasRemaining | ( | ) | const throw () [inline, virtual, inherited] |
| bool isEmpty | ( | ) | const throw () [inline] |
Determine if the buffer is empty.
| bool isFull | ( | ) | const throw () [inline] |
Determine if the buffer is full.
| bool isPartialRead | ( | ) | const throw () [inline] |
Determine if a partially-read element is in the buffer.
This will always be false when the template parameter is an object of size 1.
| bool isPartialWrite | ( | ) | const throw () [inline] |
Determine if a partially-written element is in the buffer.
This will always be false when the template parameter is an object of size 1.
| size_t peek | ( | const T & | value, | |
| size_t | maxlen, | |||
| bool & | found, | |||
| bool | resetPeek = true | |||
| ) | throw () [inline] |
Scan forward from the current peek position for an element equal to the given value.
| value | The value to scan for. | |
| maxlen | The maximum number of elements to scan. | |
| found | A flag that is set to true if the item was found, and false otherwise. | |
| resetPeek | If true, reset the peek position to the read position before scanning. |
| size_t read | ( | Stream & | stream, | |
| size_t | count = 0 | |||
| ) | throw (IOException) [inline] |
Read data from the buffer and write it to a stream.
| stream | The stream to write to. | |
| count | The number of bytes to write to the stream. |
| commoncpp::IOException | If an I/O error occurs. |
| size_t read | ( | Buffer< T > & | buffer, | |
| size_t | count = 0 | |||
| ) | throw () [inline] |
Read data from the buffer into a Buffer.
| buffer | The buffer to read into. | |
| count | The number of elements to copy to the buffer, or 0 to write as much as possible. |
| size_t read | ( | T * | buf, | |
| size_t | count | |||
| ) | throw () [inline] |
Read data from the buffer into an array.
| buf | The base of the array. | |
| count | The number of elements to write to the array. |
| void resetPeekPos | ( | ) | throw () [inline] |
Reset the peek position to the read position.
| void setSize | ( | size_t | newSize | ) | [inline, virtual] |
Resize the buffer.
| newSize | The new size, in elements. |
Reimplemented from AbstractBuffer< T >.
| size_t write | ( | Stream & | stream, | |
| size_t | count = 0 | |||
| ) | throw (IOException) [inline] |
Read data from a stream and write it into the buffer.
| stream | The stream to read from. | |
| count | The number of elements to write from the stream. |
| commoncpp::IOException | If an I/O error occurs. |
| size_t write | ( | Buffer< T > & | buffer, | |
| size_t | count = 0 | |||
| ) | throw () [inline] |
Write data from a Buffer into the buffer.
| buffer | The buffer of data to write. | |
| count | The number of elements to write from the buffer, or 0 to write as much as possible. |
| size_t write | ( | const T * | buf, | |
| size_t | count | |||
| ) | throw () [inline] |
Write data from an array into the buffer.
| buf | The base of the array. | |
| count | The number of elements to read from the array. |
T * _data [protected, inherited] |
A pointer to the raw buffer.
size_t _size [protected, inherited] |
The size of the buffer.
1.5.9