java: Usable wrapping of Configurable.config_keys().
This commit is contained in:
parent
36e3f6a9ce
commit
f2831ab35b
|
@ -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<const ConfigKey *, set<Capability> > config_keys(const ConfigKey *key);
|
||||
map<const ConfigKey *, set<enum Capability> > 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:
|
||||
|
|
|
@ -193,6 +193,44 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant)
|
|||
}
|
||||
}
|
||||
|
||||
/* Specialisation for ConfigKey->set<Capability> maps */
|
||||
|
||||
MAP_COMMON(const sigrok::ConfigKey *, std::set<enum sigrok::Capability>,
|
||||
ConfigKey, java.util.Set<Capability>)
|
||||
|
||||
%typemap(jni) std::map<const sigrok::ConfigKey *, std::set<enum sigrok::Capability>> "jobject"
|
||||
%typemap(jtype) std::map<const sigrok::ConfigKey *, std::set<enum sigrok::Capability>>
|
||||
"java.util.Map<ConfigKey,java.util.Set<Capability>>"
|
||||
|
||||
%typemap(out) std::map<const sigrok::ConfigKey *, std::set<enum sigrok::Capability>> {
|
||||
jclass HashMap = jenv->FindClass("java/util/HashMap");
|
||||
jmethodID HashMap_init = jenv->GetMethodID(HashMap, "<init>", "()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, "<init>", "()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, "<init>", "(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 * %{
|
||||
|
|
|
@ -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 _Key> class set {};
|
||||
}
|
||||
#else
|
||||
%include "std_set.i"
|
||||
#endif
|
||||
|
||||
%template(StringMap) std::map<std::string, std::string>;
|
||||
|
||||
|
@ -56,6 +63,12 @@ using namespace std;
|
|||
%template(ConfigMap)
|
||||
std::map<const sigrok::ConfigKey *, Glib::VariantBase>;
|
||||
|
||||
%template(CapabilitySet)
|
||||
std::set<enum sigrok::Capability>;
|
||||
|
||||
%template(ConfigKeys)
|
||||
std::map<const sigrok::ConfigKey *, std::set<enum sigrok::Capability> >;
|
||||
|
||||
%template(OptionVector)
|
||||
std::vector<std::shared_ptr<sigrok::Option> >;
|
||||
%template(OptionMap)
|
||||
|
|
Loading…
Reference in New Issue