]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/include/libsigrok/libsigrok.hpp
cxx: Implement more of EnumValue in template.
[libsigrok.git] / bindings / cxx / include / libsigrok / libsigrok.hpp
index 3e49bd5986defbc4cbabc789c0adf0be2c08a9f6..3582646fee28954fb772e41986cd7adebe378a9c 100644 (file)
@@ -352,8 +352,6 @@ protected:
 class SR_API Device : public Configurable
 {
 public:
-       /** Description identifying this device. */
-       virtual string description();
        /** Vendor name for this device. */
        string vendor();
        /** Model name for this device. */
@@ -615,8 +613,6 @@ class SR_API SessionDevice :
        public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
        public Device
 {
-       /** Description identifying this device. */
-       string description();
 protected:
        SessionDevice(struct sr_dev_inst *sdi);
        ~SessionDevice();
@@ -863,9 +859,6 @@ class SR_API InputDevice :
        public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
        public Device
 {
-public:
-       /** Description identifying this device. */
-       string description();
 protected:
        InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
        ~InputDevice();
@@ -942,17 +935,44 @@ protected:
 };
 
 /** Base class for objects which wrap an enumeration value from libsigrok */
-template <typename T> class SR_API EnumValue
+template <class Class, typename Enum> class SR_API EnumValue
 {
 public:
-       /** The enum constant associated with this value. */
-       T id() const { return _id; }
+       /** The integer constant associated with this value. */
+       int id() const
+       {
+               return static_cast<int>(_id);
+       }
        /** The name associated with this value. */
-       string name() const { return _name; }
+       string name() const
+       {
+               return _name;
+       }
+       /** Get value associated with a given integer constant. */
+       static const Class *get(int id)
+       {
+               auto key = static_cast<Enum>(id);
+               if (_values.find(key) == _values.end())
+                       throw Error(SR_ERR_ARG);
+               return _values.at(key);
+       }
+       /** Get possible values. */
+       static std::vector<const Class *> values()
+       {
+               std::vector<const Class *> result;
+               for (auto entry : _values)
+                       result.push_back(entry.second);
+               return result;
+       }
 protected:
-       EnumValue(T id, const char name[]) : _id(id), _name(name) {}
-       ~EnumValue() {}
-       const T _id;
+       EnumValue(Enum id, const char name[]) : _id(id), _name(name)
+       {
+       }
+       ~EnumValue()
+       {
+       }
+       static const std::map<const Enum, const Class * const> _values;
+       const Enum _id;
        const string _name;
 };