blob: 6bb3071aa22e59f582f1fe7bf272b3da99d8b31b (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
//
// Copyright 1997-1998 by Craig Stuart Sapp, All Rights Reserved.
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: 19 December 1997
// Last Modified: Wed Jan 21 23:08:13 GMT-0800 1998
// Filename: ...sig/maint/code/base/CircularBuffer/CircularBuffer.h
// Web Address: http://sig.sapp.org/include/sigBase/CircularBuffer.cpp
// Documentation: http://sig.sapp.org/doc/classes/CircularBuffer
// Syntax: C++
//
// Description: A Circular buffer designed to handle MIDI input,
// but able to store any type of object. Elements
// can be read out of the buffer in two ways.
// (1) from a read pointer which extracts the
// elements in order by following the write pointer,
// and (2) from an index operator related to the
// write pointer's location, for example,
// object[0] is the last value written into the
// buffer and object[-1] (or object[1]) is the
// item written just before that.
//
#ifndef _CIRCULARBUFFER_H_INCLUDED
#define _CIRCULARBUFFER_H_INCLUDED
template<class type>
class CircularBuffer {
public:
CircularBuffer (void);
CircularBuffer (int maxElements);
CircularBuffer (const CircularBuffer<type>&
anotherBuffer);
~CircularBuffer ();
int capacity (void) const;
type extract (void);
int getCount (void) const;
int getSize (void) const;
void insert (const type& aMessage);
type& operator[] (int index);
type read (void);
void reset (void);
void setSize (int aSize);
void write (const type& aMessage);
protected:
type* buffer;
int size;
int writeIndex;
int readIndex;
int itemCount;
void increment (int& index);
};
#include "CircularBuffer.cpp"
#endif /* _CIRCULARBUFFER_H_INCLUDED */
// md5sum: 2857693ec37fdcb6df09db479faf110b - CircularBuffer.h =css= 20030102
|