Browse Source

AP_HAL: RingBuffer: Prefix private members with underscore

master
fnoop 8 years ago committed by Lucas De Marchi
parent
commit
3ddd9a6bca
  1. 50
      libraries/AP_HAL/utility/RingBuffer.h

50
libraries/AP_HAL/utility/RingBuffer.h

@ -189,28 +189,28 @@ private:
template <class T> template <class T>
class ObjectArray { class ObjectArray {
public: public:
ObjectArray(uint16_t _size) { ObjectArray(uint16_t size_) {
size = _size; _size = size_;
head = count = 0; _head = _count = 0;
buffer = new T[size]; _buffer = new T[_size];
} }
~ObjectArray(void) { ~ObjectArray(void) {
delete[] buffer; delete[] _buffer;
} }
// return number of objects available to be read // return number of objects available to be read
uint16_t available(void) const { uint16_t available(void) const {
return count; return _count;
} }
// return number of objects that could be written // return number of objects that could be written
uint16_t space(void) const { uint16_t space(void) const {
return size - count; return _size - _count;
} }
// true is available() == 0 // true is available() == 0
bool empty(void) const { bool empty(void) const {
return count == 0; return _count == 0;
} }
// push one object // push one object
@ -218,8 +218,8 @@ public:
if (space() == 0) { if (space() == 0) {
return false; return false;
} }
buffer[(head+count)%size] = object; _buffer[(_head+_count)%_size] = object;
count++; _count++;
return true; return true;
} }
@ -230,15 +230,15 @@ public:
if (empty()) { if (empty()) {
return false; return false;
} }
head = (head+1) % size; _head = (_head+1) % _size;
count--; _count--;
return true; return true;
} }
// Discards the buffer content, emptying it. // Discards the buffer content, emptying it.
void clear(void) void clear(void)
{ {
head = count = 0; _head = _count = 0;
} }
/* /*
@ -248,7 +248,7 @@ public:
if (empty()) { if (empty()) {
return false; return false;
} }
object = buffer[head]; object = _buffer[_head];
return pop(); return pop();
} }
@ -268,12 +268,12 @@ public:
remove the Nth element from the array. First element is zero remove the Nth element from the array. First element is zero
*/ */
bool remove(uint16_t n) { bool remove(uint16_t n) {
if (n >= count) { if (n >= _count) {
return false; return false;
} }
if (n == count-1) { if (n == _count-1) {
// remove last element // remove last element
count--; _count--;
return true; return true;
} }
if (n == 0) { if (n == 0) {
@ -281,25 +281,25 @@ public:
return pop(); return pop();
} }
// take advantage of the [] operator for simple shift of the array elements // take advantage of the [] operator for simple shift of the array elements
for (uint16_t i=n; i<count-1; i++) { for (uint16_t i=n; i<_count-1; i++) {
*(*this)[i] = *(*this)[i+1]; *(*this)[i] = *(*this)[i+1];
} }
count--; _count--;
return true; return true;
} }
// allow array indexing, based on current head. Returns a pointer // allow array indexing, based on current head. Returns a pointer
// to the object or nullptr // to the object or nullptr
T * operator[](uint16_t i) { T * operator[](uint16_t i) {
if (i >= count) { if (i >= _count) {
return nullptr; return nullptr;
} }
return &buffer[(head+i)%size]; return &_buffer[(_head+i)%_size];
} }
private: private:
T *buffer; T *_buffer;
uint16_t size; // total buffer size uint16_t _size; // total buffer size
uint16_t count; // number in buffer now uint16_t _count; // number in buffer now
uint16_t head; // first element uint16_t _head; // first element
}; };

Loading…
Cancel
Save