Permalink
Browse files

made NormalizingIterator a bit safer to use by preventing accidental …

…casts
  • Loading branch information...
gentryx committed Jun 29, 2018
1 parent 4515a87 commit 6146ae85797f9b2c3a86d7a1762bd3b3773e038c
Showing with 27 additions and 8 deletions.
  1. +27 −8 src/libgeodecomp/storage/displacedgrid.h
@@ -33,16 +33,17 @@ namespace LibGeoDecomp {
namespace DisplacedGridHelpers {
template<class TOPOLOGY, bool TOPOLOGICALLY_CORRECT>
class NormalizingIterator : public RegionStreakIterator<TOPOLOGY::DIM, Region<TOPOLOGY::DIM> >
class NormalizingIterator : private RegionStreakIterator<TOPOLOGY::DIM, Region<TOPOLOGY::DIM> >
{
public:
static const int DIM = TOPOLOGY::DIM;
typedef RegionStreakIterator<DIM, Region<DIM> > StreakIterator;
inline NormalizingIterator(
const RegionStreakIterator<DIM, Region<DIM> >& iter,
const StreakIterator& iter,
const Coord<DIM>& origin,
const Coord<DIM>& topoDimensions) :
RegionStreakIterator<DIM, Region<DIM> >(iter),
StreakIterator(iter),
topoDimensions(topoDimensions)
{
this->offset -= origin;
@@ -52,23 +53,41 @@ class NormalizingIterator : public RegionStreakIterator<TOPOLOGY::DIM, Region<TO
}
inline NormalizingIterator(
const RegionStreakIterator<DIM, Region<DIM> >& iter,
const StreakIterator& iter,
const Coord<DIM>& topoDimensions) :
RegionStreakIterator<DIM, Region<DIM> >(iter),
StreakIterator(iter),
topoDimensions(topoDimensions)
{
normalize();
}
inline void operator++()
{
RegionStreakIterator<DIM, Region<DIM> >::operator++();
StreakIterator::operator++();
normalize();
}
inline bool operator==(const StreakIterator& other) const
{
return StreakIterator::operator==(other);
}
inline bool operator!=(const StreakIterator& other) const
{
return StreakIterator::operator!=(other);
}
inline const Streak<DIM>& operator*() const
{
return StreakIterator::operator*();
}
inline const Streak<DIM> *operator->() const
{
return StreakIterator::operator->();
}
private:
// fixme: get rid of this, too?
Streak<DIM> normalizedStreak;
const Coord<DIM>& topoDimensions;
inline void normalize()

0 comments on commit 6146ae8

Please sign in to comment.