From: Martin Ling Date: Mon, 2 Nov 2015 20:52:00 +0000 (+0000) Subject: bindings: Wrap enum sr_configcap as Capability class. X-Git-Tag: libsigrok-0.4.0~55 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=12f2f640cbe9167ad386a2d9069ec882d70cda5b;p=libsigrok.git bindings: Wrap enum sr_configcap as Capability class. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 5eb3a750..49c75580 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -491,12 +491,12 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key) const return Glib::VariantContainerBase(data); } -map> Configurable::config_keys(const ConfigKey *key) +map> Configurable::config_keys(const ConfigKey *key) { GVariant *gvar_opts; gsize num_opts; const uint32_t *opts; - map> result; + map> result; check(sr_config_list( config_driver, config_sdi, config_channel_group, @@ -508,13 +508,13 @@ map> Configurable::config_keys(const ConfigKe for (gsize i = 0; i < num_opts; i++) { auto key = ConfigKey::get(opts[i] & SR_CONF_MASK); - set capabilities; + set capabilities; if (opts[i] & SR_CONF_GET) - capabilities.insert(GET); + capabilities.insert(Capability::GET); if (opts[i] & SR_CONF_SET) - capabilities.insert(SET); + capabilities.insert(Capability::SET); if (opts[i] & SR_CONF_LIST) - capabilities.insert(LIST); + capabilities.insert(Capability::LIST); result[key] = capabilities; } diff --git a/bindings/cxx/enums.py b/bindings/cxx/enums.py index 32ef6bc1..a1577a06 100644 --- a/bindings/cxx/enums.py +++ b/bindings/cxx/enums.py @@ -40,6 +40,7 @@ mapping = dict([ ('sr_unit', ('Unit', 'Unit of measurement')), ('sr_mqflag', ('QuantityFlag', 'Flag applied to measured quantity')), ('sr_configkey', ('ConfigKey', 'Configuration key')), + ('sr_configcap', ('Capability', 'Configuration capability')), ('sr_datatype', ('DataType', 'Configuration data type')), ('sr_channeltype', ('ChannelType', 'Channel type')), ('sr_trigger_matches', ('TriggerMatchType', 'Trigger match type')), diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index d8cf3bdc..da2a286e 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -98,6 +98,7 @@ class SR_API HardwareDevice; class SR_API Channel; class SR_API Session; class SR_API ConfigKey; +class SR_API Capability; class SR_API InputFormat; class SR_API OutputFormat; class SR_API OutputFlag; @@ -310,12 +311,6 @@ private: friend struct std::default_delete; }; -enum Capability { - GET = SR_CONF_GET, - SET = SR_CONF_SET, - LIST = SR_CONF_LIST -}; - /** An object that can be configured. */ class SR_API Configurable { @@ -331,7 +326,7 @@ public: * @param key ConfigKey to enumerate values for. */ Glib::VariantContainerBase config_list(const ConfigKey *key) const; /** Enumerate available keys, according to a given index key. */ - map > config_keys(const ConfigKey *key); + map > config_keys(const ConfigKey *key); /** Check for a key in the list from a given index key. */ bool config_check(const ConfigKey *key, const ConfigKey *index_key) const; protected: diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index 6489b9cf..1b303464 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -195,14 +195,14 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) /* Specialisation for ConfigKey->set maps */ -MAP_COMMON(const sigrok::ConfigKey *, std::set, +MAP_COMMON(const sigrok::ConfigKey *, std::set, ConfigKey, java.util.Set) -%typemap(jni) std::map > "jobject" -%typemap(jtype) std::map > +%typemap(jni) std::map > "jobject" +%typemap(jtype) std::map > "java.util.Map>" -%typemap(out) std::map > { +%typemap(out) std::map > { jclass HashMap = jenv->FindClass("java/util/HashMap"); jmethodID HashMap_init = jenv->GetMethodID(HashMap, "", "()V"); jmethodID HashMap_put = jenv->GetMethodID(HashMap, "put", @@ -214,8 +214,7 @@ MAP_COMMON(const sigrok::ConfigKey *, std::set, jclass ConfigKey = jenv->FindClass("org/sigrok/core/classes/ConfigKey"); jmethodID ConfigKey_init = jenv->GetMethodID(ConfigKey, "", "(JZ)V"); jclass Capability = jenv->FindClass("org/sigrok/core/classes/Capability"); - jmethodID Capability_swigToEnum = jenv->GetStaticMethodID(Capability, - "swigToEnum", "(I)Lorg/sigrok/core/classes/Capability;"); + jmethodID Capability_init = jenv->GetMethodID(Capability, "", "(JZ)V"); $result = jenv->NewObject(HashMap, HashMap_init); jlong key = 0; for (auto map_entry : $1) @@ -224,8 +223,7 @@ MAP_COMMON(const sigrok::ConfigKey *, std::set, jobject value = jenv->NewObject(HashSet, HashSet_init); for (auto &set_entry : map_entry.second) jenv->CallObjectMethod(value, HashSet_add, - jenv->CallStaticObjectMethod(Capability, - Capability_swigToEnum, set_entry)); + jenv->NewObject(Capability, Capability_init, set_entry)); jenv->CallObjectMethod($result, HashMap_put, jenv->NewObject(ConfigKey, ConfigKey_init, key, false), value); } diff --git a/bindings/swig/templates.i b/bindings/swig/templates.i index b3cf9fb9..f160866d 100644 --- a/bindings/swig/templates.i +++ b/bindings/swig/templates.i @@ -63,11 +63,16 @@ namespace std { %template(ConfigMap) std::map; +/* Currently broken on Python. */ +#ifndef SWIGPYTHON + %template(CapabilitySet) - std::set; + std::set; %template(ConfigKeys) - std::map >; + std::map >; + +#endif %template(OptionVector) std::vector >;