-
Notifications
You must be signed in to change notification settings - Fork 2
/
circularbuffer.h
55 lines (48 loc) · 1.32 KB
/
circularbuffer.h
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
#ifndef CIRCULARBUFFER_H
#define CIRCULARBUFFER_H
#include <QObject>
#include <QMutex>
#include <QByteArray>
#include <QString>
class CircularBuffer : public QObject
{
Q_OBJECT
public:
explicit CircularBuffer(const uint bufferSize,const QString bufferName = "",QObject *parent = 0);
~CircularBuffer();
int getSize();
bool append(const QByteArray *newData);
bool append(const QString text);
bool append(const char* data,size_t size);
void clear();
QByteArray getCurrentPosData(int length);
QByteArray getCurrentPosData();
QByteArray getData();
size_t getAvailableBytesCount();
static void runTest();
void operator <<(QByteArray newData);
QByteArray operator >>(const int lenght);
enum OverflowPolicy {
Drop = 0,
Expand = 1,
Replace = 2
};
void setOverflowPolicy(const OverflowPolicy newPolicy);
void setPacketSize(const size_t size);
private:
size_t packetSize;
int bsize;
int originalSize;
QByteArray data;
int positionRead;
int positionWrite;
QMutex mutex;
OverflowPolicy policy;
void say(const QString message);
signals:
void readyRead(const int size);
void overflowPolicyChanged(const OverflowPolicy newPolicy);
void debug(const QString message);
public slots:
};
#endif // CIRCULARBUFFER_H