ResizeArrayIter.h

Go to the documentation of this file.
00001 
00007 #ifndef RAITER_H
00008 #define RAITER_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 ResizeArrayIter {
00016   private:
00017 
00018     ResizeArray<T> *array;
00019     int currentIndex;
00020 
00021   public:
00022 
00023     T *operator->(void) { return ((array->rep.array)+currentIndex); }
00024 
00025     ResizeArrayIter(void) {
00026       array = NULL;
00027       currentIndex = 0;
00028     }
00029 
00030     ResizeArrayIter(ResizeArray<T>& ra) {
00031       array = &ra;
00032       currentIndex = 0;
00033     }
00034 
00035     ResizeArrayIter(const ResizeArrayIter<T>& iter) {
00036       array = iter.array;
00037       currentIndex = iter.currentIndex;
00038     }
00039 
00040     ResizeArrayIter<T>& operator= (const ResizeArrayIter<T>& iter) {
00041       array = iter.array;
00042       currentIndex = iter.currentIndex;
00043       return (*this);
00044     }
00045 
00046     ~ResizeArrayIter(void) {}
00047 
00048     ResizeArrayIter<T> begin(void) const {
00049       ResizeArrayIter<T> iter;
00050       iter.array = array;
00051       iter.currentIndex = 0;
00052       return(iter);
00053     }
00054 
00055     ResizeArrayIter<T> end(void) const {
00056       ResizeArrayIter<T> iter;
00057       iter.array = array;
00058       iter.currentIndex = array->size();
00059       return(iter);
00060     }
00061         
00062     int operator!= (const ResizeArrayIter<T> &iter) const {
00063       return (iter.currentIndex != currentIndex || iter.array != array);
00064     }
00065 
00066     int operator== (const ResizeArrayIter<T> &iter) const {
00067       return (!operator!=(iter));
00068     }
00069 
00070     ResizeArrayIter<T> operator++(void) {
00071       currentIndex++;
00072       return (*this);
00073     }
00074 
00075     ResizeArrayIter<T> operator++(int) {
00076       ResizeArrayIter<T> tmp(*this);
00077       currentIndex++;
00078       return (tmp);
00079     }
00080 
00081     T& operator* (void) const {
00082       return array->rep.array[currentIndex];
00083     }
00084 };
00085 
00086 #endif

Generated on Sat Nov 18 01:17:15 2017 for NAMD by  doxygen 1.4.7