analog module solar on foils project
Dependencies: mbed
Fork of CAN_module_analog by
Diff: circular_buffer.h
- Revision:
- 0:38f51c4f7655
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/circular_buffer.h Tue Aug 11 08:41:49 2015 +0000 @@ -0,0 +1,53 @@ +#ifndef CIRCULAR_BUFFER +#define CIRCULAR_BUFFER + + +template<class T> +class circular_buffer +{ +public: +// circular_buffer(); + circular_buffer(int capacity); + ~circular_buffer(); + + int get_capacity(); // get the maximum capacity of the buf + int get_size(); // get the current item count + + void push_back(T item); +// void push_front(T item); + + void pop_back(); + void pop_front(); + + T& front(); + T& back(); + + T& at(int index); + T& operator[](int index); + + +protected: + + int capacity; + int size; + int start_pos; + int end_pos; + + T *buffer; + + void increment(int& index); + void decrement(int& index); + + int if_increment(int index); + int if_decrement(int index); + + void reset(); + + +}; + +#include "circular_buffer.cpp" + +#endif // CIRCULAR_BUFFER + +