]> sigrok.org Git - pulseview.git/blobdiff - pv/devicemanager.cpp
Modified header guards to match file names
[pulseview.git] / pv / devicemanager.cpp
index df0b055caa7dc849a5fa12b1278edeba8e6cb270..c7111e865e9f4bc10f5b8f0e83f03a9d47153b21 100644 (file)
 #include <string>
 #include <vector>
 
-#include <libsigrok/libsigrok.hpp>
+#include <libsigrokcxx/libsigrokcxx.hpp>
 
+#include <boost/algorithm/string/join.hpp>
 #include <boost/filesystem.hpp>
 
+using boost::algorithm::join;
+
 using std::dynamic_pointer_cast;
 using std::list;
 using std::map;
-using std::ostringstream;
 using std::remove_if;
 using std::runtime_error;
 using std::shared_ptr;
@@ -196,8 +198,6 @@ void DeviceManager::build_display_name(shared_ptr<Device> device)
                return;
        }
 
-       ostringstream s;
-
        // First, build the device's full name. It always contains all
        // possible information.
        vector<string> parts = {device->vendor(), device->model(),
@@ -206,33 +206,20 @@ void DeviceManager::build_display_name(shared_ptr<Device> device)
        if (device->connection_id().length() > 0)
                parts.push_back("("+device->connection_id()+")");
 
-       for (size_t i = 0; i < parts.size(); i++)
-       {
-               if (parts[i].length() > 0)
-               {
-                       if (i != 0)
-                               s << " ";
-                       s << parts[i];
-               }
-       }
-
-       full_names_[device] = s.str();
+       full_names_[device] = join(parts, " ");
 
        // Next, build the display name. It only contains fields as required.
-       bool multiple_dev = false;
 
        // If we can find another device with the same model/vendor then
        // we have at least two such devices and need to distinguish them.
-       if (hardware_device)
-               multiple_dev = any_of(devices_.begin(), devices_.end(),
-                       [&](shared_ptr<HardwareDevice> dev) {
+       const bool multiple_dev = hardware_device && any_of(
+               devices_.begin(), devices_.end(),
+               [&](shared_ptr<HardwareDevice> dev) {
                        return (dev->vendor() == hardware_device->vendor() &&
-                       dev->model() == hardware_device->model()) &&
-                       dev != hardware_device;
-                       } );
+                               dev->model() == hardware_device->model()) &&
+                               dev != hardware_device;
+               } );
 
-       s.str("");
-       parts.clear();
        parts = {device->vendor(), device->model()};
 
        if (multiple_dev) {
@@ -244,17 +231,7 @@ void DeviceManager::build_display_name(shared_ptr<Device> device)
                        parts.push_back("("+device->connection_id()+")");
        }
 
-       for (size_t i = 0; i < parts.size(); i++)
-       {
-               if (parts[i].length() > 0)
-               {
-                       if (i != 0)
-                               s << " ";
-                       s << parts[i];
-               }
-       }
-
-       display_names_[device] = s.str();
+       display_names_[device] = join(parts, " ");
 }
 
 const std::string DeviceManager::get_display_name(std::shared_ptr<sigrok::Device> dev)