From: Joel Holdsworth Date: Tue, 20 May 2014 21:15:50 +0000 (+0100) Subject: Replaced BOOST_FOREACH with C++11 range-based for loops X-Git-Tag: pulseview-0.3.0~613 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d9aecf1fcd9af471db3b59de7efc65b9632a6d79;p=pulseview.git Replaced BOOST_FOREACH with C++11 range-based for loops --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 21ddb5fb..c7430432 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include "analog.h" #include "analogsnapshot.h" @@ -53,7 +51,7 @@ void Analog::clear() uint64_t Analog::get_max_sample_count() const { uint64_t l = 0; - BOOST_FOREACH(const boost::shared_ptr s, _snapshots) { + for (const boost::shared_ptr s : _snapshots) { assert(s); l = max(l, s->get_sample_count()); } diff --git a/pv/data/analogsnapshot.cpp b/pv/data/analogsnapshot.cpp index 4d4f5d67..ab968cf7 100644 --- a/pv/data/analogsnapshot.cpp +++ b/pv/data/analogsnapshot.cpp @@ -27,8 +27,6 @@ #include -#include - #include "analogsnapshot.h" using boost::lock_guard; @@ -59,7 +57,7 @@ AnalogSnapshot::AnalogSnapshot(const uint64_t expected_num_samples) : AnalogSnapshot::~AnalogSnapshot() { lock_guard lock(_mutex); - BOOST_FOREACH(Envelope &e, _envelope_levels) + for (Envelope &e : _envelope_levels) free(e.samples); } diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index f82d3ecc..1cb7d4ff 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -20,7 +20,6 @@ #include -#include #include #include @@ -126,7 +125,7 @@ std::vector DecoderStack::get_visible_rows() const vector rows; - BOOST_FOREACH (const shared_ptr &dec, _stack) + for (const shared_ptr &dec : _stack) { assert(dec); if (!dec->shown()) @@ -194,7 +193,7 @@ void DecoderStack::begin_decode() clear(); // Check that all decoders have the required channels - BOOST_FOREACH(const shared_ptr &dec, _stack) + for (const shared_ptr &dec : _stack) if (!dec->have_required_probes()) { _error_message = tr("One or more required channels " "have not been specified"); @@ -202,7 +201,7 @@ void DecoderStack::begin_decode() } // Add classes - BOOST_FOREACH (const shared_ptr &dec, _stack) + for (const shared_ptr &dec : _stack) { assert(dec); const srd_decoder *const decc = dec->decoder(); @@ -235,7 +234,7 @@ void DecoderStack::begin_decode() // We get the logic data of the first channel in the list. // This works because we are currently assuming all // LogicSignals have the same data/snapshot - BOOST_FOREACH (const shared_ptr &dec, _stack) + for (const shared_ptr &dec : _stack) if (dec && !dec->channels().empty() && ((logic_signal = (*dec->channels().begin()).second)) && ((data = logic_signal->logic_data()))) @@ -336,7 +335,7 @@ void DecoderStack::decode_proc() // Create the decoders const unsigned int unit_size = _snapshot->unit_size(); - BOOST_FOREACH(const shared_ptr &dec, _stack) + for (const shared_ptr &dec : _stack) { srd_decoder_inst *const di = dec->create_decoder_inst(session, unit_size); diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 167c79bd..9bcfd0a3 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include "logic.h" #include "logicsnapshot.h" @@ -61,7 +59,7 @@ void Logic::clear() uint64_t Logic::get_max_sample_count() const { uint64_t l = 0; - BOOST_FOREACH(boost::shared_ptr s, _snapshots) { + for (boost::shared_ptr s : _snapshots) { assert(s); l = max(l, s->get_sample_count()); } diff --git a/pv/data/logicsnapshot.cpp b/pv/data/logicsnapshot.cpp index 797a00bc..f896ed17 100644 --- a/pv/data/logicsnapshot.cpp +++ b/pv/data/logicsnapshot.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include "config.h" #include "logicsnapshot.h" @@ -59,7 +57,7 @@ LogicSnapshot::LogicSnapshot(const sr_datafeed_logic &logic, LogicSnapshot::~LogicSnapshot() { lock_guard lock(_mutex); - BOOST_FOREACH(MipMapLevel &l, _mip_map) + for (MipMapLevel &l : _mip_map) free(l.data); } diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 7a986c5a..6b07b991 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -26,8 +26,6 @@ #include #include -#include - #include using boost::shared_ptr; @@ -108,7 +106,7 @@ void DeviceManager::init_drivers() void DeviceManager::release_devices() { // Release all the used devices - BOOST_FOREACH(shared_ptr dev, _devices) { + for (shared_ptr dev : _devices) { assert(dev); dev->release(); } @@ -129,7 +127,7 @@ void DeviceManager::scan_all_drivers() void DeviceManager::release_driver(struct sr_dev_driver *const driver) { - BOOST_FOREACH(shared_ptr dev, _devices) { + for (shared_ptr dev : _devices) { assert(dev); if(dev->dev_inst()->driver == driver) dev->release(); diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp index 1dd8c507..c5535d87 100644 --- a/pv/dialogs/connect.cpp +++ b/pv/dialogs/connect.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include #include "connect.h" @@ -174,7 +172,7 @@ void Connect::scan_pressed() g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts); - BOOST_FOREACH(shared_ptr dev_inst, devices) + for (shared_ptr dev_inst : devices) { assert(dev_inst); const sr_dev_inst *const sdi = dev_inst->dev_inst(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index ec87ee05..26890603 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -23,7 +23,6 @@ #endif #include -#include #include #include diff --git a/pv/popups/deviceoptions.cpp b/pv/popups/deviceoptions.cpp index 13055fc0..353dfcfe 100644 --- a/pv/popups/deviceoptions.cpp +++ b/pv/popups/deviceoptions.cpp @@ -20,8 +20,6 @@ #include "deviceoptions.h" -#include - #include #include diff --git a/pv/popups/probes.cpp b/pv/popups/probes.cpp index 8683ab24..ada4d9a0 100644 --- a/pv/popups/probes.cpp +++ b/pv/popups/probes.cpp @@ -20,8 +20,6 @@ #include -#include - #include #include #include @@ -65,7 +63,7 @@ Probes::Probes(SigSession &session, QWidget *parent) : // Collect a set of signals map > signal_map; const vector< shared_ptr > sigs = _session.get_signals(); - BOOST_FOREACH(const shared_ptr &sig, sigs) + for (const shared_ptr &sig : sigs) signal_map[sig->probe()] = sig; // Populate channel groups @@ -185,7 +183,7 @@ QGridLayout* Probes::create_channel_group_grid( int row = 0, col = 0; QGridLayout *const grid = new QGridLayout(); - BOOST_FOREACH(const shared_ptr& sig, sigs) + for (const shared_ptr& sig : sigs) { assert(sig); diff --git a/pv/prop/binding/binding.cpp b/pv/prop/binding/binding.cpp index 3a6c73fb..1a5eb5ec 100644 --- a/pv/prop/binding/binding.cpp +++ b/pv/prop/binding/binding.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include #include @@ -39,7 +37,7 @@ const std::vector< boost::shared_ptr >& Binding::properties() void Binding::commit() { - BOOST_FOREACH(shared_ptr p, _properties) { + for (shared_ptr p : _properties) { assert(p); p->commit(); } @@ -50,7 +48,7 @@ void Binding::add_properties_to_form(QFormLayout *layout, { assert(layout); - BOOST_FOREACH(shared_ptr p, _properties) + for (shared_ptr p : _properties) { assert(p); diff --git a/pv/prop/binding/decoderoptions.cpp b/pv/prop/binding/decoderoptions.cpp index 6e0630c0..930e1f0a 100644 --- a/pv/prop/binding/decoderoptions.cpp +++ b/pv/prop/binding/decoderoptions.cpp @@ -23,7 +23,6 @@ #include "decoderoptions.h" #include -#include #include #include diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 6948ced1..282b7ec5 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -43,8 +43,6 @@ #include -#include - #include #include @@ -137,7 +135,7 @@ void SigSession::set_default_device() default_device = devices.front(); // Try and find the demo device and select that by default - BOOST_FOREACH (shared_ptr dev, devices) + for (shared_ptr dev : devices) if (strcmp(dev->dev_inst()->driver->name, "demo") == 0) { default_device = dev; @@ -211,7 +209,7 @@ set< shared_ptr > SigSession::get_data() const { lock_guard lock(_signals_mutex); set< shared_ptr > data; - BOOST_FOREACH(const shared_ptr sig, _signals) { + for (const shared_ptr sig : _signals) { assert(sig); data.insert(sig->data()); } @@ -247,8 +245,8 @@ bool SigSession::add_decoder(srd_decoder *const dec) all_probes.push_back((const srd_channel*)i->data); // Auto select the initial probes - BOOST_FOREACH(const srd_channel *pdch, all_probes) - BOOST_FOREACH(shared_ptr s, _signals) + for (const srd_channel *pdch : all_probes) + for (shared_ptr s : _signals) { shared_ptr l = dynamic_pointer_cast(s); @@ -399,7 +397,7 @@ shared_ptr SigSession::signal_from_probe( const sr_channel *probe) const { lock_guard lock(_signals_mutex); - BOOST_FOREACH(shared_ptr sig, _signals) { + for (shared_ptr sig : _signals) { assert(sig); if (sig->probe() == probe) return sig; @@ -428,7 +426,7 @@ void SigSession::read_sample_rate(const sr_dev_inst *const sdi) // Set the sample rate of all data const set< shared_ptr > data_set = get_data(); - BOOST_FOREACH(shared_ptr data, data_set) { + for (shared_ptr data : data_set) { assert(data); data->set_samplerate(sample_rate); } diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 6d419f74..367b9b2e 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -22,8 +22,6 @@ #include -#include - #include #include #include @@ -114,7 +112,7 @@ void SamplingBar::set_device_list( _device_selector.clear(); _device_selector_map.clear(); - BOOST_FOREACH (shared_ptr dev_inst, devices) { + for (shared_ptr dev_inst : devices) { assert(dev_inst); const string title = dev_inst->format_device_title(); const sr_dev_inst *sdi = dev_inst->dev_inst(); diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index f8217510..e2c21184 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -24,7 +24,6 @@ extern "C" { #include -#include #include #include @@ -214,7 +213,7 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) _decoder_stack->get_annotation_subset(annotations, row, start_sample, end_sample); if (!annotations.empty()) { - BOOST_FOREACH(const Annotation &a, annotations) + for (const Annotation &a : annotations) draw_annotation(a, p, get_text_colour(), annotation_height, left, right, samples_per_pixel, pixels_offset, y, @@ -429,7 +428,7 @@ void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p, QString best_annotation; int best_width = 0; - BOOST_FOREACH(const QString &a, annotations) { + for (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; @@ -480,7 +479,7 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, // We get the logic data of the first probe in the list. // This works because we are currently assuming all // LogicSignals have the same data/snapshot - BOOST_FOREACH (const shared_ptr &dec, stack) + for (const shared_ptr &dec : stack) if (dec && !dec->channels().empty() && ((logic_signal = (*dec->channels().begin()).second)) && ((data = logic_signal->logic_data()))) @@ -623,7 +622,7 @@ void DecodeTrace::commit_decoder_probes(shared_ptr &dec) map > probe_map; const vector< shared_ptr > sigs = _session.get_signals(); - BOOST_FOREACH(const ProbeSelector &s, _probe_selectors) + for (const ProbeSelector &s : _probe_selectors) { if(s._decoder != dec) break; @@ -632,7 +631,7 @@ void DecodeTrace::commit_decoder_probes(shared_ptr &dec) (LogicSignal*)s._combo->itemData( s._combo->currentIndex()).value(); - BOOST_FOREACH(shared_ptr sig, sigs) + for (shared_ptr sig : sigs) if(sig.get() == selection) { probe_map[s._pdch] = dynamic_pointer_cast(sig); @@ -646,8 +645,7 @@ void DecodeTrace::commit_decoder_probes(shared_ptr &dec) void DecodeTrace::commit_probes() { assert(_decoder_stack); - BOOST_FOREACH(shared_ptr dec, - _decoder_stack->stack()) + for (shared_ptr dec : _decoder_stack->stack()) commit_decoder_probes(dec); _decoder_stack->begin_decode(); diff --git a/pv/view/header.cpp b/pv/view/header.cpp index a00efb14..7c68f302 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -26,8 +26,6 @@ #include -#include - #include #include #include @@ -70,7 +68,7 @@ QSize Header::sizeHint() const int max_width = 0; const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(shared_ptr t, traces) { + for (shared_ptr t : traces) { assert(t); if (t->enabled()) { @@ -86,7 +84,7 @@ shared_ptr Header::get_mouse_over_trace(const QPoint &pt) const int w = width(); const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) { assert(t); if (t->pt_in_label_rect(0, w, pt)) @@ -99,7 +97,7 @@ shared_ptr Header::get_mouse_over_trace(const QPoint &pt) void Header::clear_selection() { const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(const shared_ptr t, traces) { + for (const shared_ptr t : traces) { assert(t); t->select(false); } @@ -116,7 +114,7 @@ void Header::paintEvent(QPaintEvent*) painter.setRenderHint(QPainter::Antialiasing); const bool dragging = !_drag_traces.empty(); - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) { assert(t); @@ -138,7 +136,7 @@ void Header::mousePressEvent(QMouseEvent *event) _mouse_down_point = event->pos(); // Save the offsets of any signals which will be dragged - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) if (t->selected()) _drag_traces.push_back( make_pair(t, t->get_v_offset())); @@ -168,7 +166,7 @@ void Header::mousePressEvent(QMouseEvent *event) if (~QApplication::keyboardModifiers() & Qt::ControlModifier) { // Unselect all other signals because the Ctrl is not // pressed - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) if (t != mouse_over_trace) t->select(false); } @@ -268,7 +266,7 @@ void Header::keyPressEvent(QKeyEvent *e) case Qt::Key_Delete: { const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) if (t->selected()) t->delete_pressed(); break; @@ -279,7 +277,7 @@ void Header::keyPressEvent(QKeyEvent *e) void Header::on_signals_changed() { const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(shared_ptr t, traces) { + for (shared_ptr t : traces) { assert(t); connect(t.get(), SIGNAL(visibility_changed()), this, SLOT(on_trace_changed())); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 3d3b8eb2..0ebfea1e 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -26,8 +26,6 @@ #include #include -#include - #include #include #include @@ -192,7 +190,7 @@ void View::zoom_one_to_one() return; double samplerate = 0.0; - BOOST_FOREACH(const shared_ptr d, visible_data) { + for (const shared_ptr d : visible_data) { assert(d); samplerate = max(samplerate, d->samplerate()); } @@ -248,7 +246,7 @@ list > View::selected_items() const // List the selected signals const vector< shared_ptr > traces(get_traces()); - BOOST_FOREACH (shared_ptr t, traces) { + for (shared_ptr t : traces) { assert(t); if (t->selected()) items.push_back(t); @@ -270,7 +268,7 @@ set< shared_ptr > View::get_visible_data() const // Make a set of all the visible data objects set< shared_ptr > visible_data; - BOOST_FOREACH(const shared_ptr sig, sigs) + for (const shared_ptr sig : sigs) if (sig->enabled()) visible_data.insert(sig->data()); @@ -284,7 +282,7 @@ pair View::get_time_extents() const return make_pair(0.0, 0.0); double left_time = DBL_MAX, right_time = DBL_MIN; - BOOST_FOREACH(const shared_ptr d, visible_data) + for (const shared_ptr d : visible_data) { const double start_time = d->get_start_time(); double samplerate = d->samplerate(); @@ -340,11 +338,11 @@ void View::normalize_layout() const vector< shared_ptr > traces(get_traces()); int v_min = INT_MAX; - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) v_min = min(t->get_v_offset(), v_min); const int delta = -min(v_min, 0); - BOOST_FOREACH(shared_ptr t, traces) + for (shared_ptr t : traces) t->set_v_offset(t->get_v_offset() + delta); verticalScrollBar()->setSliderPosition(_v_offset + delta); @@ -499,7 +497,7 @@ void View::signals_changed() { int offset = SignalMargin + SignalHeight; const vector< shared_ptr > traces(get_traces()); - BOOST_FOREACH(shared_ptr t, traces) { + for (shared_ptr t : traces) { t->set_view(this); t->set_v_offset(offset); offset += SignalHeight + 2 * SignalMargin; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 3b06cf9e..cdae779e 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -26,8 +26,6 @@ #include -#include - using boost::shared_ptr; using std::max; using std::min; @@ -59,7 +57,7 @@ int Viewport::get_total_height() const { int h = 0; const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(const shared_ptr t, traces) { + for (const shared_ptr t : traces) { assert(t); h = max(t->get_v_offset() + View::SignalHeight, h); } @@ -78,16 +76,16 @@ void Viewport::paintEvent(QPaintEvent*) _view.cursors().draw_viewport_background(p, rect()); // Plot the signal - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) { assert(t); t->paint_back(p, 0, width()); } - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) t->paint_mid(p, 0, width()); - BOOST_FOREACH(const shared_ptr t, traces) + for (const shared_ptr t : traces) t->paint_fore(p, 0, width()); if (_view.cursors_shown()) @@ -145,7 +143,7 @@ void Viewport::wheelEvent(QWheelEvent *event) void Viewport::on_signals_changed() { const vector< shared_ptr > traces(_view.get_traces()); - BOOST_FOREACH(shared_ptr t, traces) { + for (shared_ptr t : traces) { assert(t); connect(t.get(), SIGNAL(visibility_changed()), this, SLOT(update()));