mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 01:23:34 +08:00
Add some more useful methods to the ringbuffer class.
This commit is contained in:
@@ -104,6 +104,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool full() { return _next(_head) == _tail; }
|
bool full() { return _next(_head) == _tail; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the capacity of the buffer, or zero if the buffer could
|
||||||
|
* not be allocated.
|
||||||
|
*/
|
||||||
|
unsigned size() { return (_buf != nullptr) ? _size : 0; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Empties the buffer.
|
||||||
|
*/
|
||||||
|
void flush() { _head = _tail = _size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T *const _buf;
|
T *const _buf;
|
||||||
const unsigned _size;
|
const unsigned _size;
|
||||||
@@ -114,11 +125,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
RingBuffer<T>::RingBuffer(unsigned size) :
|
RingBuffer<T>::RingBuffer(unsigned with_size) :
|
||||||
_buf(new T[size + 1]),
|
_buf(new T[with_size + 1]),
|
||||||
_size(size),
|
_size(with_size),
|
||||||
_head(size),
|
_head(with_size),
|
||||||
_tail(size)
|
_tail(with_size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user