Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgConnCompIterator.h

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


17 Jun 2010 Doxygen 1.4.7