47 : events_(other.events_), limit_to_reserved_capacity_(other.limit_to_reserved_capacity_),
48 dropped_events_(other.dropped_events_) {
53 events_ = other.events_;
54 limit_to_reserved_capacity_ = other.limit_to_reserved_capacity_;
55 dropped_events_ = other.dropped_events_;
69 prepare_sort_after_growth();
77 events_.push_back(std::move(e));
78 prepare_sort_after_growth();
86 events_.push_back({p, sample_offset});
87 prepare_sort_after_growth();
95 bool empty()
const {
return events_.empty(); }
96 std::size_t
size()
const {
return events_.size(); }
97 std::size_t
capacity()
const {
return events_.capacity(); }
101 sort_indices_.reserve(events_.capacity());
102 sort_events_.reserve(events_.capacity());
105 limit_to_reserved_capacity_ = enabled;
113 const auto count = events_.size();
116 sort_indices_.resize(count);
117 for (std::size_t i = 0; i < count; ++i)
118 sort_indices_[i] = i;
119 std::sort(sort_indices_.begin(), sort_indices_.end(), [
this](std::size_t a, std::size_t b) {
120 if (events_[a].sample_offset != events_[b].sample_offset)
121 return events_[a].sample_offset < events_[b].sample_offset;
124 sort_events_.resize(count);
125 for (std::size_t i = 0; i < count; ++i)
126 sort_events_[i] = events_[sort_indices_[i]];
127 events_.swap(sort_events_);
130 auto begin() {
return events_.begin(); }
131 auto end() {
return events_.end(); }
132 auto begin()
const {
return events_.begin(); }
133 auto end()
const {
return events_.end(); }
138 void prepare_sort_after_growth() {
139 if (!limit_to_reserved_capacity_) {
140 sort_indices_.reserve(events_.capacity());
141 sort_events_.reserve(events_.capacity());
144 bool can_append()
const {
145 return !limit_to_reserved_capacity_ || events_.size() < events_.capacity();
148 if (dropped_events_ < std::numeric_limits<std::uint32_t>::max()) {
153 static constexpr std::size_t kInitialCapacity = 128;
154 std::vector<UmpEvent> events_;
155 std::vector<std::size_t> sort_indices_;
156 std::vector<UmpEvent> sort_events_;
157 bool limit_to_reserved_capacity_ =
false;
158 std::uint32_t dropped_events_ = 0;
UmpBuffer(const UmpBuffer &other)
Definition ump_buffer.hpp:46
UmpBuffer & operator=(const UmpBuffer &other)
Definition ump_buffer.hpp:51
void set_realtime_capacity_limit(bool enabled=true)
Definition ump_buffer.hpp:104
std::size_t capacity() const
Definition ump_buffer.hpp:97
auto end() const
Definition ump_buffer.hpp:133
bool add(const UmpEvent &e)
Definition ump_buffer.hpp:63
void reserve(std::size_t capacity)
Definition ump_buffer.hpp:99
auto begin()
Definition ump_buffer.hpp:130
const UmpEvent & operator[](std::size_t i) const
Definition ump_buffer.hpp:135
bool add(UmpEvent &&e)
Definition ump_buffer.hpp:72
void sort()
Sort by sample offset, preserving arrival order for equal offsets.
Definition ump_buffer.hpp:112
UmpBuffer(UmpBuffer &&) noexcept=default
UmpBuffer()
Definition ump_buffer.hpp:43
auto end()
Definition ump_buffer.hpp:131
std::size_t size() const
Definition ump_buffer.hpp:96
std::uint32_t dropped_event_count() const
Definition ump_buffer.hpp:98
bool add(const UmpPacket &p, int32_t sample_offset=0)
Definition ump_buffer.hpp:81
bool realtime_capacity_limited() const
Definition ump_buffer.hpp:107
bool empty() const
Definition ump_buffer.hpp:95
void clear()
Definition ump_buffer.hpp:91
auto begin() const
Definition ump_buffer.hpp:132
Definition custom_node_events.hpp:26
One UMP packet with a block-relative sample offset.
Definition ump_buffer.hpp:25
UmpPacket packet
Definition ump_buffer.hpp:26
int32_t sample_offset
Definition ump_buffer.hpp:27