00001 //---------------------------------------------------------------------------- 00002 /** @file SgConnCompIterator.h 00003 Classes ConnCompIterator and ConnComp8Iterator */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef SG_CONNCOMPITERATOR_H 00007 #define SG_CONNCOMPITERATOR_H 00008 00009 #include "SgPointSet.h" 00010 00011 //---------------------------------------------------------------------------- 00012 00013 /** Iterate through all connected components of a given set. 00014 Example: compute all blocks of a given color: 00015 <pre> 00016 for (ConnCompIterator it(board.All(color), board); it; ++it) DO 00017 { 00018 ...define block with points '*it' and color 'color'... 00019 } 00020 </pre> */ 00021 class SgConnCompIterator 00022 { 00023 public: 00024 /** Create an iterator to iterate through set on 'board'. */ 00025 SgConnCompIterator(const SgPointSet& set, int boardSize); 00026 00027 void operator++(); 00028 00029 const SgPointSet& operator*() const; 00030 00031 operator bool() const 00032 { 00033 return m_nextPoint <= m_lastBoardPoint; 00034 } 00035 00036 private: 00037 SgPointSet m_set; 00038 00039 SgPointSet m_nextSet; 00040 00041 int m_nextPoint; 00042 00043 int m_lastBoardPoint; 00044 }; 00045 00046 //---------------------------------------------------------------------------- 00047 00048 /** Iterate through all 8-connected components of a given set. */ 00049 class SgConnComp8Iterator 00050 { 00051 public: 00052 /** Create an iterator to iterate through set on 'board'. */ 00053 SgConnComp8Iterator(const SgPointSet& set, int boardSize); 00054 00055 void operator++(); 00056 00057 const SgPointSet& operator*() const; 00058 00059 operator bool() const 00060 { 00061 return m_nextPoint <= m_lastBoardPoint; 00062 } 00063 00064 private: 00065 SgPointSet m_set; 00066 00067 SgPointSet m_nextSet; 00068 00069 int m_nextPoint; 00070 00071 int m_lastBoardPoint; 00072 }; 00073 00074 //---------------------------------------------------------------------------- 00075 00076 #endif // SG_CONNCOMPITERATOR_H