00001 00007 /* 00008 UniqueSet template - (hashtable) 00009 */ 00010 00011 #ifndef USITER_H 00012 #define USITER_H 00013 00014 #include "InfoStream.h" 00015 #include "UniqueSetRaw.h" 00016 #include "UniqueSet.h" 00017 00018 00019 template <class T> class UniqueSetIter { 00020 00021 private: 00022 00023 UniqueSet<T> *us; 00024 EntryGlob<T> *eg; 00025 int index; 00026 00027 public: 00028 00029 UniqueSetIter(void) { us = NULL; eg = NULL; index = 0; } 00030 00031 UniqueSetIter(UniqueSet<T>& us_param) { 00032 us = &us_param; eg = us_param.rep->globHead; index = 0; 00033 } 00034 00035 UniqueSetIter(const UniqueSetIter<T>& iter) { 00036 us = iter.us; eg = iter.eg; index = iter.index; 00037 } 00038 00039 UniqueSetIter<T>& operator= (const UniqueSetIter<T>& iter) { 00040 us = iter.us; eg = iter.eg; index = iter.index; return (*this); 00041 } 00042 00043 ~UniqueSetIter(void) {} 00044 00045 T *operator->(void) { 00046 gotoUsed(); 00047 if (eg) 00048 return (T *)&(eg->glob[index].obj); 00049 else { 00050 index = 0; 00051 return(NULL); 00052 } 00053 } 00054 00055 UniqueSetIter<T> begin(void) const { 00056 UniqueSetIter<T> iter; 00057 iter.us = us; 00058 iter.index = 0; 00059 iter.eg = us->rep->globHead; 00060 iter.gotoUsed(); 00061 return(iter); 00062 } 00063 00064 UniqueSetIter<T> end(void) const { 00065 UniqueSetIter<T> iter; 00066 iter.us = us; 00067 iter.index = 0; 00068 iter.eg = NULL; 00069 return(iter); 00070 } 00071 00072 int operator!= (const UniqueSetIter<T> &iter) const { 00073 return (iter.index != index || iter.eg != eg); 00074 } 00075 00076 int operator== (const UniqueSetIter<T> &iter) const { 00077 return (!operator!=(iter)); 00078 } 00079 00080 UniqueSetIter<T> operator++(void) { 00081 index++; 00082 gotoUsed(); 00083 return (*this); 00084 } 00085 00086 UniqueSetIter<T> operator++(int) { 00087 UniqueSetIter<T> tmp(*this); 00088 index++; 00089 gotoUsed(); 00090 return (tmp); 00091 } 00092 00093 T& operator* (void) { 00094 gotoUsed(); 00095 return *((T *)&(eg->glob[index].obj)); 00096 } 00097 00098 void status(void) { 00099 std::cout << "Index is " << index << " addr is " << eg << std::endl; 00100 } 00101 00102 void gotoUsed(void) { 00103 while (eg) { 00104 for(;index < us->rep->globSize; index++) { 00105 if (eg->glob[index].isUsed()) break; 00106 } 00107 if (index < us->rep->globSize) break; 00108 index = 0; 00109 eg = eg->next(); 00110 } 00111 if (!eg) index = 0; 00112 } 00113 }; 00114 00115 #endif
1.3.9.1