00001 00007 #ifndef RAPITER_H 00008 #define RAPITER_H 00009 00010 #include "ResizeArray.h" 00011 00012 // Don't use for speed - use iter if later we will probably want 00013 // to use a better container class for better space or algorithm behavior 00014 00015 template <class T> class ResizeArrayPrimIter { 00016 private: 00017 00018 ResizeArray<T> *array; 00019 int currentIndex; 00020 00021 public: 00022 ResizeArrayPrimIter(void) { 00023 array = NULL; 00024 currentIndex = 0; 00025 } 00026 00027 ResizeArrayPrimIter(ResizeArray<T>& ra) { 00028 array = &ra; 00029 currentIndex = 0; 00030 } 00031 00032 ResizeArrayPrimIter(const ResizeArrayPrimIter<T>& iter) { 00033 array = iter.array; 00034 currentIndex = iter.currentIndex; 00035 } 00036 00037 ResizeArrayPrimIter<T>& operator= (const ResizeArrayPrimIter<T>& iter) { 00038 array = iter.array; 00039 currentIndex = iter.currentIndex; 00040 return (*this); 00041 } 00042 00043 ~ResizeArrayPrimIter(void) {} 00044 00045 ResizeArrayPrimIter<T> begin(void) const { 00046 ResizeArrayPrimIter<T> iter; 00047 iter.array = array; 00048 iter.currentIndex = 0; 00049 return(iter); 00050 } 00051 00052 ResizeArrayPrimIter<T> end(void) const { 00053 ResizeArrayPrimIter<T> iter; 00054 iter.array = array; 00055 iter.currentIndex = array->size(); 00056 return(iter); 00057 } 00058 00059 int operator!= (const ResizeArrayPrimIter<T> &iter) const { 00060 return (iter.currentIndex != currentIndex || iter.array != array); 00061 } 00062 00063 int operator== (const ResizeArrayPrimIter<T> &iter) const { 00064 return (!operator!=(iter)); 00065 } 00066 00067 ResizeArrayPrimIter<T> operator++(void) { 00068 currentIndex++; 00069 return (*this); 00070 } 00071 00072 ResizeArrayPrimIter<T> operator++(int) { 00073 ResizeArrayPrimIter<T> tmp(*this); 00074 currentIndex++; 00075 return (tmp); 00076 } 00077 00078 T& operator* (void) const { 00079 return array->operator[](currentIndex); 00080 } 00081 }; 00082 00083 #endif
1.3.9.1