23 #ifndef PD_VALUERING_H 24 #define PD_VALUERING_H 31 #define VALUERING_DEBUG 0 49 void setRange(std::chrono::nanoseconds);
52 void append(std::chrono::nanoseconds time,
const T &value);
111 if ((
int) length < ring.size()) {
112 unsigned int o = (offset + length) % ring.size();
117 qDebug() << ring.size() <<
"reached.";
123 ring.append(newPair);
136 std::chrono::nanoseconds time)
140 for (
unsigned int i = 0; i < other.
length; i++) {
142 if (p.first > time) {
179 return ring[(offset + index) % ring.size()];
189 return ring.at((offset + index) % ring.size());
202 return ring[(offset + index) % ring.size()];
205 return ring[(offset + length + index) % ring.size()];
219 return ring.at((offset + index) % ring.size());
222 return ring.at((offset + length + index) % ring.size());
233 std::chrono::nanoseconds depTime((*
this)[length - 1].first - range);
235 if (ring[offset].first < depTime) {
236 offset = (offset + 1) % ring.size();
252 QList<TimeValuePair> newRing;
256 qDebug() <<
"reshaping" << length <<
"values";
259 for (i = 0; i < length; i++) {
260 newRing.append((*
this)[i]);
Time/Value ring buffer.
Definition: ValueRing.h:43
TimeValuePair & operator[](unsigned int index)
Index operator.
Definition: ValueRing.h:177
ValueRing()
Constructor.
Definition: ValueRing.h:80
void removeDeprecated()
Remove values that exceed the time range.
Definition: ValueRing.h:230
unsigned int offset
Ring offset.
Definition: ValueRing.h:66
std::chrono::nanoseconds range
Time range covered by the ring.
Definition: ValueRing.h:68
Definition: BroadcastModel.h:32
void copyUntil(const ValueRing< T > &, std::chrono::nanoseconds)
Copies data from another ring, up to a specific time.
Definition: ValueRing.h:134
std::chrono::nanoseconds getRange() const
Definition: ValueRing.h:50
void setRange(std::chrono::nanoseconds)
Sets the range.
Definition: ValueRing.h:96
QPair< std::chrono::nanoseconds, T > TimeValuePair
Definition: ValueRing.h:58
~ValueRing()
Destructor.
Definition: ValueRing.h:89
unsigned int getLength() const
Definition: ValueRing.h:167
QList< TimeValuePair > ring
Time/Value ring.
Definition: ValueRing.h:65
unsigned int length
Number of valid elements at offset.
Definition: ValueRing.h:67
void reshape()
Reshape the ring to move the offset to zero.
Definition: ValueRing.h:250
void clear()
Clears the ring.
Definition: ValueRing.h:155
void append(std::chrono::nanoseconds time, const T &value)
Appends a value to the ring.
Definition: ValueRing.h:107