15 #ifndef EMP_EVO_WORLD_ITER_H 16 #define EMP_EVO_WORLD_ITER_H 18 #include "../base/Ptr.h" 22 template <
typename WORLD>
25 using world_t = WORLD;
26 using org_t =
typename world_t::org_t;
33 size_t WorldSize() {
emp_assert(world_ptr);
return world_ptr->size(); }
40 while (pos < WorldSize() && OrgPtr() ==
nullptr) ++pos;
46 World_iterator(world_t * _w,
size_t _p=0) : world_ptr(_w), pos(_p) { MakeValid(); }
53 world_ptr = _in.world_ptr;
69 while (pos < WorldSize() && OrgPtr() ==
nullptr) --pos;
92 org_t &
operator*() { MakeValid();
return *(OrgPtr()); }
95 const org_t &
operator*()
const { MakeValid();
return *(OrgPtr()); }
98 operator bool()
const { MakeValid();
return pos < WorldSize(); }
this_t & operator--()
Backup iterator to the previos non-empty cell in the world.
Definition: World_iterator.h:67
bool operator!=(const this_t &rhs) const
Compare two iterators to determine if they point to different positions in the world.
Definition: World_iterator.h:77
const org_t & operator*() const
Return a const reference to the organism pointed to by this iterator.
Definition: World_iterator.h:95
World_iterator(const World_iterator &_in)
Create an iterator pointing to the same position as another iterator.
Definition: World_iterator.h:49
bool operator>(const this_t &rhs) const
Determine if this iterator points to a position in the world AFTER another iterator.
Definition: World_iterator.h:86
Definition: World_iterator.h:23
this_t & operator++()
Advance iterator to the next non-empty cell in the world.
Definition: World_iterator.h:60
org_t & operator*()
Return a reference to the organism pointed to by this iterator.
Definition: World_iterator.h:92
bool operator<(const this_t &rhs) const
Determine if this iterator points to a position in the world BEFORE another iterator.
Definition: World_iterator.h:80
World_iterator(world_t *_w, size_t _p=0)
Definition: World_iterator.h:46
bool operator>=(const this_t &rhs) const
Determine if this iterator points to a position in the world AFTER or the SAME AS another iterator...
Definition: World_iterator.h:89
this_t end()
Return an iterator pointing to just past the end of the world.
Definition: World_iterator.h:107
const this_t begin() const
Return a const iterator pointing to the first occupied cell in the world.
Definition: World_iterator.h:104
this_t begin()
Return an iterator pointing to the first occupied cell in the world.
Definition: World_iterator.h:101
bool operator<=(const this_t &rhs) const
Determine if this iterator points to a position in the world BEFORE or the SAME AS another iterator...
Definition: World_iterator.h:83
If we are in emscripten, make sure to include the header.
Definition: array.h:37
const this_t end() const
Return a const iterator pointing to just past the end of the world.
Definition: World_iterator.h:110
#define emp_assert(...)
Definition: assert.h:199
this_t & operator=(const World_iterator &_in)
Assign this iterator to the position of another iterator.
Definition: World_iterator.h:52
bool operator==(const this_t &rhs) const
Compare two iterators to determine if they point to identical positions in the world.
Definition: World_iterator.h:74