-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsequentialbuffer.h
More file actions
79 lines (61 loc) · 1.87 KB
/
sequentialbuffer.h
File metadata and controls
79 lines (61 loc) · 1.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef SEQUENTIALBUFFER_H
#define SEQUENTIALBUFFER_H
#include <QVector>
#include <QPointF>
#include <QRectF>
/**
* @brief Циклический буфер упорядоченных по X точек.
*/
class SequentialBuffer
{
public:
enum AddressingMode {
CIRCULAR = 0,
LINEAR = 1
};
SequentialBuffer();
SequentialBuffer(const SequentialBuffer& sb);
SequentialBuffer(SequentialBuffer&& sb);
~SequentialBuffer();
AddressingMode addressingMode() const;
void setAddressingMode(AddressingMode newMode);
size_t size() const;
void setSize(size_t newSize);
qreal samplingPeriod() const;
void setSamplingPeriod(qreal newPeriod);
qreal startTime() const;
void setStartTime(qreal newTime);
// Очищает данные.
void clear();
// Сбрасывает информацию о полученных данных.
void reset();
// Число семплов, записанных в буфер.
size_t avail() const;
const QPointF& get(size_t i) const;
QPointF get(size_t i);
// отрицательно приращение x
// использует установленный период дискретизации.
void put(const qreal& y, const qreal& dx = -1);
const QRectF& boundingRect() const;
private:
class Data {
public:
QVector<QPointF> samples;
int index;
int count;
qreal period;
qreal startTime;
AddressingMode addrMode;
QRectF boundingRect;
};
Data* m_d;
void putAndUpd(const qreal& new_y, const qreal& new_dx);
int transIndex(int i, int ref_i) const;
int decIndex(int i) const;
int incIndex(int i) const;
int incCount(int cnt) const;
int decCount(int cnt) const;
void updateVerticalBounds() const;
void recalBounds();
};
#endif // SEQUENTIALBUFFER_H