- const auto iter = rows_.find(row);
- if (iter != rows_.end())
- (*iter).second.get_annotation_subset(dest,
- start_sample, end_sample);
+ try {
+ const DecodeSegment *segment = &(segments_.at(segment_id));
+ const map<const decode::Row, decode::RowData> *rows =
+ &(segment->annotation_rows);
+
+ const auto iter = rows->find(row);
+ if (iter != rows->end())
+ (*iter).second.get_annotation_subset(dest,
+ start_sample, end_sample);
+ } catch (out_of_range&) {
+ // Do nothing
+ }
+}
+
+void DecodeSignal::get_annotation_subset(
+ vector<pv::data::decode::Annotation> &dest,
+ uint32_t segment_id, uint64_t start_sample, uint64_t end_sample) const
+{
+ // Note: We put all vectors and lists on the heap, not the stack
+
+ const vector<Row> rows = visible_rows();
+
+ // Use forward_lists for faster merging
+ forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
+
+ for (const Row& row : rows) {
+ vector<Annotation> *ann_vector = new vector<Annotation>();
+ get_annotation_subset(*ann_vector, row, segment_id, start_sample, end_sample);
+
+ forward_list<Annotation> *ann_list =
+ new forward_list<Annotation>(ann_vector->begin(), ann_vector->end());
+ delete ann_vector;
+
+ all_ann_list->merge(*ann_list);
+ delete ann_list;
+ }
+
+ move(all_ann_list->begin(), all_ann_list->end(), back_inserter(dest));
+ delete all_ann_list;