package BoxTools; /** * a DataIterator object is used to iterate through the local * boxed data contained in a BoxLayoutData object. * a DataIterator object actually iterates through the layout * of a BoxLayoutData object. It returns a DataIndex * object each time. This DataIndex object is used to get the * corresponding BoxedArray from the BoxLayoutData. *

Usage: a DataIterator object must be declared local. A typical * way to use a DataIterator is * DataIterator local DIT = new DataIterator(a_BoxLayoutData.boxLayout()); * DataIndex local DI; * template BoxedArray local boxedArray; * while (!DIT.isEnded()){ * DI=LIT.access(); * boxedArray=a_BoxLayoutData.getLocalBoxedArray(DI); * ... * DIT.advance(); * } * * @see DataIndex, BoxLayout * @see Chombo Specification * @version 1.0 * @author Tong Wen, LBNL * @since 1.0 */ public class DataIterator{ private int m_index=0; private int m_procID=Ti.thisProc(); private BoxLayout local m_layout; private int m_numOfBoxes; private DataIterator(){} /*a_BL must be closed*/ public inline DataIterator(BoxLayout local a_BL){ if (!a_BL.isClosed()) Util.printErrMsg("DataIterator::DataIterator(): BoxLayout must be closed!"); m_layout=a_BL; m_numOfBoxes=m_layout.numBoxesAt(m_procID); } /* public inline DataIterator(BoxLayoutData local a_BLD){ m_layout=a_BLD.boxLayout(); if (!m_layout.isClosed()) Util.printErrMsg("DataIterator::DataIterator(): BoxLayout must be closed!"); m_numOfBoxes=m_layout.numBoxesAt(m_procID); }*/ public final inline local void reset(){ m_index=0; } public final inline local void advance(){ if (m_index < m_numOfBoxes) m_index++; } public final inline local DataIndex local getIndex(){ if (m_index < m_numOfBoxes) return new DataIndex(m_index,m_layout.getRoot(),m_procID); else return new DataIndex(m_numOfBoxes-1,m_layout.getRoot(),m_procID); } public final inline local DataIndex local access(){ if (m_index < m_numOfBoxes) return new DataIndex(m_index,m_layout.getRoot(),m_procID); else return new DataIndex(m_numOfBoxes-1,m_layout.getRoot(),m_procID); } public final inline local boolean isEnded(){ return (m_index>=m_numOfBoxes); } }