2 * This file is part of the PulseView project.
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <pv/data/decode/decoder.hpp>
21 #include <pv/data/decode/row.hpp>
22 #include <pv/data/decode/rowdata.hpp>
30 RowData::RowData(Row* row) :
36 uint64_t RowData::get_max_sample() const
38 if (annotations_.empty())
40 return annotations_.back().end_sample();
43 uint64_t RowData::get_annotation_count() const
45 return annotations_.size();
48 void RowData::get_annotation_subset(
49 vector<pv::data::decode::Annotation> &dest,
50 uint64_t start_sample, uint64_t end_sample) const
52 // Determine whether we must apply per-class filtering or not
53 bool all_ann_classes_enabled = true;
54 bool all_ann_classes_disabled = true;
56 uint32_t max_ann_class_id = 0;
57 for (AnnotationClass* c : row_->ann_classes()) {
59 all_ann_classes_enabled = false;
61 all_ann_classes_disabled = false;
62 if (c->id > max_ann_class_id)
63 max_ann_class_id = c->id;
66 if (all_ann_classes_enabled) {
67 // No filtering, send everyting out as-is
68 for (const auto& annotation : annotations_)
69 if ((annotation.end_sample() > start_sample) &&
70 (annotation.start_sample() <= end_sample))
71 dest.push_back(annotation);
73 if (!all_ann_classes_disabled) {
74 // Filter out invisible annotation classes
75 vector<size_t> class_visible;
76 class_visible.resize(max_ann_class_id + 1, 0);
77 for (AnnotationClass* c : row_->ann_classes())
79 class_visible[c->id] = 1;
81 for (const auto& annotation : annotations_)
82 if ((annotation.end_sample() > start_sample) &&
83 (annotation.start_sample() <= end_sample) &&
84 (class_visible[annotation.ann_class()]))
85 dest.push_back(annotation);
90 void RowData::emplace_annotation(srd_proto_data *pdata)
92 annotations_.emplace_back(pdata, row_);