X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Finclude%2Flibsigrok%2Flibsigrok.hpp;h=3582646fee28954fb772e41986cd7adebe378a9c;hb=9d229ecb9e301921284c6264ffc1d956572873df;hp=0fcc59d0f682c3f0150cd0de4071170ee3efd640;hpb=3250d8c7e05f2d6a3ffbdf2499af8a13fa99fe39;p=libsigrok.git diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 0fcc59d0..3582646f 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -935,17 +935,44 @@ protected: }; /** Base class for objects which wrap an enumeration value from libsigrok */ -template class SR_API EnumValue +template 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(_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(id); + if (_values.find(key) == _values.end()) + throw Error(SR_ERR_ARG); + return _values.at(key); + } + /** Get possible values. */ + static std::vector values() + { + std::vector 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 _values; + const Enum _id; const string _name; };