Circular Buffer template for any data type

Dependents:   serqet serqet2 EMGvoorjan kopija_NUCLEO_CELL_LOCKER_copy ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers circular_buffer.h Source File

circular_buffer.h

00001 #ifndef CIRCULAR_BUFFER
00002 #define CIRCULAR_BUFFER
00003 
00004 
00005 template<class T>
00006 class circular_buffer
00007 {
00008 public:
00009 //    circular_buffer();
00010     circular_buffer(int capacity);
00011     ~circular_buffer();
00012 
00013     int get_capacity(); // get the maximum capacity of the buf
00014     int get_size();     // get the current item count
00015 
00016     void push_back(T item);
00017 //    void push_front(T item);
00018 
00019     void pop_back();
00020     void pop_front();
00021 
00022     T& front();
00023     T& back();
00024 
00025     T& at(int index);
00026     T& operator[](int index);
00027 
00028 
00029 protected:
00030 
00031     int capacity;
00032     int size;
00033     int start_pos;
00034     int end_pos;
00035 
00036     T *buffer;
00037 
00038     void increment(int& index);
00039     void decrement(int& index);
00040 
00041     int if_increment(int index);
00042     int if_decrement(int index);
00043 
00044     void reset();
00045 
00046 
00047 };
00048 
00049 #include "circular_buffer.cpp"
00050 
00051 #endif // CIRCULAR_BUFFER
00052 
00053