 |
Gorgon Game Engine
|
Go to the documentation of this file.
15 namespace Containers {
30 template <
class I_,
class T_,
class D_=
long>
31 class Iterator :
public std::iterator<std::random_access_iterator_tag, T_, D_> {
33 I_ &iterator() {
return *
static_cast<I_*
>(
this); }
34 const I_ &iterator()
const {
return *
static_cast<const I_*
>(
this); }
44 return iterator().current();
49 return &iterator().current();
54 return iterator().moveby(amount);
59 return iterator().moveby(1);
64 return iterator().moveby(-1);
69 return iterator().isvalid();
73 explicit operator bool()
const {
84 return this->iterator().compare(iterator);
89 return this->iterator().distance(iterator);
94 return this->iterator().compare(iterator);
99 return !(this->iterator() <= iterator);
104 return this->iterator().isbefore(iterator);
109 return !(this->iterator() < iterator);
114 return this->iterator().isbefore(iterator) || this->iterator().compare(iterator);
119 return !iterator().compare(it);
124 this->iterator().set(iterator);
126 return this->iterator();
131 return iterator.distance(this->iterator());
152 iterator().moveby(offset);
159 iterator().moveby(-offset);
166 iterator().moveby(1);
173 iterator().moveby(-1);
181 iterator().moveby(1);
189 iterator().moveby(-1);
196 return iterator().current();
201 return &iterator().current();
218 template <
class I_,
class T_,
class D_=
long>
219 class ValueIterator : std::iterator<std::random_access_iterator_tag, T_, D_> {
221 I_ &iterator() {
return *
static_cast<I_*
>(
this); }
222 const I_ &iterator()
const {
return *
static_cast<const I_*
>(
this); }
232 return iterator().current();
238 return iterator().moveby(amount);
243 return iterator().moveby(1);
248 return iterator().moveby(-1);
253 return iterator().isvalid();
257 explicit operator bool()
const {
268 return this->iterator().compare(iterator);
273 return this->iterator().distance(iterator);
278 return this->iterator().compare(iterator);
283 return !(this->iterator() <= iterator);
288 return this->iterator().isbefore(iterator);
293 return !(this->iterator() < iterator);
298 return this->iterator().isbefore(iterator) || this->iterator().compare(iterator);
303 return !iterator().compare(it);
308 this->iterator().set(iterator);
310 return this->iterator();
315 return iterator.distance(this->iterator());
336 iterator().moveby(offset);
343 iterator().moveby(-offset);
350 iterator().moveby(1);
357 iterator().moveby(-1);
365 iterator().moveby(1);
373 iterator().moveby(-1);
380 return iterator().current();
387 for(I_ i=first; i!=
end; ++i) {
395 for(I_ i=first; i!=
end; ++i) {
402 template<
class I_,
class T_>
403 I_
Find(
const I_ &first,
const I_ &
end,
const T_ &item) {
404 for(I_ i=first; i!=
end; ++i) {
414 template<
class C_,
class I_>
416 for(I_ i=it; i.IsValid(); i.Next()) {
423 template<
class C_,
class I_>
432 template<
class T_,
class I_,
class A_>
433 void AddCopy(std::vector<T_, A_> &target,
const I_ &it) {
434 for(I_ i=it; i.IsValid(); i.Next()) {
435 target.push_back(*i);
441 template<
class T_,
class I_,
class A_>
444 target.push_back(*i);
456 std::ostream &
operator <<(std::ostream &out,
const std::vector<T_> &vec) {
T_ operator*() const
Dereferences the operator to get its value.
Definition: Iterator.h:379
D_ Distance(const I_ &iterator) const
Returns the distance to the given iterator.
Definition: Iterator.h:272
void Remove(const I_ &first, const I_ &end)
This function works with collection iterators.
Definition: Iterator.h:386
bool MoveBy(int amount)
Moves the iterator by the given amount.
Definition: Iterator.h:53
I_ & operator-=(D_ offset)
Moves the iterator by the given offset to backwards.
Definition: Iterator.h:342
bool Previous()
Moves to the previous item.
Definition: Iterator.h:247
I_ & operator++()
Moves the iterator to forwards.
Definition: Iterator.h:349
T_ & Current() const
Returns current item.
Definition: Iterator.h:43
D_ operator-(const I_ &iterator) const
Returns the distance to the given iterator.
Definition: Iterator.h:314
bool MoveBy(int amount)
Moves the iterator by the given amount.
Definition: Iterator.h:237
bool operator<(const I_ &iterator) const
Checks if the current operator is before the given.
Definition: Iterator.h:287
T_ * operator->() const
Dereferences the operator to access its values.
Definition: Iterator.h:200
I_ operator+(D_ offset) const
Creates a new iterator adding the given offset.
Definition: Iterator.h:135
I_ & operator--()
Moves the iterator to backwards.
Definition: Iterator.h:356
std::vector< T_ >::const_iterator begin(enum_type_id< T_ >)
Definition: Enum.h:283
T_ * CurrentPtr() const
Returns current item.
Definition: Iterator.h:48
T_ & operator[](D_ ind) const
Index notation.
Definition: Iterator.h:78
void Delete(const I_ &first, const I_ &end)
This function works with collection iterators.
Definition: Iterator.h:394
bool Next()
Advances the iterator to the next item.
Definition: Iterator.h:58
T_ operator[](D_ ind) const
Index notation.
Definition: Iterator.h:262
Generic iterator interface.
Definition: Iterator.h:219
bool Compare(const I_ &iterator) const
Compares two iterators if they point to the same item.
Definition: Iterator.h:83
I_ & operator+=(D_ offset)
Moves the D_ by the given offset to forwards.
Definition: Iterator.h:335
bool operator<=(const I_ &iterator) const
Checks whether current operator is before or at the same point.
Definition: Iterator.h:113
bool operator>(const I_ &iterator) const
Checks whether current operator is after the given.
Definition: Iterator.h:98
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::ostream & >::type operator<<(std::ostream &out, const T_ &e)
Stream writer for upgraded enums.
Definition: Enum.h:326
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
bool operator<=(const I_ &iterator) const
Checks whether current operator is before or at the same point.
Definition: Iterator.h:297
void AddCopy(C_ &target, const I_ &it)
This function copies the contents of the given iterator as long as it can be dereferenced to the give...
Definition: Iterator.h:415
bool IsValid() const
Checks if the iterator is pointing to a valid item.
Definition: Iterator.h:68
I_ Find(const I_ &first, const I_ &end, const T_ &item)
This function works with collection iterators.
Definition: Iterator.h:403
bool operator>=(const I_ &iterator) const
Checks whether current operator is after or at the same point.
Definition: Iterator.h:292
bool Compare(const I_ &iterator) const
Compares two iterators if they point to the same item.
Definition: Iterator.h:267
bool operator<(const I_ &iterator) const
Checks if the current operator is before the given.
Definition: Iterator.h:103
I_ & operator++()
Moves the iterator to forwards.
Definition: Iterator.h:165
T_ & operator*() const
Dereferences the operator to get its value.
Definition: Iterator.h:195
bool IsValid() const
Checks if the iterator is pointing to a valid item.
Definition: Iterator.h:252
ValueIterator()
Cannot be constructed unless overridden.
Definition: Iterator.h:226
bool operator>(const I_ &iterator) const
Checks whether current operator is after the given.
Definition: Iterator.h:282
bool Previous()
Moves to the previous item.
Definition: Iterator.h:63
bool operator==(const I_ &iterator) const
Compares two iterators if they point to the same item.
Definition: Iterator.h:277
D_ operator-(const I_ &iterator) const
Returns the distance to the given iterator.
Definition: Iterator.h:130
bool operator!=(const I_ &it) const
Compares this iterator with another.
Definition: Iterator.h:302
I_ & operator--()
Moves the iterator to backwards.
Definition: Iterator.h:172
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
Iterator()
Cannot be constructed unless overridden.
Definition: Iterator.h:38
I_ operator+(D_ offset) const
Creates a new iterator adding the given offset.
Definition: Iterator.h:319
bool Next()
Advances the iterator to the next item.
Definition: Iterator.h:242
T_ Current() const
Returns current item.
Definition: Iterator.h:231
Generic iterator interface.
Definition: Iterator.h:31
I_ & operator=(const I_ &iterator)
Moves this iterator to the item pointed by the given.
Definition: Iterator.h:307
I_ & operator+=(D_ offset)
Moves the D_ by the given offset to forwards.
Definition: Iterator.h:151
bool operator!=(const I_ &it) const
Compares this iterator with another.
Definition: Iterator.h:118
D_ Distance(const I_ &iterator) const
Returns the distance to the given iterator.
Definition: Iterator.h:88
bool operator>=(const I_ &iterator) const
Checks whether current operator is after or at the same point.
Definition: Iterator.h:108
I_ & operator=(const I_ &iterator)
Moves this iterator to the item pointed by the given.
Definition: Iterator.h:123
bool operator==(const I_ &iterator) const
Compares two iterators if they point to the same item.
Definition: Iterator.h:93
I_ & operator-=(D_ offset)
Moves the iterator by the given offset to backwards.
Definition: Iterator.h:158