00001 //---------------------------------------------------------------------------- 00002 /** @file SgConnCompIterator.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "SgConnCompIterator.h" 00008 00009 using namespace std; 00010 00011 //---------------------------------------------------------------------------- 00012 00013 SgConnCompIterator::SgConnCompIterator(const SgPointSet& set, int boardSize) 00014 : m_set(set), 00015 m_nextPoint(SgPointUtil::Pt(1, 1) - 1), 00016 m_lastBoardPoint(SgPointUtil::Pt(boardSize, boardSize)) 00017 { 00018 SG_ASSERTRANGE(boardSize, 1, SG_MAX_SIZE); 00019 operator++(); // find first. 00020 } 00021 00022 void SgConnCompIterator::operator++() 00023 { 00024 ++m_nextPoint; 00025 while ((m_nextPoint <= m_lastBoardPoint) && !(m_set[m_nextPoint])) 00026 ++m_nextPoint; 00027 if (m_nextPoint <= m_lastBoardPoint) 00028 { 00029 m_nextSet = m_set.ConnComp(m_nextPoint); 00030 m_set -= m_nextSet; 00031 } 00032 } 00033 00034 const SgPointSet& SgConnCompIterator::operator*() const 00035 { 00036 SG_ASSERT(m_nextPoint <= m_lastBoardPoint); 00037 return m_nextSet; 00038 } 00039 00040 //---------------------------------------------------------------------------- 00041 00042 SgConnComp8Iterator::SgConnComp8Iterator(const SgPointSet& set, int boardSize) 00043 : m_set(set), 00044 m_nextPoint(SgPointUtil::Pt(1, 1) - 1), 00045 m_lastBoardPoint(SgPointUtil::Pt(boardSize, boardSize)) 00046 { 00047 SG_ASSERTRANGE(boardSize, 1, SG_MAX_SIZE); 00048 operator++(); // find first. 00049 } 00050 00051 void SgConnComp8Iterator::operator++() 00052 { 00053 ++m_nextPoint; 00054 while ((m_nextPoint <= m_lastBoardPoint) && !(m_set[m_nextPoint])) 00055 ++m_nextPoint; 00056 if (m_nextPoint <= m_lastBoardPoint) 00057 { 00058 m_nextSet = m_set.ConnComp8(m_nextPoint); 00059 m_set -= m_nextSet; 00060 } 00061 } 00062 00063 const SgPointSet& SgConnComp8Iterator::operator*() const 00064 { 00065 SG_ASSERT(m_nextPoint <= m_lastBoardPoint); 00066 return m_nextSet; 00067 } 00068 00069 //---------------------------------------------------------------------------- 00070