Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

DataIterator.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef DATAITERATOR_H
00029 #define DATAITERATOR_H
00030 
00031 #ifndef WRAPPER
00032 #include "DataIndex.H"
00033 #include "BoxLayout.H"
00034 #include "SPMD.H"
00035 #endif /* WRAPPER */
00036 
00038 
00050 class DataIterator
00051 {
00052 public:
00053   // default copy constructor should be fine
00054 
00056   DataIterator();
00057 
00058   ~DataIterator() {;}
00060   inline const DataIndex& operator()() const;
00061   DataIndex i() const { return this->operator()();}
00062 
00064   inline void operator++();
00065   void incr() { ++(*this);}
00066 
00068   bool ok() const;
00069 
00071   void reset();
00072 
00074   void begin();
00075 
00077 
00081   void end();
00082 
00083 private:
00084 
00085   friend class BoxLayout;
00086   friend class DisjointBoxLayout;
00087 
00088   DataIterator(const BoxLayout& boxlayout, const int* layoutID);
00089 
00090   //int m_begin, m_end;
00091 
00092   const BoxLayout m_layout;
00093 
00094   unsigned int m_index;
00095 
00096   DataIndex m_current;
00097 
00098   unsigned int m_procID;
00099 
00100 };
00101 
00102 #ifndef WRAPPER
00103 
00104 inline DataIterator::DataIterator()
00105   : m_index(0), m_procID(0)
00106 {}
00107 
00108 
00109 inline const DataIndex& DataIterator::operator()() const
00110 {
00111   assert(ok());
00112   return m_current;
00113 }
00114 
00115 inline void DataIterator::operator++()
00116 {
00117   const BoxLayout::Entry* box;
00118   while(++m_index < m_layout.size())
00119     {
00120       box = &(*(m_layout.m_boxes))[m_index];
00121       if(box->m_procID == m_procID)
00122         {
00123           m_current.m_index = box->index;
00124           return;
00125         }
00126     }
00127 
00128 }
00129 
00130 inline bool DataIterator::ok() const
00131 {
00132   return m_index < m_layout.size();
00133 }
00134 
00135 
00136 
00137 inline void DataIterator::reset()
00138 {
00139   begin();
00140 }
00141 
00142 inline void DataIterator::begin()
00143 {
00144   m_index = 0; 
00145   const BoxLayout::Entry* box;
00146   while(m_index < m_layout.size())
00147     {
00148       box = &(*(m_layout.m_boxes))[m_index];
00149       if(box->m_procID == m_procID)
00150         {
00151           m_current.m_index = box->index;
00152           return;
00153         }
00154       ++m_index;
00155     }
00156 }
00157 #endif
00158 
00159 #endif 

Generated on Wed Apr 16 14:31:04 2003 for EBChombo by doxygen1.2.16