7#ifndef MFRAME_9DAB1F2F_D976_4CB4_9CDD_36EE14C28322
8#define MFRAME_9DAB1F2F_D976_4CB4_9CDD_36EE14C28322
15#include "./../lang/Iterable.h"
16#include "./../lang/Object.h"
41template <
class E =
void*>
60 : vIterable(iterable), vIndex(
index) {
120 return (this->vIterable.
nextIndex(this->vIndex) != -1);
129 this->vIndex = this->vIterable.
nextIndex(this->vIndex);
130 if (this->vIndex == -1) {
131 UFM_THROW(
"Iterator has reached the end of the collection.",
143 return this->vIterable.
elementAt(this->vIndex);
物件基底類別
Definition Object.h:63
[Class] 迭代器介面
Definition Iterator.h:42
Iterator & operator++()
前置遞增運算子,將迭代器移動到下一個元素。
Definition Iterator.h:93
bool hasNext(void) const
判斷是否還有下一個元素可供遍歷。
Definition Iterator.h:119
void next(void)
將迭代器移動到下一個元素。
Definition Iterator.h:128
bool operator!=(const Iterator &other) const
不等於運算子,判斷兩個迭代器是否指向不同位置。
Definition Iterator.h:106
virtual ~Iterator(void) override
解構 Iterator 物件。
Definition Iterator.h:69
E * get(void) const
取得目前元素的參考。
Definition Iterator.h:142
int index(void) const
重新設定該迭代器至初始狀態。
Definition Iterator.h:151
E & operator*() const
取得目前元素的參考(解引用運算子)。
Definition Iterator.h:83
Iterator(ufm::lang::Iterable< E > &iterable, int index=0) noexcept
建構 Iterator 物件。
Definition Iterator.h:59
@ INDEX_OUT_OF_BOUNDS
索引超出範圍,泛指各種集合
[Interface] 定義可迭代集合介面
Definition Iterable.h:49
virtual E * elementAt(int index) const override
獲取集合中指定索引處的元素。
virtual int nextIndex(int index) const override
返回當前索引的下一個有效索引。