36372 mbed / Mbed 2 deprecated SP14P1_skeleton

Dependencies:   AvailableMemory mbed-rtos mbed

Fork of helloaabbc by 32314 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RingBuffer.h Source File

RingBuffer.h

00001 #ifndef _RING_BUFFER_H
00002 #define _RING_BUFFER_H
00003 
00004 #include "mbed.h"
00005 
00006 class RingBuffer{
00007 private:
00008 
00009   /*buf is the maximum size of the ring buffer; start is the beginning of first valid element, end is the next available position
00010     to write*/
00011   int bufSize, start, end;
00012 public:
00013   /*buf is the pointer to actual buffer start, bufEnd is the actual end of the buffer,
00014     end is the current available position to insert (no element is at end yet), start is the first full position*/
00015   int *buf;
00016   /*cur is used in next() method, denoting the current position in a sequential read, count is the number of elements*/
00017   int cur,count;
00018 
00019   RingBuffer(int *data=NULL, int bs=0):bufSize(bs),start(0),end(0),buf(data),cur(0),count(0){}
00020   ~RingBuffer(){buf=NULL;}
00021   void insert(int sample);
00022   int next();
00023   int getCount()const{return count;}
00024   void dump(FILE *fp)const;
00025 };
00026 
00027 #endif