added new helper methods/classes (e.g. for heading) new test cases optimize the dijkstra cleanups/refactoring added timed-benchmarks to the log many more...
67 lines
1.8 KiB
C++
67 lines
1.8 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 */
|
|
Grid<gridSize_cm, T>* grid;
|
|
|
|
/** index of the source-node within its grid */
|
|
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<gridSize_cm, T>*)&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
|