From a336aacb4fbb804b3ca692c0fe6a2708cfe1f440 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 13 Dec 2010 11:25:26 +0000 Subject: (svn r21494) -Codechange: split the tile iterator in two classes --- src/tilearea_type.h | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/tilearea_type.h b/src/tilearea_type.h index feaf919e8..01cffefae 100644 --- a/src/tilearea_type.h +++ b/src/tilearea_type.h @@ -60,24 +60,19 @@ struct TileArea { } }; -/** Iterator to iterate over a tile area (rectangle) of the map. */ +/** Base class for tile iterators. */ class TileIterator { -private: +protected: TileIndex tile; ///< The current tile we are at. - int w; ///< The width of the iterated area. - int x; ///< The current 'x' position in the rectangle. - int y; ///< The current 'y' position in the rectangle. -public: /** - * Construct the iterator. - * @param ta Area, i.e. begin point and width/height of to-be-iterated area. + * Initialise the iterator starting at this tile. + * @param tile The tile we start iterating from. */ - TileIterator(const TileArea &ta) : tile(ta.tile), w(ta.w), x(ta.w), y(ta.h) + TileIterator(TileIndex tile) : tile(tile) { - if (ta.w == 0 || ta.h == 0) this->tile = INVALID_TILE; } - +public: /** * Get the tile we are currently at. * @return The tile we are at, or INVALID_TILE when we're done. @@ -87,6 +82,28 @@ public: return this->tile; } + /** + * Move ourselves to the next tile in the rectange on the map. + */ + virtual TileIterator& operator ++() = 0; +}; + +/** Iterator to iterate over a tile area (rectangle) of the map. */ +class OrthogonalTileIterator : public TileIterator { +private: + int w; ///< The width of the iterated area. + int x; ///< The current 'x' position in the rectangle. + int y; ///< The current 'y' position in the rectangle. + +public: + /** + * Construct the iterator. + * @param ta Area, i.e. begin point and width/height of to-be-iterated area. + */ + OrthogonalTileIterator(const TileArea &ta) : TileIterator(ta.w == 0 || ta.h == 0 ? INVALID_TILE : ta.tile), w(ta.w), x(ta.w), y(ta.h) + { + } + /** * Move ourselves to the next tile in the rectange on the map. */ @@ -112,6 +129,6 @@ public: * This variable will be allocated in this \c for of this loop. * @param ta The tile area to search over. */ -#define TILE_AREA_LOOP(var, ta) for (TileIterator var(ta); var != INVALID_TILE; ++var) +#define TILE_AREA_LOOP(var, ta) for (OrthogonalTileIterator var(ta); var != INVALID_TILE; ++var) #endif /* TILEAREA_TYPE_H */ -- cgit v1.2.3-54-g00ecf