Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ privmx::endpoint::core::PagingQuery parsePagingQuery(JniContextUtils &ctx, jobje


// java -> c++
template<typename T>
std::vector<T> jArrayToVector(JniContextUtils &ctx, jobjectArray jArray,
std::function<T(JniContextUtils &, jobject)> fun, bool acceptNullValues);

template<typename T>
std::vector<T> jArrayToVector(JniContextUtils &ctx, jobjectArray jArray,
std::function<T(JniContextUtils &, jobject)> fun);
Expand All @@ -64,7 +68,12 @@ std::string jobject2string(JniContextUtils &ctx, jobject jString);

// c++ -> java
template<typename T, typename F>
jobject vectorTojArray(JniContextUtils &ctx, const std::vector<T> &vector,F fun){
jobject vectorTojArray(
JniContextUtils &ctx,
const std::vector<T> &vector,
F fun,
bool acceptNullValues
) {
jclass arrayListCls = ctx->FindClass("java/util/ArrayList");
jmethodID initMID = ctx->GetMethodID(arrayListCls, "<init>", "()V");
jmethodID addToListMID = ctx->GetMethodID(arrayListCls, "add", "(Ljava/lang/Object;)Z");
Expand All @@ -73,16 +82,24 @@ jobject vectorTojArray(JniContextUtils &ctx, const std::vector<T> &vector,F fun)

for (const auto &item: vector) {
jobject jItem = fun(ctx, item);
if (!acceptNullValues) {
if (ctx.nullCheck(jItem, "Array element")) {return nullptr;}
}

ctx->CallBooleanMethod(listObj, addToListMID, jItem);
}

return listObj;
}

template<typename T, typename F>
jobject pagingList2Java(JniContextUtils &ctx, privmx::endpoint::core::PagingList<T> pagingList,F fun);
jobject vectorTojArray(JniContextUtils &ctx, const std::vector<T> &vector, F fun) {
return vectorTojArray(ctx, vector, fun, true);
}

template<typename T, typename F>
jobject pagingList2Java(JniContextUtils &ctx, privmx::endpoint::core::PagingList<T> pagingList, F fun);

jobject string2jobject(JniContextUtils &ctx,const std::string &cstring);
jobject long2jobject(JniContextUtils &ctx,const int64_t &clong);
jobject string2jobject(JniContextUtils &ctx, const std::string &cstring);
jobject long2jobject(JniContextUtils &ctx, const int64_t &clong);

#endif //PRIVMX_POCKET_LIB_PARSER_H
Loading