]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decodesignal.cpp
Internal decoder class handling refactoring
[pulseview.git] / pv / data / decodesignal.cpp
index a6d4a9d603b23e0820a9a6a869658020e7787079..593af02fdd796348aac72d3b621fa13239cffa3f 100644 (file)
@@ -236,12 +236,11 @@ void DecodeSignal::begin_decode()
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
 
-                       const Row row(row_index++, decc, ann_row);
+                       const Row row(row_index++, dec.get(), ann_row);
 
                        for (const GSList *ll = ann_row->ann_classes;
                                ll; ll = ll->next)
-                               class_rows_[make_pair(decc,
-                                       GPOINTER_TO_INT(ll->data))] = row;
+                               class_rows_[make_pair(decc, GPOINTER_TO_INT(ll->data))] = row;
                }
        }
 
@@ -471,20 +470,37 @@ vector<Row> DecodeSignal::get_rows(bool visible_only) const
                int row_index = 0;
                // Add a row for the decoder if it doesn't have a row list
                if (!decc->annotation_rows)
-                       rows.emplace_back(row_index++, decc);
+                       rows.emplace_back(row_index++, dec.get());
 
                // Add the decoder rows
                for (const GSList *l = decc->annotation_rows; l; l = l->next) {
                        const srd_decoder_annotation_row *const ann_row =
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
-                       rows.emplace_back(row_index++, decc, ann_row);
+                       rows.emplace_back(row_index++, dec.get(), ann_row);
                }
        }
 
        return rows;
 }
 
+uint64_t DecodeSignal::get_annotation_count(const decode::Row &row,
+       uint32_t segment_id) const
+{
+       if (segment_id >= segments_.size())
+               return 0;
+
+       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())
+               return (*iter).second.get_annotation_count();
+
+       return 0;
+}
+
 void DecodeSignal::get_annotation_subset(
        vector<pv::data::decode::Annotation> &dest,
        const decode::Row &row, uint32_t segment_id, uint64_t start_sample,
@@ -496,8 +512,7 @@ void DecodeSignal::get_annotation_subset(
                return;
 
        const DecodeSegment *segment = &(segments_.at(segment_id));
-       const map<const decode::Row, decode::RowData> *rows =
-               &(segment->annotation_rows);
+       const map<const decode::Row, decode::RowData> *rows = &(segment->annotation_rows);
 
        const auto iter = rows->find(row);
        if (iter != rows->end())
@@ -510,7 +525,7 @@ void DecodeSignal::get_annotation_subset(
 {
        // Note: We put all vectors and lists on the heap, not the stack
 
-       const vector<Row> rows = get_rows(true);
+       const vector<Row> rows = get_rows();
 
        // Use forward_lists for faster merging
        forward_list<Annotation> *all_ann_list = new forward_list<Annotation>();
@@ -1370,7 +1385,7 @@ void DecodeSignal::create_decode_segment()
                int row_index = 0;
                // Add a row for the decoder if it doesn't have a row list
                if (!decc->annotation_rows)
-                       (segments_.back().annotation_rows)[Row(row_index++, decc)] =
+                       (segments_.back().annotation_rows)[Row(row_index++, dec.get())] =
                                decode::RowData();
 
                // Add the decoder rows
@@ -1379,11 +1394,10 @@ void DecodeSignal::create_decode_segment()
                                (srd_decoder_annotation_row *)l->data;
                        assert(ann_row);
 
-                       const Row row(row_index++, decc, ann_row);
+                       const Row row(row_index++, dec.get(), ann_row);
 
                        // Add a new empty row data object
-                       (segments_.back().annotation_rows)[row] =
-                               decode::RowData();
+                       (segments_.back().annotation_rows)[row] = decode::RowData();
                }
        }
 
@@ -1429,7 +1443,9 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa
                row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find((*r).second);
        else {
                // Failing that, use the decoder as a key
-               row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, decc));
+               for (const shared_ptr<decode::Decoder>& dec : ds->decoder_stack())
+                       if (dec->decoder() == decc)
+                               row_iter = ds->segments_.at(ds->current_segment_id_).annotation_rows.find(Row(0, dec.get()));
        }
 
        if (row_iter == ds->segments_.at(ds->current_segment_id_).annotation_rows.end()) {