Make libnativehelper C++ library agnostic and remove libnativehelper_libc++.
Change-Id: Ib5510add3337992dc2a99affe671a01d39782237
diff --git a/include/nativehelper/toStringArray.h b/include/nativehelper/toStringArray.h
index 55fae2c..9dc7a16 100644
--- a/include/nativehelper/toStringArray.h
+++ b/include/nativehelper/toStringArray.h
@@ -45,7 +45,27 @@
return result;
}
-JNIEXPORT jobjectArray toStringArray(JNIEnv* env, const std::vector<std::string>& strings);
+struct VectorCounter {
+ const std::vector<std::string>& strings;
+ VectorCounter(const std::vector<std::string>& strings) : strings(strings) {}
+ size_t operator()() {
+ return strings.size();
+ }
+};
+struct VectorGetter {
+ const std::vector<std::string>& strings;
+ VectorGetter(const std::vector<std::string>& strings) : strings(strings) {}
+ const char* operator()(size_t i) {
+ return strings[i].c_str();
+ }
+};
+
+inline jobjectArray toStringArray(JNIEnv* env, const std::vector<std::string>& strings) {
+ VectorCounter counter(strings);
+ VectorGetter getter(strings);
+ return toStringArray<VectorCounter, VectorGetter>(env, &counter, &getter);
+}
+
JNIEXPORT jobjectArray toStringArray(JNIEnv* env, const char* const* strings);
#endif // TO_STRING_ARRAY_H_included