OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/jni_array.h" | 5 #include "base/android/jni_array.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 jfloatArray float_array, | 239 jfloatArray float_array, |
240 std::vector<float>* out) { | 240 std::vector<float>* out) { |
241 DCHECK(out); | 241 DCHECK(out); |
242 size_t len = SafeGetArrayLength(env, float_array); | 242 size_t len = SafeGetArrayLength(env, float_array); |
243 out->resize(len); | 243 out->resize(len); |
244 if (!len) | 244 if (!len) |
245 return; | 245 return; |
246 env->GetFloatArrayRegion(float_array, 0, len, &(*out)[0]); | 246 env->GetFloatArrayRegion(float_array, 0, len, &(*out)[0]); |
247 } | 247 } |
248 | 248 |
| 249 void JavaJObjectArrayToJObjectVector( |
| 250 JNIEnv* env, |
| 251 jobjectArray jobject_array, |
| 252 std::vector<ScopedJavaLocalRef<jobject>>* out) { |
| 253 DCHECK(out); |
| 254 size_t len = SafeGetArrayLength(env, jobject_array); |
| 255 if (!len) |
| 256 return; |
| 257 out->reserve(len); |
| 258 |
| 259 for (size_t i = 0; i < len; ++i) { |
| 260 out->push_back(ScopedJavaLocalRef<jobject>( |
| 261 env, env->GetObjectArrayElement(jobject_array, i))); |
| 262 } |
| 263 } |
| 264 |
249 void JavaArrayOfByteArrayToStringVector( | 265 void JavaArrayOfByteArrayToStringVector( |
250 JNIEnv* env, | 266 JNIEnv* env, |
251 jobjectArray array, | 267 jobjectArray array, |
252 std::vector<std::string>* out) { | 268 std::vector<std::string>* out) { |
253 DCHECK(out); | 269 DCHECK(out); |
254 size_t len = SafeGetArrayLength(env, array); | 270 size_t len = SafeGetArrayLength(env, array); |
255 out->resize(len); | 271 out->resize(len); |
256 for (size_t i = 0; i < len; ++i) { | 272 for (size_t i = 0; i < len; ++i) { |
257 ScopedJavaLocalRef<jbyteArray> bytes_array( | 273 ScopedJavaLocalRef<jbyteArray> bytes_array( |
258 env, static_cast<jbyteArray>( | 274 env, static_cast<jbyteArray>( |
(...skipping 14 matching lines...) Expand all Loading... |
273 out->resize(len); | 289 out->resize(len); |
274 for (size_t i = 0; i < len; ++i) { | 290 for (size_t i = 0; i < len; ++i) { |
275 ScopedJavaLocalRef<jintArray> int_array( | 291 ScopedJavaLocalRef<jintArray> int_array( |
276 env, static_cast<jintArray>(env->GetObjectArrayElement(array, i))); | 292 env, static_cast<jintArray>(env->GetObjectArrayElement(array, i))); |
277 JavaIntArrayToIntVector(env, int_array.obj(), &((*out)[i])); | 293 JavaIntArrayToIntVector(env, int_array.obj(), &((*out)[i])); |
278 } | 294 } |
279 } | 295 } |
280 | 296 |
281 } // namespace android | 297 } // namespace android |
282 } // namespace base | 298 } // namespace base |
OLD | NEW |