World_iterator.hpp

This file defines iterators for use with World objects.

Todo:

Add a const interator.

Currently we do MakeValid after every change AND before many accesses. Pick one?

Fix operator– which can go off of the beginnig of the world.

Note

Originally called PopulationIterator.h

template<typename WORLD>
class World_iterator
#include <World_iterator.hpp>

Public Functions

inline World_iterator(Ptr<world_t> _w, size_t _p = 0)

Create an iterator in the specified world pointing to the first occupied cell after the provided start position.

inline World_iterator(const World_iterator &_in)

Create an iterator pointing to the same position as another iterator.

inline this_t &operator=(const World_iterator &_in)

Assign this iterator to the position of another iterator.

inline this_t &operator++()

Advance iterator to the next non-empty cell in the world.

inline this_t &operator--()

Backup iterator to the previos non-empty cell in the world.

inline bool operator==(const this_t &rhs) const

Compare two iterators to determine if they point to identical positions in the world.

inline bool operator!=(const this_t &rhs) const

Compare two iterators to determine if they point to different positions in the world.

inline bool operator<(const this_t &rhs) const

Determine if this iterator points to a position in the world BEFORE another iterator.

inline 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.

inline bool operator>(const this_t &rhs) const

Determine if this iterator points to a position in the world AFTER another iterator.

inline 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.

inline org_t &operator*()

Return a reference to the organism pointed to by this iterator.

inline const org_t &operator*() const

Return a const reference to the organism pointed to by this iterator.

inline operator bool() const

Is this iterator pointing to a valid cell in the world?

inline this_t begin()

Return an iterator pointing to the first occupied cell in the world.

inline const this_t begin() const

Return a const iterator pointing to the first occupied cell in the world.

inline this_t end()

Return an iterator pointing to just past the end of the world.

inline const this_t end() const

Return a const iterator pointing to just past the end of the world.

Private Types

using world_t = WORLD
using org_t = typename world_t::org_t
using this_t = World_iterator<world_t>

Private Functions

inline size_t WorldSize()
inline Ptr<org_t> OrgPtr()
inline void MakeValid()

Private Members

Ptr<world_t> world_ptr
size_t pos