23 #ifndef PD_VALUERING_H 24 #define PD_VALUERING_H 31 #define VALUERING_DEBUG 0 50 void setRange(std::chrono::nanoseconds);
53 void append(std::chrono::nanoseconds time,
const T &value);
117 if ((
int) length < ring.size()) {
118 unsigned int o = (offset + length) % ring.size();
122 qDebug() << ring.size() <<
"reached.";
128 ring.append(newPair);
142 std::chrono::nanoseconds time
147 for (
unsigned int i = 0; i < other.
length; i++) {
149 if (p.first > time) {
190 return ring[(offset + index) % ring.size()];
202 return ring.at((offset + index) % ring.size());
217 return ring[(offset + index) % ring.size()];
220 return ring[(offset + length + index) % ring.size()];
236 return ring.at((offset + index) % ring.size());
239 return ring.at((offset + length + index) % ring.size());
251 std::chrono::nanoseconds depTime((*
this)[length - 1].first - range);
253 if (ring[offset].first < depTime) {
254 offset = (offset + 1) % ring.size();
270 QList<TimeValuePair> newRing;
274 qDebug() <<
"reshaping" << length <<
"values";
277 for (i = 0; i < length; i++) {
278 newRing.
append((*
this)[i]);
~ValueRing()
Destructor.
Definition: ValueRing.h:93
unsigned int length
Number of valid elements at offset.
Definition: ValueRing.h:68
void reshape()
Reshape the ring to move the offset to zero.
Definition: ValueRing.h:268
void copyUntil(const ValueRing< T > &, std::chrono::nanoseconds)
Copies data from another ring, up to a specific time.
Definition: ValueRing.h:140
std::chrono::nanoseconds range
Time range covered by the ring.
Definition: ValueRing.h:69
ValueRing()
Constructor.
Definition: ValueRing.h:82
QList< TimeValuePair > ring
Time/Value ring.
Definition: ValueRing.h:66
QPair< std::chrono::nanoseconds, T > TimeValuePair
Definition: ValueRing.h:59
void setRange(std::chrono::nanoseconds)
Sets the range.
Definition: ValueRing.h:102
void append(std::chrono::nanoseconds time, const T &value)
Appends a value to the ring.
Definition: ValueRing.h:113
Time/Value ring buffer.
Definition: ValueRing.h:44
void removeDeprecated()
Remove values that exceed the time range.
Definition: ValueRing.h:248
unsigned int offset
Ring offset.
Definition: ValueRing.h:67
std::chrono::nanoseconds getRange() const
Definition: ValueRing.h:51
void clear()
Clears the ring.
Definition: ValueRing.h:163
unsigned int getLength() const
Definition: ValueRing.h:176
TimeValuePair & operator[](unsigned int index)
Index operator.
Definition: ValueRing.h:186