]> sigrok.org Git - pulseview.git/commitdiff
Store annotations as objects emplaced in the vector
authorJoel Holdsworth <redacted>
Wed, 25 Dec 2013 23:41:12 +0000 (23:41 +0000)
committerJoel Holdsworth <redacted>
Fri, 27 Dec 2013 15:19:14 +0000 (15:19 +0000)
Rather than as pointers to heap allocated objects.

pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/view/decode/annotation.cpp
pv/view/decode/annotation.h
pv/view/decodetrace.cpp

index 6d5e4e19440a4f154abb8fceb1e0824ccbf83b8f..e588ad6b9bf173be8791b5ee392b6c2f574659d4 100644 (file)
@@ -94,8 +94,7 @@ int64_t DecoderStack::samples_decoded() const
        return _samples_decoded;
 }
 
-const vector< shared_ptr<view::decode::Annotation> >
-       DecoderStack::annotations() const
+const vector<view::decode::Annotation> DecoderStack::annotations() const
 {
        lock_guard<mutex> lock(_mutex);
        return _annotations;
@@ -150,7 +149,7 @@ uint64_t DecoderStack::get_max_sample_count() const
 {
        if (_annotations.empty())
                return 0;
-       return _annotations.back()->end_sample();
+       return _annotations.back().end_sample();
 }
 
 void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
@@ -237,9 +236,8 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
 
        DecoderStack *const d = (DecoderStack*)decoder;
 
-       shared_ptr<Annotation> a(new Annotation(pdata));
        lock_guard<mutex> lock(d->_mutex);
-       d->_annotations.push_back(a);
+       d->_annotations.push_back(Annotation(pdata));
 
        d->new_decode_data();
 }
index dc656f91f7f9b503ff13a850cc35e0328a68a3f5..58dd887145c62cc6bb98dfa18d43c316112b649b 100644 (file)
@@ -78,8 +78,7 @@ public:
 
        int64_t samples_decoded() const;
 
-       const std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
-               annotations() const;
+       const std::vector<pv::view::decode::Annotation> annotations() const;
 
        QString error_message();
 
@@ -112,8 +111,7 @@ private:
 
        mutable boost::mutex _mutex;
        int64_t _samples_decoded;
-       std::vector< boost::shared_ptr<pv::view::decode::Annotation> >
-               _annotations;
+       std::vector<pv::view::decode::Annotation> _annotations;
        QString _error_message;
 
        boost::thread _decode_thread;
index 6a2f74a6bb2c23bdc7241890c025670f0bc1f81b..4a110e67c4d4814af8ca49414b9cf9a9e21a50a5 100644 (file)
@@ -81,7 +81,7 @@ uint64_t Annotation::end_sample() const
 
 void Annotation::paint(QPainter &p, QColor text_color, int h,
        int left, int right, double samples_per_pixel, double pixels_offset,
-       int y)
+       int y) const
 {
        const double start = _start_sample / samples_per_pixel -
                pixels_offset;
@@ -103,7 +103,7 @@ void Annotation::paint(QPainter &p, QColor text_color, int h,
 }
 
 void Annotation::draw_instant(QPainter &p, QColor fill, QColor outline,
-       QColor text_color, int h, double x, int y)
+       QColor text_color, int h, double x, int y) const
 {
        const QString text = _annotations.empty() ?
                QString() : _annotations.back();
@@ -120,7 +120,7 @@ void Annotation::draw_instant(QPainter &p, QColor fill, QColor outline,
 }
 
 void Annotation::draw_range(QPainter &p, QColor fill, QColor outline,
-       QColor text_color, int h, double start, double end, int y)
+       QColor text_color, int h, double start, double end, int y) const
 {
        const double top = y + .5 - h / 2;
        const double bottom = y + .5 + h / 2;
@@ -159,7 +159,7 @@ void Annotation::draw_range(QPainter &p, QColor fill, QColor outline,
        QString best_annotation;
        int best_width = 0;
 
-       BOOST_FOREACH(QString &a, _annotations) {
+       BOOST_FOREACH(const QString &a, _annotations) {
                const int w = p.boundingRect(QRectF(), 0, a).width();
                if (w <= rect.width() && w > best_width)
                        best_annotation = a, best_width = w;
index d0282114a21972c3eb53de8b253a55c5c5fd2556..94b7dc90c9fabfdb330c9d14f5105018f56612a4 100644 (file)
@@ -47,15 +47,15 @@ public:
 
        void paint(QPainter &p, QColor text_colour, int text_height, int left,
                int right, double samples_per_pixel, double pixels_offset,
-               int y);
+               int y) const;
 
 private:
        void draw_instant(QPainter &p, QColor fill, QColor outline,
-               QColor text_color, int h, double x, int y);
+               QColor text_color, int h, double x, int y) const;
 
        void draw_range(QPainter &p, QColor fill, QColor outline,
                QColor text_color, int h, double start,
-               double end, int y);
+               double end, int y) const;
 
 private:
        uint64_t _start_sample;
index 2d641827f13bbd8416f09baa62f74c18cdce5a47..e582d1a8e2042d1ba4d4f2dd1046940bd8067990 100644 (file)
@@ -135,12 +135,10 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
        const int y = get_y();
 
        assert(_decoder_stack);
-       vector< shared_ptr<Annotation> > annotations(_decoder_stack->annotations());
-       BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
-               assert(a);
-               a->paint(p, get_text_colour(), h, left, right,
+       vector<Annotation> annotations(_decoder_stack->annotations());
+       BOOST_FOREACH(const Annotation &a, annotations)
+               a.paint(p, get_text_colour(), h, left, right,
                        samples_per_pixel, pixels_offset, y);
-       }
 
        draw_unresolved_period(p, h, left, right,
                samples_per_pixel, pixels_offset);