From: Martin Ling Date: Sun, 25 Oct 2015 16:02:54 +0000 (+0000) Subject: java: Usable wrapping of Configurable.config_keys(). X-Git-Tag: libsigrok-0.4.0~156 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f2831ab35b4988930535dfd135884873b1b5b00d;p=libsigrok.git java: Usable wrapping of Configurable.config_keys(). --- diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index 48111b87..cf86bfc3 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -326,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 c5d9b27b..daa66305 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -193,6 +193,44 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) } } +/* Specialisation for ConfigKey->set maps */ + +MAP_COMMON(const sigrok::ConfigKey *, std::set, + ConfigKey, java.util.Set) + +%typemap(jni) std::map> "jobject" +%typemap(jtype) std::map> + "java.util.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", + "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + jclass HashSet = jenv->FindClass("java/util/HashSet"); + jmethodID HashSet_init = jenv->GetMethodID(HashSet, "", "()V"); + jmethodID HashSet_add = jenv->GetMethodID(HashSet, "add", + "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + 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;"); + $result = jenv->NewObject(HashMap, HashMap_init); + jlong key; + for (auto map_entry : $1) + { + *(const sigrok::ConfigKey **) &key = map_entry.first; + 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->CallObjectMethod($result, HashMap_put, + jenv->NewObject(ConfigKey, ConfigKey_init, key, false), value); + } +} + /* Pass JNIEnv parameter to C++ extension methods requiring it. */ %typemap(in, numinputs=0) JNIEnv * %{ diff --git a/bindings/swig/templates.i b/bindings/swig/templates.i index bbb3619c..b3cf9fb9 100644 --- a/bindings/swig/templates.i +++ b/bindings/swig/templates.i @@ -26,6 +26,13 @@ using namespace std; %include "std_shared_ptr.i" %include "std_vector.i" %include "std_map.i" +#ifdef SWIGJAVA +namespace std { + template class set {}; +} +#else +%include "std_set.i" +#endif %template(StringMap) std::map; @@ -56,6 +63,12 @@ using namespace std; %template(ConfigMap) std::map; +%template(CapabilitySet) + std::set; + +%template(ConfigKeys) + std::map >; + %template(OptionVector) std::vector >; %template(OptionMap)