]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/bindings.cpp
Streamline iterators and loop constructs
[libs/gui.git] / source / input / bindings.cpp
index 1d33292c57ca91f4d305d0ad73bce57e65c724bc..d6317d8627bdbffe0e2f31447a8dd1668697b908 100644 (file)
@@ -1,3 +1,4 @@
+#include <algorithm>
 #include <msp/strings/format.h>
 #include "bindings.h"
 #include "controlscheme.h"
@@ -11,12 +12,12 @@ vector<Device *> Bindings::resolve_devices(Device &dev) const
 {
        vector<Device *> resolved_devs;
        resolved_devs.reserve(devices.size());
-       for(vector<DeviceRef>::const_iterator i=devices.begin(); i!=devices.end(); ++i)
+       for(const DeviceRef &d: devices)
        {
-               if(i->type!=UNSPECIFIED)
-                       resolved_devs.push_back(dev.find_subdevice(i->type));
-               else if(!i->name.empty())
-                       resolved_devs.push_back(dev.find_subdevice(i->name));
+               if(d.type!=UNSPECIFIED)
+                       resolved_devs.push_back(dev.find_subdevice(d.type));
+               else if(!d.name.empty())
+                       resolved_devs.push_back(dev.find_subdevice(d.name));
                else
                        resolved_devs.push_back(0);
        }
@@ -26,23 +27,20 @@ vector<Device *> Bindings::resolve_devices(Device &dev) const
 bool Bindings::is_compatible(Device &dev) const
 {
        vector<Device *> resolved_devs = resolve_devices(dev);
-       for(vector<Device *>::const_iterator i=resolved_devs.begin(); i!=resolved_devs.end(); ++i)
-               if(!*i)
-                       return false;
-       return true;
+       return all_of(resolved_devs.begin(), resolved_devs.end(), [](Device *d) -> bool { return d; });
 }
 
 bool Bindings::apply_to(ControlScheme &control_scheme, Device &dev)
 {
        vector<Device *> resolved_devs = resolve_devices(dev);
        bool applied = false;
-       for(vector<Binding>::const_iterator i=bindings.begin(); i!=bindings.end(); ++i)
+       for(const Binding &b: bindings)
        {
-               Control *ctrl = control_scheme.find(i->control);
-               Device *bdev = (i->device<resolved_devs.size() ? resolved_devs[i->device] : 0);
+               Control *ctrl = control_scheme.find(b.control);
+               Device *bdev = (b.device<resolved_devs.size() ? resolved_devs[b.device] : 0);
                if(ctrl && bdev)
                {
-                       ctrl->set_source(*bdev, i->type, i->index);
+                       ctrl->set_source(*bdev, b.type, b.index);
                        applied = true;
                }
        }