ArrayIterator.inl
Go to the documentation of this file.00001 //*** ArrayIterator.inl *** 00002 00003 #include "Debug.h" 00004 00005 00006 //*** Constructor *** 00007 00008 template <class TYPE> 00009 ArrayIterator<TYPE>::ArrayIterator(const Array<TYPE>& array): 00010 array_(&array), 00011 get_(0) 00012 { 00013 MoveFirst(); // Make sure it is reset to the first item on initialization 00014 } 00015 00016 00017 //*** MoveFirst *** 00018 00019 template <class TYPE> 00020 void ArrayIterator<TYPE>::MoveFirst() 00021 { 00022 get_=0; 00023 } 00024 00025 00026 //*** MoveNext*** 00027 00028 template <class TYPE> 00029 void ArrayIterator<TYPE>::MoveNext() 00030 { 00031 if (get_<array_.GetItemCount()) 00032 { 00033 get_++; 00034 } 00035 } 00036 00037 00038 //*** MovePrevious*** 00039 00040 template <class TYPE> 00041 void ArrayIterator<TYPE>::MovePrevious() 00042 { 00043 if (get_>=0) 00044 { 00045 get_--; 00046 } 00047 } 00048 00049 00050 //*** MoveLast *** 00051 00052 template <class TYPE> 00053 void ArrayIterator<TYPE>::MoveLast() 00054 { 00055 get_=array_->GetItemCount()-1; 00056 } 00057 00058 00059 //*** IsValid *** 00060 00061 template <class TYPE> 00062 bool ArrayIterator<TYPE>::IsValid() const 00063 { 00064 if (get_>=0 && get_<array_->GetItemCount()) 00065 { 00066 return true; 00067 } 00068 00069 return false; 00070 } 00071 00072 00073 //*** GetCurrent *** 00074 00075 template <class TYPE> 00076 TYPE& ArrayIterator<TYPE>::GetCurrent() const 00077 { 00078 Assert(get_>=0 && get_<array_->GetItemCount(),"Invalid get location"); 00079 if (get_>=0 && get_<array_->GetItemCount()) 00080 { 00081 return array_->Get(get_); 00082 } 00083 00084 static TYPE defaultValue; 00085 return defaultValue; 00086 } 00087 00088 00089 //*** GetCurrentIndex *** 00090 00091 template <class TYPE> 00092 int ArrayIterator<TYPE>::GetCurrentIndex() const 00093 { 00094 return get_; 00095 } 00096 00097 00098 //*** Find *** 00099 00100 template <class TYPE> 00101 bool ArrayIterator<TYPE>::Find(const TYPE& data) 00102 { 00103 // Loop through all items 00104 for (int i=0; i<array_->GetItemCount(); i++) 00105 { 00106 // Is the current item the one we are looking for? 00107 if (array_->Get(i)==data) 00108 { 00109 // Yes, so set the get pointer to point at it 00110 get_=i; 00111 00112 // And return true to indicate it was found 00113 return true; 00114 } 00115 } 00116 00117 // The item was not found, so return false to indicate this 00118 return false; 00119 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
