|
|
|
@ -9,10 +9,8 @@
@@ -9,10 +9,8 @@
|
|
|
|
|
// Constructor
|
|
|
|
|
template <class T, uint8_t SIZE> |
|
|
|
|
AP_Buffer<T,SIZE>::AP_Buffer() : |
|
|
|
|
_num_items(0) |
|
|
|
|
_num_items(0), _head(0) |
|
|
|
|
{ |
|
|
|
|
// clear the buffer
|
|
|
|
|
clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// clear - removes all points from the curve
|
|
|
|
@ -23,9 +21,8 @@ void AP_Buffer<T,SIZE>::clear() {
@@ -23,9 +21,8 @@ void AP_Buffer<T,SIZE>::clear() {
|
|
|
|
|
_head = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// add - adds an item to the buffer. returns TRUE if successfully added
|
|
|
|
|
template <class T, uint8_t SIZE> |
|
|
|
|
void AP_Buffer<T,SIZE>::add( T item ) |
|
|
|
|
void AP_Buffer<T,SIZE>::push_back( const T &item ) |
|
|
|
|
{ |
|
|
|
|
// determine position of new item
|
|
|
|
|
uint8_t tail = _head + _num_items; |
|
|
|
@ -48,9 +45,8 @@ void AP_Buffer<T,SIZE>::add( T item )
@@ -48,9 +45,8 @@ void AP_Buffer<T,SIZE>::add( T item )
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// get - returns the next value in the buffer
|
|
|
|
|
template <class T, uint8_t SIZE> |
|
|
|
|
T AP_Buffer<T,SIZE>::get() |
|
|
|
|
T AP_Buffer<T,SIZE>::pop_front() |
|
|
|
|
{ |
|
|
|
|
T result; |
|
|
|
|
|
|
|
|
@ -74,15 +70,15 @@ T AP_Buffer<T,SIZE>::get()
@@ -74,15 +70,15 @@ T AP_Buffer<T,SIZE>::get()
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// peek - check what the next value in the buffer is but don't pull it off
|
|
|
|
|
template <class T, uint8_t SIZE> |
|
|
|
|
T AP_Buffer<T,SIZE>::peek(uint8_t position) const |
|
|
|
|
const T& AP_Buffer<T,SIZE>::peek(uint8_t position) const |
|
|
|
|
{ |
|
|
|
|
uint8_t j = _head+position; |
|
|
|
|
uint8_t j = _head + position; |
|
|
|
|
|
|
|
|
|
// return zero if position is out of range
|
|
|
|
|
if( position >= _num_items ) { |
|
|
|
|
return 0; |
|
|
|
|
const static T r = 0; |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// wrap around if necessary
|
|
|
|
@ -93,12 +89,7 @@ T AP_Buffer<T,SIZE>::peek(uint8_t position) const
@@ -93,12 +89,7 @@ T AP_Buffer<T,SIZE>::peek(uint8_t position) const
|
|
|
|
|
return _buff[j]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template float AP_Buffer<float,5>::peek(uint8_t position) const; |
|
|
|
|
template AP_Buffer<float, 5>::AP_Buffer(); |
|
|
|
|
template void AP_Buffer<float, 5>::clear(); |
|
|
|
|
template void AP_Buffer<float, 5>::add(float); |
|
|
|
|
|
|
|
|
|
template float AP_Buffer<float,15>::peek(uint8_t position) const; |
|
|
|
|
template AP_Buffer<float, 15>::AP_Buffer(); |
|
|
|
|
template void AP_Buffer<float, 15>::clear(); |
|
|
|
|
template void AP_Buffer<float, 15>::add(float); |
|
|
|
|
// explicitly instantiate all needed template instances
|
|
|
|
|
// (this is needed to allow the separation of declaration and definition into header and source files)
|
|
|
|
|
template class AP_Buffer<float, 5>; |
|
|
|
|
template class AP_Buffer<float, 15>; |
|
|
|
|