ADC 1.0

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Macros Pages
RingBuffer.cpp
Go to the documentation of this file.
1 #include "RingBuffer.h"
2
3 // I CAN'T GET NEW[] AND DELETE[] TO WORK....
4 /*RingBuffer::RingBuffer()
5 {
6 RingBuffer(DEFAULT_BUFFER_SIZE);
7 }
8
9 RingBuffer::RingBuffer(int buffer_size) {
10 if(buffer_size%2) { // not a power of 2
11 size = (int)ceil(1.443*log(buffer_size));
12 }
13 b_size = buffer_size;
14 elems = new int[1024];
15 }
16
17 RingBuffer::~RingBuffer()
18 {
19 delete[] elems;
20 }*/
21
22
23 RingBuffer::RingBuffer()
24 {
25 //ctor
26 }
27
28 RingBuffer::~RingBuffer()
29 {
30 // dtor
31 }
32
33 int RingBuffer::isFull() {
34 return (b_end == (b_start ^ b_size));
35 }
36
37 int RingBuffer::isEmpty() {
38 return (b_end == b_start);
39 }
40
41 void RingBuffer::write(int value) {
42 elems[b_end&(b_size-1)] = value;
43 if (isFull()) { /* full, overwrite moves start pointer */
44 b_start = increase(b_start);
45 }
46 b_end = increase(b_end);
47 }
48
49 int RingBuffer::read() {
50 int result = elems[b_start&(b_size-1)];
51 b_start = increase(b_start);
52 return result;
53 }
54
55 // increases the pointer modulo 2*size-1
56 int RingBuffer::increase(int p) {
57 return (p + 1)&(2*b_size-1);
58 }
RingBuffer::read
int read()
Read a value from the buffer.
Definition: RingBuffer.cpp:49
RingBuffer::RingBuffer
RingBuffer()
Default constructor, buffer has a size DEFAULT_BUFFER_SIZE.
Definition: RingBuffer.cpp:23
RingBuffer::isEmpty
int isEmpty()
Returns 1 (true) if the buffer is empty.
Definition: RingBuffer.cpp:37
RingBuffer.h
RingBuffer::~RingBuffer
virtual ~RingBuffer()
Definition: RingBuffer.cpp:28
RingBuffer::write
void write(int value)
Write a value into the buffer.
Definition: RingBuffer.cpp:41
RingBuffer::isFull
int isFull()
Returns 1 (true) if the buffer is full.
Definition: RingBuffer.cpp:33