Chromium Code Reviews| Index: webrtc/api/java/jni/jni_helpers.cc |
| diff --git a/webrtc/api/java/jni/jni_helpers.cc b/webrtc/api/java/jni/jni_helpers.cc |
| index 32092e65f8b7e8a2c94cb69b393ccc5f4f2ebb2e..dc014fde225af3462c9b29ff5ff08070bcac3618 100644 |
| --- a/webrtc/api/java/jni/jni_helpers.cc |
| +++ b/webrtc/api/java/jni/jni_helpers.cc |
| @@ -272,4 +272,51 @@ ScopedLocalRefFrame::~ScopedLocalRefFrame() { |
| jni_->PopLocalFrame(NULL); |
| } |
| +// Creates an iterator representing the end of any collection. |
| +Iterator::Iterator() : iterator_(NULL) {} |
|
magjed_webrtc
2016/03/22 15:15:30
nit: Use nullptr instead of NULL. This file seems
skvlad
2016/03/23 00:29:27
Thanks. I've updated the entire file to use nullpt
|
| + |
| +// Creates an iterator pointing to the beginning of the specified collection. |
| +Iterator::Iterator(JNIEnv* jni, jobject iterable) : jni_(jni) { |
| + jclass j_class = GetObjectClass(jni, iterable); |
| + jmethodID iterator_id = |
| + GetMethodID(jni, j_class, "iterator", "()Ljava/util/Iterator;"); |
| + iterator_ = jni->CallObjectMethod(iterable, iterator_id); |
| + CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; |
| + RTC_CHECK(iterator_ != NULL); |
| + |
| + jclass iterator_class = GetObjectClass(jni, iterator_); |
| + has_next_id_ = GetMethodID(jni, iterator_class, "hasNext", "()Z"); |
| + next_id_ = GetMethodID(jni, iterator_class, "next", "()Ljava/lang/Object;"); |
| + |
| + // Start at the first element in the collection. |
| + ++(*this); |
| +} |
| + |
| +// Move constructor - necessary to be able to return iterator types from |
| +// functions. |
| +Iterator::Iterator(Iterator&& other) |
| + : jni_(std::move(other.jni_)), |
| + iterator_(std::move(other.iterator_)), |
| + value_(std::move(other.value_)), |
| + has_next_id_(std::move(other.has_next_id_)), |
| + next_id_(std::move(other.next_id_)){}; |
|
magjed_webrtc
2016/03/22 15:15:30
nit: space between '(' and '{'. Can you use 'git c
skvlad
2016/03/23 00:29:27
Done. Curiously, "git cl format" wants to remove t
|
| + |
| +// Advances the iterator one step. |
| +Iterator& Iterator::operator++() { |
| + if (iterator_ == NULL) { |
| + // Can't iterate past the end. |
| + return *this; |
| + } |
| + bool has_next = jni_->CallBooleanMethod(iterator_, has_next_id_); |
| + CHECK_EXCEPTION(jni_) << "error during CallBooleanMethod"; |
| + if (!has_next) { |
|
magjed_webrtc
2016/03/22 15:15:30
You should probably set |value_| to nullptr here a
skvlad
2016/03/23 00:29:26
Done.
|
| + iterator_ = NULL; |
| + return *this; |
| + } |
| + |
| + value_ = jni_->CallObjectMethod(iterator_, next_id_); |
| + CHECK_EXCEPTION(jni_) << "error during CallObjectMethod"; |
| + return *this; |
| +} |
| + |
| } // namespace webrtc_jni |