From: Joel Holdsworth Date: Sat, 24 May 2014 10:17:27 +0000 (+0100) Subject: Replaced boost::bind with C++11 lambdas X-Git-Tag: pulseview-0.3.0~608 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=6db7315814ee9d2f92d4b326be7c5b9e6e4b789b;p=pulseview.git Replaced boost::bind with C++11 lambdas --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 42f79bbc..145d7d99 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -22,8 +22,6 @@ #include #endif -#include - #include #include @@ -324,8 +322,8 @@ void MainWindow::load_file(QString file_name) update_device_list(); - _session.start_capture(boost::bind(&MainWindow::session_error, this, - errorMessage, infoMessage)); + _session.start_capture([&, errorMessage, infoMessage](QString) { + session_error(errorMessage, infoMessage); }); } void MainWindow::show_session_error( @@ -439,9 +437,8 @@ void MainWindow::run_stop() { switch(_session.get_capture_state()) { case SigSession::Stopped: - _session.start_capture( - boost::bind(&MainWindow::session_error, this, - QString("Capture failed"), _1)); + _session.start_capture([&](QString message) { + session_error("Capture failed", message); }); break; case SigSession::AwaitingTrigger: diff --git a/pv/prop/binding/decoderoptions.cpp b/pv/prop/binding/decoderoptions.cpp index 0e44386e..c5278c75 100644 --- a/pv/prop/binding/decoderoptions.cpp +++ b/pv/prop/binding/decoderoptions.cpp @@ -22,7 +22,6 @@ #include "decoderoptions.h" -#include #include #include @@ -32,7 +31,6 @@ #include #include -using boost::bind; using boost::none; using std::make_pair; using std::map; @@ -63,24 +61,24 @@ DecoderOptions::DecoderOptions( const QString name = QString::fromUtf8(opt->desc); - const Property::Getter getter = bind( - &DecoderOptions::getter, this, opt->id); - const Property::Setter setter = bind( - &DecoderOptions::setter, this, opt->id, _1); + const Property::Getter get = [&, opt]() { + return getter(opt->id); }; + const Property::Setter set = [&, opt](GVariant *value) { + setter(opt->id, value); }; shared_ptr prop; if (opt->values) - prop = bind_enum(name, opt, getter, setter); + prop = bind_enum(name, opt, get, set); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("d"))) prop = shared_ptr(new Double(name, 2, "", - none, none, getter, setter)); + none, none, get, set)); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x"))) prop = shared_ptr( - new Int(name, "", none, getter, setter)); + new Int(name, "", none, get, set)); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) prop = shared_ptr( - new String(name, getter, setter)); + new String(name, get, set)); else continue; diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index 39e12816..a2a74170 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - #include #include @@ -34,9 +32,8 @@ #include -using boost::bind; -using std::function; using boost::optional; +using std::function; using std::make_pair; using std::pair; using std::shared_ptr; @@ -75,6 +72,11 @@ DeviceOptions::DeviceOptions(shared_ptr dev_inst, const QString name = QString::fromUtf8(info->name); + const Property::Getter get = [&, key]() { + return _dev_inst->get_config(_group, key); }; + const Property::Setter set = [&, key](GVariant *value) { + _dev_inst->set_config(_group, key, value); }; + switch(key) { case SR_CONF_SAMPLERATE: @@ -83,7 +85,8 @@ DeviceOptions::DeviceOptions(shared_ptr dev_inst, break; case SR_CONF_CAPTURE_RATIO: - bind_int(name, key, "%", pair(0, 100)); + bind_int(name, "%", pair(0, 100), + get, set); break; case SR_CONF_PATTERN_MODE: @@ -93,24 +96,26 @@ DeviceOptions::DeviceOptions(shared_ptr dev_inst, case SR_CONF_FILTER: case SR_CONF_COUPLING: case SR_CONF_CLOCK_EDGE: - bind_enum(name, key, gvar_list); + bind_enum(name, key, gvar_list, get, set); break; case SR_CONF_EXTERNAL_CLOCK: case SR_CONF_RLE: - bind_bool(name, key); + bind_bool(name, get, set); break; case SR_CONF_TIMEBASE: - bind_enum(name, key, gvar_list, print_timebase); + bind_enum(name, key, gvar_list, + get, set, print_timebase); break; case SR_CONF_VDIV: - bind_enum(name, key, gvar_list, print_vdiv); + bind_enum(name, key, gvar_list, get, set, print_vdiv); break; case SR_CONF_VOLTAGE_THRESHOLD: - bind_enum(name, key, gvar_list, print_voltage_threshold); + bind_enum(name, key, gvar_list, + get, set, print_voltage_threshold); break; } @@ -120,17 +125,17 @@ DeviceOptions::DeviceOptions(shared_ptr dev_inst, g_variant_unref(gvar_opts); } -void DeviceOptions::bind_bool(const QString &name, int key) +void DeviceOptions::bind_bool(const QString &name, + Property::Getter getter, Property::Setter setter) { assert(_dev_inst); - _properties.push_back(shared_ptr(new Bool(name, - bind(&device::DevInst::get_config, _dev_inst, _group, key), - bind(&device::DevInst::set_config, _dev_inst, - _group, key, _1)))); + _properties.push_back(shared_ptr(new Bool( + name, getter, setter))); } void DeviceOptions::bind_enum(const QString &name, int key, - GVariant *const gvar_list, function printer) + GVariant *const gvar_list, Property::Getter getter, + Property::Setter setter, function printer) { GVariant *gvar; GVariantIter iter; @@ -148,19 +153,17 @@ void DeviceOptions::bind_enum(const QString &name, int key, values.push_back(make_pair(gvar, printer(gvar))); _properties.push_back(shared_ptr(new Enum(name, values, - bind(&device::DevInst::get_config, _dev_inst, _group, key), - bind(&device::DevInst::set_config, _dev_inst, - _group, key, _1)))); + getter, setter))); } -void DeviceOptions::bind_int(const QString &name, int key, QString suffix, - optional< std::pair > range) +void DeviceOptions::bind_int(const QString &name, QString suffix, + optional< std::pair > range, + Property::Getter getter, Property::Setter setter) { assert(_dev_inst); _properties.push_back(shared_ptr(new Int(name, suffix, range, - bind(&device::DevInst::get_config, _dev_inst, _group, key), - bind(&device::DevInst::set_config, _dev_inst, _group, key, _1)))); + getter, setter))); } QString DeviceOptions::print_timebase(GVariant *const gvar) diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index 1e422f67..a1efd06a 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -25,9 +25,11 @@ #include +#include + #include "binding.h" -#include +#include struct sr_dev_inst; struct sr_channel_group; @@ -48,12 +50,15 @@ public: const sr_channel_group *group = NULL); private: - void bind_bool(const QString &name, int key); + void bind_bool(const QString &name, + Property::Getter getter, Property::Setter setter); void bind_enum(const QString &name, int key, GVariant *const gvar_list, + Property::Getter getter, Property::Setter setter, std::function printer = print_gvariant); - void bind_int(const QString &name, int key, QString suffix, - boost::optional< std::pair > range); + void bind_int(const QString &name, QString suffix, + boost::optional< std::pair > range, + Property::Getter getter, Property::Setter setter); static QString print_timebase(GVariant *const gvar); static QString print_vdiv(GVariant *const gvar);