00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _MOMENTITERATOR_H_ 00012 #define _MOMENTITERATOR_H_ 00013 00014 #include "IndexedMoments.H" 00015 00016 #include "NamespaceHeader.H" 00017 00018 ///class to enable template containment 00019 template <int D> 00020 class BaseMomentIterator 00021 { 00022 public: 00023 /// 00024 /** 00025 */ 00026 BaseMomentIterator() 00027 { 00028 } 00029 00030 /// 00031 virtual ~BaseMomentIterator() 00032 { 00033 } 00034 00035 /// 00036 virtual void reset() = 0; 00037 00038 /// 00039 virtual void operator++()= 0; 00040 00041 /// 00042 virtual const IndexTM<int, D>& operator () () const = 0; 00043 00044 /// 00045 virtual bool ok() = 0; 00046 00047 virtual int size() const = 0; 00048 00049 }; 00050 00051 ///iterates through the indices of a IndexedMoment 00052 /** 00053 MomentIterator iterates through the multi-indices of a IndexedMoments. 00054 */ 00055 template <int D, int P> 00056 class MomentIterator: public BaseMomentIterator<D> 00057 { 00058 public: 00059 /// 00060 /** 00061 */ 00062 MomentIterator() 00063 { 00064 m_indicies = &(IndexedMoments<D,P>::getMonomialPowers()); 00065 m_current = 0; 00066 } 00067 00068 /// 00069 virtual ~MomentIterator() 00070 { 00071 } 00072 00073 /// 00074 virtual void reset() 00075 { 00076 m_current = 0; 00077 } 00078 00079 /// 00080 virtual void operator ++ () 00081 { 00082 m_current++; 00083 } 00084 00085 /// 00086 /** 00087 Returns the moment of the current multi-index of this MomentIterator. 00088 */ 00089 virtual const IndexTM<int, D>& operator () () const 00090 { 00091 return (*m_indicies)[m_current]; 00092 } 00093 00094 /// 00095 /** 00096 Returns true if this MomentIterator's location is within its IndexedMoment. 00097 */ 00098 virtual bool ok() 00099 { 00100 bool retval = m_current < m_indicies->size(); 00101 return retval; 00102 } 00103 00104 virtual int size() const 00105 { 00106 return m_indicies->size(); 00107 } 00108 protected: 00109 00110 00111 /// points to the (static) powers that live in IndexedMoments 00112 const Vector<IndexTM<int,D> >* m_indicies; 00113 00114 /// 00115 int m_current; 00116 00117 00118 }; 00119 00120 #include "NamespaceFooter.H" 00121 #endif