-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathringbuffer.h
More file actions
38 lines (33 loc) · 1.38 KB
/
Copy pathringbuffer.h
File metadata and controls
38 lines (33 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
#include <vector>
#include <string>
#include <ostream>
class RingBuffer
{
public:
RingBuffer(unsigned int size); //constructor
int & operator [](int i) ; //operator [] overloading
friend std::ostream& operator <<(std::ostream& os, const RingBuffer& rb){
std::string str;
for(unsigned i = 0; i < rb.data.size()-1; i++)
str.append(std::to_string(rb.data[i]) + " - ");
str.append(std::to_string(rb.data[rb.data.size()-1]));
os << str;
return os;
};
//general functions
void insert(int data); //for data insertion
bool remove(int data); //for data removal
bool is_full(); //check if buffer is already full
bool is_empty(); //check if buffer is empty
void clear_data(); //clear data :)
std::string to_string(); //print vector data
private:
std::vector<int> data; //buffer's data
std::vector<int>::iterator it; //iterator for vector control
std::size_t size_data; //contains the buffer size
unsigned int ctrlInsert; //insertion controller
unsigned int ctrlRemove; //removal controller
};
#endif // RINGBUFFER_H