]> sigrok.org Git - pulseview.git/blame - pv/data/decode/rowdata.cpp
Row: Include fix
[pulseview.git] / pv / data / decode / rowdata.cpp
CommitLineData
f9101a91
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
f9101a91
JH
18 */
19
6a26fc44
SA
20#include <pv/data/decode/decoder.hpp>
21#include <pv/data/decode/row.hpp>
22#include <pv/data/decode/rowdata.hpp>
f9101a91
JH
23
24using std::vector;
25
26namespace pv {
27namespace data {
28namespace decode {
29
6a26fc44 30RowData::RowData(Row* row) :
5a9146ac
SA
31 row_(row),
32 prev_ann_start_sample_(0)
6a26fc44
SA
33{
34 assert(row);
35}
36
f9101a91
JH
37uint64_t RowData::get_max_sample() const
38{
8dbbc7f0 39 if (annotations_.empty())
f9101a91 40 return 0;
8dbbc7f0 41 return annotations_.back().end_sample();
f9101a91
JH
42}
43
f994f496
SA
44uint64_t RowData::get_annotation_count() const
45{
46 return annotations_.size();
47}
48
f9101a91 49void RowData::get_annotation_subset(
5a9146ac 50 vector<const pv::data::decode::Annotation*> &dest,
f9101a91
JH
51 uint64_t start_sample, uint64_t end_sample) const
52{
6a26fc44
SA
53 // Determine whether we must apply per-class filtering or not
54 bool all_ann_classes_enabled = true;
55 bool all_ann_classes_disabled = true;
56
57 uint32_t max_ann_class_id = 0;
58 for (AnnotationClass* c : row_->ann_classes()) {
59 if (!c->visible)
60 all_ann_classes_enabled = false;
61 else
62 all_ann_classes_disabled = false;
63 if (c->id > max_ann_class_id)
64 max_ann_class_id = c->id;
65 }
66
67 if (all_ann_classes_enabled) {
68 // No filtering, send everyting out as-is
5a9146ac 69 dest.reserve(dest.size() + annotations_.size());
6a26fc44
SA
70 for (const auto& annotation : annotations_)
71 if ((annotation.end_sample() > start_sample) &&
72 (annotation.start_sample() <= end_sample))
5a9146ac 73 dest.push_back(&annotation);
6a26fc44
SA
74 } else {
75 if (!all_ann_classes_disabled) {
76 // Filter out invisible annotation classes
77 vector<size_t> class_visible;
78 class_visible.resize(max_ann_class_id + 1, 0);
79 for (AnnotationClass* c : row_->ann_classes())
80 if (c->visible)
81 class_visible[c->id] = 1;
82
5a9146ac 83 dest.reserve(dest.size() + annotations_.size());
6a26fc44 84 for (const auto& annotation : annotations_)
81dc0221
SA
85 if ((class_visible[annotation.ann_class()]) &&
86 (annotation.end_sample() > start_sample) &&
87 (annotation.start_sample() <= end_sample))
5a9146ac 88 dest.push_back(&annotation);
6a26fc44
SA
89 }
90 }
f9101a91
JH
91}
92
6a26fc44 93void RowData::emplace_annotation(srd_proto_data *pdata)
f9101a91 94{
5a9146ac
SA
95 // We insert the annotation in a way so that the annotation list
96 // is sorted by start sample. Otherwise, we'd have to sort when
97 // painting, which is expensive
98
99 if (pdata->start_sample < prev_ann_start_sample_) {
100 // Find location to insert the annotation at
101
102 auto it = annotations_.end();
103 do {
104 it--;
105 } while ((it->start_sample() > pdata->start_sample) && (it != annotations_.begin()));
106
107 // Allow inserting at the front
108 if (it != annotations_.begin())
109 it++;
110
111 annotations_.insert(it, Annotation(pdata, row_));
112 } else {
113 annotations_.emplace_back(pdata, row_);
114 prev_ann_start_sample_ = pdata->start_sample;
115 }
f9101a91
JH
116}
117
870ea3db
UH
118} // namespace decode
119} // namespace data
120} // namespace pv