NAMD
ResizeArrayIter.h
Go to the documentation of this file.
1 
7 #ifndef RAITER_H
8 #define RAITER_H
9 
10 #include "ResizeArray.h"
11 
12 // Don't use for speed - use iter if later we will probably want
13 // to use a better container class for better space or algorithm behavior
14 
15 template <class T> class ResizeArrayIter {
16  private:
17 
18  ResizeArray<T> *array;
19  int currentIndex;
20 
21  public:
22 
23  T *operator->(void) { return ((array->rep.array)+currentIndex); }
24 
26  array = NULL;
27  currentIndex = 0;
28  }
29 
31  array = &ra;
32  currentIndex = 0;
33  }
34 
36  array = iter.array;
37  currentIndex = iter.currentIndex;
38  }
39 
41  array = iter.array;
42  currentIndex = iter.currentIndex;
43  return (*this);
44  }
45 
47 
48  ResizeArrayIter<T> begin(void) const {
49  ResizeArrayIter<T> iter;
50  iter.array = array;
51  iter.currentIndex = 0;
52  return(iter);
53  }
54 
55  ResizeArrayIter<T> end(void) const {
56  ResizeArrayIter<T> iter;
57  iter.array = array;
58  iter.currentIndex = array->size();
59  return(iter);
60  }
61 
62  int operator!= (const ResizeArrayIter<T> &iter) const {
63  return (iter.currentIndex != currentIndex || iter.array != array);
64  }
65 
66  int operator== (const ResizeArrayIter<T> &iter) const {
67  return (!operator!=(iter));
68  }
69 
71  currentIndex++;
72  return (*this);
73  }
74 
76  ResizeArrayIter<T> tmp(*this);
77  currentIndex++;
78  return (tmp);
79  }
80 
81  T& operator* (void) const {
82  return array->rep.array[currentIndex];
83  }
84 };
85 
86 #endif
int operator==(const ResizeArrayIter< T > &iter) const
ResizeArrayIter< T > end(void) const
ResizeArrayIter< T > & operator=(const ResizeArrayIter< T > &iter)
ResizeArrayIter< T > operator++(int)
T & operator*(void) const
ResizeArrayIter< T > operator++(void)
ResizeArrayIter(ResizeArray< T > &ra)
T * operator->(void)
int operator!=(const ResizeArrayIter< T > &iter) const
ResizeArrayIter< T > begin(void) const
ResizeArrayIter(const ResizeArrayIter< T > &iter)