-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathringIndex.h
More file actions
42 lines (32 loc) · 1.27 KB
/
ringIndex.h
File metadata and controls
42 lines (32 loc) · 1.27 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
39
40
41
42
#ifndef ringIndex_h
#define ringIndex_h
// This does the math and accounting of a ring buffer (Queue) of items. Basically you
// inherit this and use it's call to calculate the indexes (head and tail) of where to
// store items and where to read them from.
//
// Example : Lets say you create a ring buffer of text. To store a char in this buffer,
// you use addItem(). First you can check if your buffer is full, and if not?
//
// buffer[addItem()] = aChar;
//
// addItem() returns the index into your buffer to store the char. Then updates the
// indexes for the next call. readItem() works the same way.
#define INDEX_ERR -1
class ringIndex {
public:
ringIndex(int inNumItems);
virtual ~ringIndex(void);
virtual int addItem(void); // Write to this index, if not INDEX_ERR.
virtual int readItem(void); // Read at this index, if not INDEX_ERR.
virtual bool empty(void); // Are we empty?
virtual bool full(void); // Are we full?
virtual int itemCount(void); // How many items do we have?
virtual int maxItems(void); // How many items can we store?
virtual void flushItems(void); // Reset to zero items.
protected:
virtual int increment(int inIndex); // Increment a pointer. Head or tail, temp?
int numItems;
int head;
int tail;
};
#endif