From: Martin Ling Date: Thu, 24 Jul 2014 13:45:58 +0000 (+0100) Subject: bindings: Add Device::get_description() method. X-Git-Tag: libsigrok-0.4.0~1198 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f36ca8893d575d42eae0b103768ac7d8a4320322;p=libsigrok.git bindings: Add Device::get_description() method. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index ac583d04..044e8c45 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -19,6 +19,8 @@ #include "libsigrok/libsigrok.hpp" +#include + namespace sigrok { @@ -362,6 +364,20 @@ Device::~Device() delete entry.second; } +string Device::get_description() +{ + ostringstream s; + + vector parts = + {get_vendor(), get_model(), get_version()}; + + for (string part : parts) + if (part.length() > 0) + s << part; + + return s.str(); +} + string Device::get_vendor() { return valid_string(structure->vendor); diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 041f8498..a6cca1d2 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -276,6 +276,8 @@ class SR_API Device : public StructureWrapper { public: + /** Description identifying this device. */ + string get_description(); /** Vendor name for this device. */ string get_vendor(); /** Model name for this device. */ diff --git a/bindings/swig/classes.i b/bindings/swig/classes.i index 7c6b60c6..253ce01b 100644 --- a/bindings/swig/classes.i +++ b/bindings/swig/classes.i @@ -180,6 +180,7 @@ typedef std::map %attributestring(sigrok::OutputFormat, std::string, description, get_description); +%attributestring(sigrok::Device, std::string, description, get_description); %attributestring(sigrok::Device, std::string, vendor, get_vendor); %attributestring(sigrok::Device, std::string, model, get_model); %attributestring(sigrok::Device, std::string, version, get_version);