]> sigrok.org Git - pulseview.git/blobdiff - pv/data/decode/rowdata.hpp
Fix #811 by using a hashed annotation text backing storage
[pulseview.git] / pv / data / decode / rowdata.hpp
index 3c967ff70b1e8998d60903c39bcc35e2e8fcc2ce..f01aa3ca81c2f71a24c61dc71f7b1d1ba67f7139 100644 (file)
 #ifndef PULSEVIEW_PV_DATA_DECODE_ROWDATA_HPP
 #define PULSEVIEW_PV_DATA_DECODE_ROWDATA_HPP
 
+#include <unordered_map>
 #include <vector>
 
+#include <QHash>
+#include <QString>
+
 #include <libsigrokdecode/libsigrokdecode.h>
 
-#include "annotation.hpp"
+#include <pv/data/decode/annotation.hpp>
+
+using std::deque;
+using std::unordered_map;
 
-using std::vector;
+namespace std {
+  template<> struct hash<QString> {
+    std::size_t operator()(const QString& s) const noexcept {
+      return (size_t) qHash(s);
+    }
+  };
+}
 
 namespace pv {
 namespace data {
@@ -37,9 +50,10 @@ class Row;
 class RowData
 {
 public:
-       RowData() = default;
+       RowData(Row* row);
+
+       const Row* row() const;
 
-public:
        uint64_t get_max_sample() const;
 
        uint64_t get_annotation_count() const;
@@ -49,14 +63,16 @@ public:
         * Note: The annotations are unsorted and only annotations that fully
         * fit into the sample range are considered.
         */
-       void get_annotation_subset(
-               vector<pv::data::decode::Annotation> &dest,
+       void get_annotation_subset(deque<const pv::data::decode::Annotation*> &dest,
                uint64_t start_sample, uint64_t end_sample) const;
 
-       void emplace_annotation(srd_proto_data *pdata, const Row *row);
+       const Annotation* emplace_annotation(srd_proto_data *pdata);
 
 private:
-       vector<Annotation> annotations_;
+       deque<Annotation> annotations_;
+       unordered_map<QString, vector<QString> > ann_texts_;  // unordered_map since pointers must not change
+       Row* row_;
+       uint64_t prev_ann_start_sample_;
 };
 
 }  // namespace decode