EKF simplify RingBuffer allocation check

This commit is contained in:
Daniel Agar
2017-11-16 13:09:17 -05:00
parent af7004ef01
commit 75d1ed894c
3 changed files with 63 additions and 114 deletions
+9 -10
View File
@@ -45,7 +45,13 @@ template <typename data_type>
class RingBuffer
{
public:
RingBuffer() = default;
RingBuffer() {
if (allocate(1)) {
// initialize with one empty sample
data_type d = {};
push(d);
}
}
~RingBuffer() { delete[] _buffer; }
// no copy, assignment, move, move assignment
@@ -72,8 +78,8 @@ public:
_tail = 0;
// set the time elements to zero so that bad data is not retrieved from the buffers
for (unsigned index = 0; index < _size; index++) {
_buffer[index].time_us = 0;
for (uint8_t index = 0; index < _size; index++) {
_buffer[index] = {};
}
_first_write = true;
@@ -149,13 +155,6 @@ public:
return false;
}
// return ttrue if allocated
unsigned is_allocated()
{
return (_buffer != NULL);
}
private:
data_type *_buffer{nullptr};