12#ifndef TT_INCLUDE__ITERATOR_H
13#define TT_INCLUDE__ITERATOR_H
18#include "engine_vector.h"
20#define TT_FOREACH(iterator, collection) for (Iterator<decltype(collection)&> iterator(collection); iterator; ++iterator)
21#define TT_CONST_FOREACH(iterator, collection) for (Iterator<const decltype(collection)&> iterator(collection); iterator; ++iterator)
25template<
class T>
class Iterator;
29template<
class T>
class Iterator<SList<T>&>
36 inline Iterator(SList<T>& list) { node = list.Head(); }
37 inline operator bool() {
return node != NULL; }
38 inline operator T*() {
return node->Data(); }
39 inline T* operator ->() {
return (T*)*
this; }
40 inline Iterator& operator ++() { node = node->Next();
return *
this; }
46template<
class T>
class Iterator<const SList<T>&>
49 const SLNode<T>* node;
53 inline Iterator(
const SList<T>& list) { node = list.Head(); }
54 inline operator bool() {
return node != NULL; }
55 inline operator const T*() {
return node->Data(); }
56 inline const T* operator ->() {
return (T*)*
this; }
57 inline Iterator& operator ++() { node = node->Next();
return *
this; }
63template<
class T>
class Iterator<VectorClass<T>&>
71 inline Iterator(VectorClass<T>& vector) { current = &vector[0]; end = &vector[vector.Length()]; }
72 inline operator bool() {
return current != end; }
73 inline operator T*() {
return current; }
74 inline T* operator ->() {
return (T*)*
this; }
75 inline Iterator& operator ++() { ++current;
return *
this; }
81template<
class T>
class Iterator<const VectorClass<T>&>
89 inline Iterator(
const VectorClass<T>& vector) { current = &vector[0]; end = &vector[vector.Length()]; }
90 inline operator bool() {
return current != end; }
91 inline operator const T*() {
return current; }
92 inline const T* operator ->() {
return (
const T*)*
this; }
93 inline Iterator& operator ++() { ++current;
return *
this; }
99template<
class T>
class Iterator<DynamicVectorClass<T>&>
107 inline Iterator(DynamicVectorClass<T>& vector) { current = &vector[0]; end = &vector[vector.Count()]; }
108 inline operator bool() {
return current != end; }
109 inline operator T*() {
return current; }
110 inline T* operator ->() {
return (T*)*
this; }
111 inline Iterator& operator ++() { ++current;
return *
this; }
117template<
class T>
class Iterator<const DynamicVectorClass<T>&>
125 inline Iterator(
const DynamicVectorClass<T>& vector) { current = &vector[0]; end = &vector[vector.Count()]; }
126 inline operator bool() {
return current != end; }
127 inline operator const T*() {
return current; }
128 inline const T* operator ->() {
return (
const T*)*
this; }
129 inline Iterator& operator ++() { ++current;
return *
this; }
135template<
class T>
class Iterator<SimpleVecClass<T>&>
143 inline Iterator(SimpleVecClass<T>& vector) { current = &vector[0]; end = &vector[vector.Length()]; }
144 inline operator bool() {
return current != end; }
145 inline operator T*() {
return current; }
146 inline T* operator ->() {
return (T*)*
this; }
147 inline Iterator& operator ++() { ++current;
return *
this; }
153template<
class T>
class Iterator<const SimpleVecClass<T>&>
161 inline Iterator(
const SimpleVecClass<T>& vector) { current = &vector[0]; end = &vector[vector.Length()]; }
162 inline operator bool() {
return current != end; }
163 inline operator const T*() {
return current; }
164 inline const T* operator ->() {
return (
const T*)*
this; }
165 inline Iterator& operator ++() { ++current;
return *
this; }
171template<
class T>
class Iterator<SimpleDynVecClass<T>&>
179 inline Iterator(SimpleDynVecClass<T>& vector) { current = &vector[0]; end = &vector[vector.Count()]; }
180 inline operator bool() {
return current != end; }
181 inline operator T*() {
return current; }
182 inline T* operator ->() {
return (T*)*
this; }
183 inline Iterator& operator ++() { ++current;
return *
this; }
189template<
class T>
class Iterator<const SimpleDynVecClass<T>&>
197 inline Iterator(
const SimpleDynVecClass<T>& vector) { current = &vector[0]; end = &vector[vector.Count()]; }
198 inline operator bool() {
return current != end; }
199 inline operator const T*() {
return current; }
200 inline const T* operator ->() {
return (
const T*)*
this; }
201 inline Iterator& operator ++() { ++current;
return *
this; }