newimage
 
Loading...
Searching...
No Matches
lazyiterators.h
1/* Templated iterators for any storage class that uses lazymanager
2
3 Mark Jenkinson, FMRIB Image Analysis Group
4
5 Copyright (C) 2000 University of Oxford */
6
7/* CCOPYRIGHT */
8
9#if !defined(__lazyiterators_h)
10#define __lazyiterators_h
11
12#include <cstdlib>
13#include <iostream>
14#include "lazy.h"
15
16namespace LAZY {
17
18 // Mutable, Random Access Iterator
19
20 template <class IT, class T>
22 private:
23 IT iter;
24 lazymanager* lazyptr;
25 public:
26 rlazyiterator() : lazyptr(0) { }
27 rlazyiterator(const rlazyiterator<IT,T>& source) :
28 iter(source.iter) , lazyptr(source.lazyptr) { }
29 rlazyiterator(const IT& sourceiter, lazymanager* lazyp) :
30 iter(sourceiter) , lazyptr(lazyp) { }
31 ~rlazyiterator() { } // do nothing
32
33 inline const rlazyiterator<IT,T> operator++(int)
34 { rlazyiterator<IT,T> tmp=*this; iter++; return tmp; }
35 inline const rlazyiterator<IT,T>& operator++() // prefix
36 { ++iter; return *this; }
37 inline const rlazyiterator<IT,T> operator--(int)
38 { rlazyiterator<IT,T> tmp=*this; iter--; return tmp; }
39 inline const rlazyiterator<IT,T>& operator--() // prefix
40 { --iter; return *this; }
41
42 inline const rlazyiterator<IT,T>& operator+=(int n)
43 { iter+=n; return *this; }
44 inline const rlazyiterator<IT,T>& operator-=(int n)
45 { iter-=n; return *this; }
46
47// template <class ITF, class TF> friend const rlazyiterator<ITF,TF>
48// operator+(const rlazyiterator<ITF,TF>& it, int n)
49// { return rlazyiterator<ITF,TF>(it.iter + n,it.lazyptr); }
50// template <class ITF, class TF> friend const rlazyiterator<ITF,TF>
51// operator+(int n, const rlazyiterator<ITF,TF>& it)
52// { return rlazyiterator<ITF,TF>(n + it.iter,it.lazyptr); }
53// template <class ITF, class TF> friend const rlazyiterator<ITF,TF>
54// operator-(const rlazyiterator<ITF,TF>& it, int n)
55// { return rlazyiterator<ITF,TF>(it.iter - n,it.lazyptr); }
56// template <class ITF, class TF> friend const rlazyiterator<ITF,TF>
57// operator-(int n, const rlazyiterator<ITF,TF>& it)
58// { return rlazyiterator<ITF,TF>(n - it.iter,it.lazyptr); }
59
60
61 inline bool operator==(const rlazyiterator<IT,T>& it) const
62 { return iter == it.iter; }
63 inline bool operator!=(const rlazyiterator<IT,T>& it) const
64 { return iter != it.iter; }
65 inline bool operator<(const rlazyiterator<IT,T>& it) const
66 { return iter < it.iter; }
67 inline bool operator>(const rlazyiterator<IT,T>& it) const
68 { return iter > it.iter; }
69 inline bool operator<=(const rlazyiterator<IT,T>& it) const
70 { return iter <= it.iter; }
71 inline bool operator>=(const rlazyiterator<IT,T>& it) const
72 { return iter >= it.iter; }
73
74 inline const rlazyiterator<IT,T>&
75 operator=(const rlazyiterator<IT,T>& source)
76 { iter=source.iter; lazyptr = source.lazyptr; return *this; }
77
78 inline T& operator*() const
79 { lazyptr->set_whole_cache_validity(false); return *iter;}
80 inline T& operator[](int n) const { return *(this + n); }
81 };
82
83
84 //---------------------------------------------------------------------//
85
86 // Constant, Random Access Iterator
87
88 // Use normal constant iterator
89
90
91 //---------------------------------------------------------------------//
92
93 // Mutable, Bidirectional Iterator
94
95 template <class IT, class T>
97 private:
98 IT iter;
99 lazymanager* lazyptr;
100 public:
101 bilazyiterator() : lazyptr(0) { }
102 bilazyiterator(const bilazyiterator<IT,T>& source) :
103 iter(source.iter) , lazyptr(source.lazyptr) { }
104 bilazyiterator(const IT& sourceiter, lazymanager* lazyp) :
105 iter(sourceiter) , lazyptr(lazyp) { }
106 ~bilazyiterator() { } // do nothing
107
108 inline const bilazyiterator<IT,T> operator++(int)
109 { bilazyiterator<IT,T> tmp=*this; iter++; return tmp; }
110 inline const bilazyiterator<IT,T>& operator++() // prefix
111 { ++iter; return *this; }
112 inline const bilazyiterator<IT,T> operator--(int)
113 { bilazyiterator<IT,T> tmp=*this; iter--; return tmp; }
114 inline const bilazyiterator<IT,T>& operator--() // prefix
115 { --iter; return *this; }
116
117 inline bool operator==(const bilazyiterator<IT,T>& it) const
118 { return iter == it.iter; }
119 inline bool operator!=(const bilazyiterator<IT,T>& it) const
120 { return iter != it.iter; }
121
122 inline const bilazyiterator<IT,T>&
123 operator=(const bilazyiterator<IT,T>& source)
124 { iter=source.iter; lazyptr = source.lazyptr; return *this; }
125
126 inline T& operator*() const
127 { lazyptr->set_whole_cache_validity(false); return *iter;}
128 };
129
130
131 //---------------------------------------------------------------------//
132
133 // Constant, Bidirectional Iterator
134
135 // Use normal constant iterator
136
137 //---------------------------------------------------------------------//
138
139 // Mutable, Forward Iterator
140
141 template <class IT, class T>
143 private:
144 IT iter;
145 lazymanager* lazyptr;
146 public:
147 flazyiterator() : lazyptr(0) { }
148 flazyiterator(const flazyiterator<IT,T>& source) :
149 iter(source.iter) , lazyptr(source.lazyptr) { }
150 flazyiterator(const IT& sourceiter, lazymanager* lazyp) :
151 iter(sourceiter) , lazyptr(lazyp) { }
152 ~flazyiterator() { } // do nothing
153
154 inline const flazyiterator<IT,T> operator++(int)
155 { flazyiterator<IT,T> tmp=*this; iter++; return tmp; }
156 inline const flazyiterator<IT,T>& operator++() // prefix
157 { ++iter; return *this; }
158
159 inline bool operator==(const flazyiterator<IT,T>& it) const
160 { return iter == it.iter; }
161 inline bool operator!=(const flazyiterator<IT,T>& it) const
162 { return iter != it.iter; }
163
164 inline const flazyiterator<IT,T>&
165 operator=(const flazyiterator<IT,T>& source)
166 { iter=source.iter; lazyptr = source.lazyptr; return *this; }
167
168 inline T& operator*() const
169 { lazyptr->set_whole_cache_validity(false); return *iter;}
170 };
171
172
173 //---------------------------------------------------------------------//
174
175 // Constant, Forward Iterator
176
177 // Use normal constant iterator
178
179 //---------------------------------------------------------------------//
180
181} // end namespace
182
183#endif
Definition: lazyiterators.h:96
Definition: lazyiterators.h:142
Definition: lazy.h:50
Definition: lazyiterators.h:21