]> sigrok.org Git - pulseview.git/commitdiff
Replaced boost::bind with C++11 lambdas
authorJoel Holdsworth <redacted>
Sat, 24 May 2014 10:17:27 +0000 (11:17 +0100)
committerJoel Holdsworth <redacted>
Sat, 24 May 2014 10:17:27 +0000 (11:17 +0100)
pv/mainwindow.cpp
pv/prop/binding/decoderoptions.cpp
pv/prop/binding/deviceoptions.cpp
pv/prop/binding/deviceoptions.h

index 42f79bbc876757b3a56b2bd200d40789eac23305..145d7d997db6cfe089d1fc18b4bafd3874e9e22c 100644 (file)
@@ -22,8 +22,6 @@
 #include <libsigrokdecode/libsigrokdecode.h>
 #endif
 
 #include <libsigrokdecode/libsigrokdecode.h>
 #endif
 
-#include <boost/bind.hpp>
-
 #include <algorithm>
 #include <iterator>
 
 #include <algorithm>
 #include <iterator>
 
@@ -324,8 +322,8 @@ void MainWindow::load_file(QString file_name)
 
        update_device_list();
 
 
        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(
 }
 
 void MainWindow::show_session_error(
@@ -439,9 +437,8 @@ void MainWindow::run_stop()
 {
        switch(_session.get_capture_state()) {
        case SigSession::Stopped:
 {
        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:
                break;
 
        case SigSession::AwaitingTrigger:
index 0e44386eafa546781244af06bdfe33d004b4e770..c5278c75fbb82583ba7082e4d4dc04ef4bf502f6 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "decoderoptions.h"
 
 
 #include "decoderoptions.h"
 
-#include <boost/bind.hpp>
 #include <boost/none_t.hpp>
 
 #include <pv/data/decoderstack.h>
 #include <boost/none_t.hpp>
 
 #include <pv/data/decoderstack.h>
@@ -32,7 +31,6 @@
 #include <pv/prop/int.h>
 #include <pv/prop/string.h>
 
 #include <pv/prop/int.h>
 #include <pv/prop/string.h>
 
-using boost::bind;
 using boost::none;
 using std::make_pair;
 using std::map;
 using boost::none;
 using std::make_pair;
 using std::map;
@@ -63,24 +61,24 @@ DecoderOptions::DecoderOptions(
 
                const QString name = QString::fromUtf8(opt->desc);
 
 
                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<Property> prop;
 
                if (opt->values)
 
                shared_ptr<Property> 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<Property>(new Double(name, 2, "",
                else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("d")))
                        prop = shared_ptr<Property>(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<Property>(
                else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
                        prop = shared_ptr<Property>(
-                               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<Property>(
                else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s")))
                        prop = shared_ptr<Property>(
-                               new String(name, getter, setter));
+                               new String(name, get, set));
                else
                        continue;
 
                else
                        continue;
 
index 39e12816fd2e3243c22bfeaaea4ca0410235b179..a2a741709145b6529625d77218623a1d5b27c7cd 100644 (file)
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#include <boost/bind.hpp>
-
 #include <stdint.h>
 
 #include <QDebug>
 #include <stdint.h>
 
 #include <QDebug>
@@ -34,9 +32,8 @@
 
 #include <libsigrok/libsigrok.h>
 
 
 #include <libsigrok/libsigrok.h>
 
-using boost::bind;
-using std::function;
 using boost::optional;
 using boost::optional;
+using std::function;
 using std::make_pair;
 using std::pair;
 using std::shared_ptr;
 using std::make_pair;
 using std::pair;
 using std::shared_ptr;
@@ -75,6 +72,11 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst,
 
                const QString name = QString::fromUtf8(info->name);
 
 
                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:
                switch(key)
                {
                case SR_CONF_SAMPLERATE:
@@ -83,7 +85,8 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst,
                        break;
 
                case SR_CONF_CAPTURE_RATIO:
                        break;
 
                case SR_CONF_CAPTURE_RATIO:
-                       bind_int(name, key, "%", pair<int64_t, int64_t>(0, 100));
+                       bind_int(name, "%", pair<int64_t, int64_t>(0, 100),
+                               get, set);
                        break;
 
                case SR_CONF_PATTERN_MODE:
                        break;
 
                case SR_CONF_PATTERN_MODE:
@@ -93,24 +96,26 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst,
                case SR_CONF_FILTER:
                case SR_CONF_COUPLING:
                case SR_CONF_CLOCK_EDGE:
                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:
                        break;
 
                case SR_CONF_EXTERNAL_CLOCK:
                case SR_CONF_RLE:
-                       bind_bool(name, key);
+                       bind_bool(name, get, set);
                        break;
 
                case SR_CONF_TIMEBASE:
                        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:
                        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:
                        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;
                }
 
                        break;
                }
 
@@ -120,17 +125,17 @@ DeviceOptions::DeviceOptions(shared_ptr<pv::device::DevInst> dev_inst,
        g_variant_unref(gvar_opts);
 }
 
        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);
 {
        assert(_dev_inst);
-       _properties.push_back(shared_ptr<Property>(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<Property>(new Bool(
+               name, getter, setter)));
 }
 
 void DeviceOptions::bind_enum(const QString &name, int key,
 }
 
 void DeviceOptions::bind_enum(const QString &name, int key,
-       GVariant *const gvar_list, function<QString (GVariant*)> printer)
+       GVariant *const gvar_list, Property::Getter getter,
+       Property::Setter setter, function<QString (GVariant*)> printer)
 {
        GVariant *gvar;
        GVariantIter iter;
 {
        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<Property>(new Enum(name, values,
                values.push_back(make_pair(gvar, printer(gvar)));
 
        _properties.push_back(shared_ptr<Property>(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<int64_t, int64_t> > range)
+void DeviceOptions::bind_int(const QString &name, QString suffix,
+       optional< std::pair<int64_t, int64_t> > range,
+       Property::Getter getter, Property::Setter setter)
 {
        assert(_dev_inst);
 
        _properties.push_back(shared_ptr<Property>(new Int(name, suffix, range,
 {
        assert(_dev_inst);
 
        _properties.push_back(shared_ptr<Property>(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)
 }
 
 QString DeviceOptions::print_timebase(GVariant *const gvar)
index 1e422f67161d48d8349970cc4f04a52499073cae..a1efd06a3fbc0bed6e42aec944f3315d1b7e3c49 100644 (file)
 
 #include <QString>
 
 
 #include <QString>
 
+#include <glib.h>
+
 #include "binding.h"
 
 #include "binding.h"
 
-#include <glib.h>
+#include <pv/prop/property.h>
 
 struct sr_dev_inst;
 struct sr_channel_group;
 
 struct sr_dev_inst;
 struct sr_channel_group;
@@ -48,12 +50,15 @@ public:
                const sr_channel_group *group = NULL);
 
 private:
                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,
        void bind_enum(const QString &name, int key,
                GVariant *const gvar_list,
+               Property::Getter getter, Property::Setter setter,
                std::function<QString (GVariant*)> printer = print_gvariant);
                std::function<QString (GVariant*)> printer = print_gvariant);
-       void bind_int(const QString &name, int key, QString suffix,
-               boost::optional< std::pair<int64_t, int64_t> > range);
+       void bind_int(const QString &name, QString suffix,
+               boost::optional< std::pair<int64_t, int64_t> > range,
+               Property::Getter getter, Property::Setter setter);
 
        static QString print_timebase(GVariant *const gvar);
        static QString print_vdiv(GVariant *const gvar);
 
        static QString print_timebase(GVariant *const gvar);
        static QString print_vdiv(GVariant *const gvar);