IM920地温観測システム CQ 2017ARMセミナー用サンプルプログラム

Dependencies:   C027_Support_ForIM920

Fork of C027_SupportTest by u-blox

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RingBuf.cpp Source File

RingBuf.cpp

00001 #include "RingBuf.h"
00002 
00003 RingBuf::RingBuf(int _size)
00004 {
00005     buf = new RingBufType[_size];
00006     size = _size;
00007     wp = 0;
00008     rp = 0;
00009     latest = -1;
00010 }
00011     
00012 RingBuf::~RingBuf()
00013 {
00014     delete [] buf;
00015 }
00016 
00017 void RingBuf::push(RingBufType *d)
00018 {
00019     latest = wp;
00020     buf[wp++] = *d;
00021     wp %= size;
00022 }
00023 RingBufType* RingBuf::pop(void)
00024 {
00025     if (rp == wp) return NULL;
00026     RingBufType *d = &buf[rp++];
00027     rp %= size;
00028     return d;
00029 }
00030 int RingBuf::len_get(void)
00031 {
00032     int i = wp - rp;
00033     if (i < 0) i += size; 
00034     return i;   
00035 }
00036 int RingBuf::size_get(void)
00037 {
00038     return size;
00039 }
00040 void RingBuf::clear(void)
00041 {
00042     rp = 0;
00043     wp = 0;
00044 }
00045 RingBufType* RingBuf::peek(int p)
00046 {
00047     if (p < 0 || p >= size) return NULL;
00048     return &buf[p];
00049 }
00050