This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/grid/GridNeighborIterator.h
kazu cdf97322f8 added new data-structures
added new test-cases
added flexible dijkstra calculation
added debugging log
modified: plotting, grid-generation, grid-importance,
refactoring
2016-01-22 18:47:06 +01:00

67 lines
1.7 KiB
C++

#ifndef GRIDNEIGHBORITERATOR_H
#define GRIDNEIGHBORITERATOR_H
/** allows iterating over all neighbors of one node */
class NeighborIter : std::iterator<std::input_iterator_tag, int> {
private:
/** the grid the src-node belongs to */
const Grid<gridSize_cm, T>& grid;
/** index of the source-node within its grid */
const int srcNodeIdx;
/** index of the current neighbor [0:10] */
int nIdx;
public:
/** ctor */
NeighborIter(const Grid<gridSize_cm, T>& grid, const int srcNodeIdx, const int nIdx) :
grid(grid), srcNodeIdx(srcNodeIdx), nIdx(nIdx) {;}
/** next neighbor */
NeighborIter& operator++() {++nIdx; return *this;}
/** next neighbor */
NeighborIter operator++(int) {NeighborIter tmp(*this); operator++(); return tmp;}
/** compare with other iterator */
bool operator==(const NeighborIter& rhs) {return srcNodeIdx == rhs.srcNodeIdx && nIdx == rhs.nIdx;}
/** compare with other iterator */
bool operator!=(const NeighborIter& rhs) {return srcNodeIdx != rhs.srcNodeIdx || nIdx != rhs.nIdx;}
/** get the neighbor the iterator currently points to */
T& operator*() {return (T&) grid.getNeighbor(srcNodeIdx, nIdx);}
};
/** allows for-each iteration over all neighbors of one node */
class NeighborForEach {
private:
/** the grid the src-node belongs to */
const Grid<gridSize_cm, T>& grid;
/** index of the source-node within its grid */
const int srcNodeIdx;
public:
/** ctor */
NeighborForEach(const Grid<gridSize_cm, T>& grid, const int srcNodeIdx) :
grid(grid), srcNodeIdx(srcNodeIdx) {;}
/** starting point */
NeighborIter begin() {return NeighborIter(grid, srcNodeIdx, 0);}
/** end point */
NeighborIter end() {return NeighborIter(grid, srcNodeIdx, grid[srcNodeIdx]._numNeighbors);}
};
#endif // GRIDNEIGHBORITERATOR_H