author | simon <simon> | 2003-01-01 12:40:02 (UTC) |
---|---|---|
committer | simon <simon> | 2003-01-01 12:40:02 (UTC) |
commit | 25d85fe77aac5763ccc50bd532c2e661f4a64d1b (patch) (unidiff) | |
tree | 28a4a01f3bf232599db4f6c0d14162d6ac61bbd3 | |
parent | 31cbc7a5e6cc0a52b58d4de34cc8581a18bc4527 (diff) | |
download | opie-25d85fe77aac5763ccc50bd532c2e661f4a64d1b.zip opie-25d85fe77aac5763ccc50bd532c2e661f4a64d1b.tar.gz opie-25d85fe77aac5763ccc50bd532c2e661f4a64d1b.tar.bz2 |
T ORecordList<T>::operator[]( uint i ) {
- if ( i < 0 || (i+1) > m_ids.count() )
+ if ( i >= m_ids.count() )
-> fix warning and simplify :)
-rw-r--r-- | libopie/pim/orecordlist.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index b77a4ab..edcd729 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -1,300 +1,300 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | 17 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 20 | friend class ORecordList<T>; |
21 | public: | 21 | public: |
22 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The c'tor used internally from | 25 | * The c'tor used internally from |
26 | * ORecordList | 26 | * ORecordList |
27 | */ | 27 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The standard c'tor | 31 | * The standard c'tor |
32 | */ | 32 | */ |
33 | ORecordListIterator(); | 33 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
35 | 35 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * a * operator ;) | 40 | * a * operator ;) |
41 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
42 | */ | 42 | */ |
43 | T operator*(); | 43 | T operator*(); |
44 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
46 | 46 | ||
47 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * the current item | 51 | * the current item |
52 | */ | 52 | */ |
53 | uint current()const; | 53 | uint current()const; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * the number of items | 56 | * the number of items |
57 | */ | 57 | */ |
58 | uint count()const; | 58 | uint count()const; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * sets the current item | 61 | * sets the current item |
62 | */ | 62 | */ |
63 | void setCurrent( uint cur ); | 63 | void setCurrent( uint cur ); |
64 | 64 | ||
65 | private: | 65 | private: |
66 | QArray<int> m_uids; | 66 | QArray<int> m_uids; |
67 | uint m_current; | 67 | uint m_current; |
68 | const Base* m_temp; | 68 | const Base* m_temp; |
69 | bool m_end : 1; | 69 | bool m_end : 1; |
70 | T m_record; | 70 | T m_record; |
71 | bool m_direction :1; | 71 | bool m_direction :1; |
72 | 72 | ||
73 | /* d pointer for future versions */ | 73 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 74 | class IteratorPrivate; |
75 | IteratorPrivate *d; | 75 | IteratorPrivate *d; |
76 | }; | 76 | }; |
77 | /** | 77 | /** |
78 | * The recordlist used as a return type | 78 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 79 | * from OPimAccessTemplate |
80 | */ | 80 | */ |
81 | template <class T = OPimRecord > | 81 | template <class T = OPimRecord > |
82 | class ORecordList { | 82 | class ORecordList { |
83 | public: | 83 | public: |
84 | typedef OTemplateBase<T> Base; | 84 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 85 | typedef ORecordListIterator<T> Iterator; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * c'tor | 88 | * c'tor |
89 | */ | 89 | */ |
90 | ORecordList () { | 90 | ORecordList () { |
91 | } | 91 | } |
92 | ORecordList( const QArray<int>& ids, | 92 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 93 | const Base* ); |
94 | ~ORecordList(); | 94 | ~ORecordList(); |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * the first iterator | 97 | * the first iterator |
98 | */ | 98 | */ |
99 | Iterator begin(); | 99 | Iterator begin(); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * the end | 102 | * the end |
103 | */ | 103 | */ |
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | 112 | int uidAt(uint i ); |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Remove the contact with given uid | 115 | * Remove the contact with given uid |
116 | */ | 116 | */ |
117 | bool remove( int uid ); | 117 | bool remove( int uid ); |
118 | 118 | ||
119 | /* | 119 | /* |
120 | ConstIterator begin()const; | 120 | ConstIterator begin()const; |
121 | ConstIterator end()const; | 121 | ConstIterator end()const; |
122 | */ | 122 | */ |
123 | private: | 123 | private: |
124 | QArray<int> m_ids; | 124 | QArray<int> m_ids; |
125 | const Base* m_acc; | 125 | const Base* m_acc; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | /* ok now implement it */ | 128 | /* ok now implement it */ |
129 | template <class T> | 129 | template <class T> |
130 | ORecordListIterator<T>::ORecordListIterator() { | 130 | ORecordListIterator<T>::ORecordListIterator() { |
131 | m_current = 0; | 131 | m_current = 0; |
132 | m_temp = 0l; | 132 | m_temp = 0l; |
133 | m_end = true; | 133 | m_end = true; |
134 | m_record = T(); | 134 | m_record = T(); |
135 | /* forward */ | 135 | /* forward */ |
136 | m_direction = TRUE; | 136 | m_direction = TRUE; |
137 | } | 137 | } |
138 | template <class T> | 138 | template <class T> |
139 | ORecordListIterator<T>::~ORecordListIterator() { | 139 | ORecordListIterator<T>::~ORecordListIterator() { |
140 | /* nothing to delete */ | 140 | /* nothing to delete */ |
141 | } | 141 | } |
142 | 142 | ||
143 | template <class T> | 143 | template <class T> |
144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
145 | // qWarning("ORecordListIterator copy c'tor"); | 145 | // qWarning("ORecordListIterator copy c'tor"); |
146 | m_uids = it.m_uids; | 146 | m_uids = it.m_uids; |
147 | m_current = it.m_current; | 147 | m_current = it.m_current; |
148 | m_temp = it.m_temp; | 148 | m_temp = it.m_temp; |
149 | m_end = it.m_end; | 149 | m_end = it.m_end; |
150 | m_record = it.m_record; | 150 | m_record = it.m_record; |
151 | m_direction = it.m_direction; | 151 | m_direction = it.m_direction; |
152 | } | 152 | } |
153 | 153 | ||
154 | template <class T> | 154 | template <class T> |
155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
156 | m_uids = it.m_uids; | 156 | m_uids = it.m_uids; |
157 | m_current = it.m_current; | 157 | m_current = it.m_current; |
158 | m_temp = it.m_temp; | 158 | m_temp = it.m_temp; |
159 | m_end = it.m_end; | 159 | m_end = it.m_end; |
160 | m_record = it.m_record; | 160 | m_record = it.m_record; |
161 | 161 | ||
162 | return *this; | 162 | return *this; |
163 | } | 163 | } |
164 | 164 | ||
165 | template <class T> | 165 | template <class T> |
166 | T ORecordListIterator<T>::operator*() { | 166 | T ORecordListIterator<T>::operator*() { |
167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
168 | if (!m_end ) | 168 | if (!m_end ) |
169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
170 | m_direction ? Base::Forward : | 170 | m_direction ? Base::Forward : |
171 | Base::Reverse ); | 171 | Base::Reverse ); |
172 | else | 172 | else |
173 | m_record = T(); | 173 | m_record = T(); |
174 | 174 | ||
175 | return m_record; | 175 | return m_record; |
176 | } | 176 | } |
177 | 177 | ||
178 | template <class T> | 178 | template <class T> |
179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
180 | m_direction = true; | 180 | m_direction = true; |
181 | if (m_current < m_uids.count() ) { | 181 | if (m_current < m_uids.count() ) { |
182 | m_end = false; | 182 | m_end = false; |
183 | ++m_current; | 183 | ++m_current; |
184 | }else | 184 | }else |
185 | m_end = true; | 185 | m_end = true; |
186 | 186 | ||
187 | return *this; | 187 | return *this; |
188 | } | 188 | } |
189 | template <class T> | 189 | template <class T> |
190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
191 | m_direction = false; | 191 | m_direction = false; |
192 | if ( m_current > 0 ) { | 192 | if ( m_current > 0 ) { |
193 | --m_current; | 193 | --m_current; |
194 | m_end = false; | 194 | m_end = false; |
195 | } else | 195 | } else |
196 | m_end = true; | 196 | m_end = true; |
197 | 197 | ||
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | template <class T> | 201 | template <class T> |
202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
203 | 203 | ||
204 | /* if both are at we're the same.... */ | 204 | /* if both are at we're the same.... */ |
205 | if ( m_end == it.m_end ) return true; | 205 | if ( m_end == it.m_end ) return true; |
206 | 206 | ||
207 | if ( m_uids != it.m_uids ) return false; | 207 | if ( m_uids != it.m_uids ) return false; |
208 | if ( m_current != it.m_current ) return false; | 208 | if ( m_current != it.m_current ) return false; |
209 | if ( m_temp != it.m_temp ) return false; | 209 | if ( m_temp != it.m_temp ) return false; |
210 | 210 | ||
211 | return true; | 211 | return true; |
212 | } | 212 | } |
213 | template <class T> | 213 | template <class T> |
214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
215 | return !(*this == it ); | 215 | return !(*this == it ); |
216 | } | 216 | } |
217 | template <class T> | 217 | template <class T> |
218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
219 | const Base* t ) | 219 | const Base* t ) |
220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
221 | m_direction( false ) | 221 | m_direction( false ) |
222 | { | 222 | { |
223 | } | 223 | } |
224 | template <class T> | 224 | template <class T> |
225 | uint ORecordListIterator<T>::current()const { | 225 | uint ORecordListIterator<T>::current()const { |
226 | return m_current; | 226 | return m_current; |
227 | } | 227 | } |
228 | template <class T> | 228 | template <class T> |
229 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 229 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
230 | if( cur < m_uids.count() ) { | 230 | if( cur < m_uids.count() ) { |
231 | m_end = false; | 231 | m_end = false; |
232 | m_current= cur; | 232 | m_current= cur; |
233 | } | 233 | } |
234 | } | 234 | } |
235 | template <class T> | 235 | template <class T> |
236 | uint ORecordListIterator<T>::count()const { | 236 | uint ORecordListIterator<T>::count()const { |
237 | return m_uids.count(); | 237 | return m_uids.count(); |
238 | } | 238 | } |
239 | template <class T> | 239 | template <class T> |
240 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 240 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
241 | const Base* acc ) | 241 | const Base* acc ) |
242 | : m_ids( ids ), m_acc( acc ) | 242 | : m_ids( ids ), m_acc( acc ) |
243 | { | 243 | { |
244 | } | 244 | } |
245 | template <class T> | 245 | template <class T> |
246 | ORecordList<T>::~ORecordList() { | 246 | ORecordList<T>::~ORecordList() { |
247 | /* nothing to do here */ | 247 | /* nothing to do here */ |
248 | } | 248 | } |
249 | template <class T> | 249 | template <class T> |
250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { |
251 | Iterator it( m_ids, m_acc ); | 251 | Iterator it( m_ids, m_acc ); |
252 | return it; | 252 | return it; |
253 | } | 253 | } |
254 | template <class T> | 254 | template <class T> |
255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { |
256 | Iterator it( m_ids, m_acc ); | 256 | Iterator it( m_ids, m_acc ); |
257 | it.m_end = true; | 257 | it.m_end = true; |
258 | it.m_current = m_ids.count(); | 258 | it.m_current = m_ids.count(); |
259 | 259 | ||
260 | return it; | 260 | return it; |
261 | } | 261 | } |
262 | template <class T> | 262 | template <class T> |
263 | uint ORecordList<T>::count()const { | 263 | uint ORecordList<T>::count()const { |
264 | return m_ids.count(); | 264 | return m_ids.count(); |
265 | } | 265 | } |
266 | template <class T> | 266 | template <class T> |
267 | T ORecordList<T>::operator[]( uint i ) { | 267 | T ORecordList<T>::operator[]( uint i ) { |
268 | if ( i < 0 || (i+1) > m_ids.count() ) | 268 | if ( i >= m_ids.count() ) |
269 | return T(); | 269 | return T(); |
270 | /* forward */ | 270 | /* forward */ |
271 | return m_acc->find( m_ids[i], m_ids, i ); | 271 | return m_acc->find( m_ids[i], m_ids, i ); |
272 | } | 272 | } |
273 | template <class T> | 273 | template <class T> |
274 | int ORecordList<T>::uidAt( uint i ) { | 274 | int ORecordList<T>::uidAt( uint i ) { |
275 | return m_ids[i]; | 275 | return m_ids[i]; |
276 | } | 276 | } |
277 | 277 | ||
278 | template <class T> | 278 | template <class T> |
279 | bool ORecordList<T>::remove( int uid ) { | 279 | bool ORecordList<T>::remove( int uid ) { |
280 | QArray<int> copy( m_ids.count() ); | 280 | QArray<int> copy( m_ids.count() ); |
281 | int counter = 0; | 281 | int counter = 0; |
282 | bool ret_val = false; | 282 | bool ret_val = false; |
283 | 283 | ||
284 | for (uint i = 0; i < m_ids.count(); i++){ | 284 | for (uint i = 0; i < m_ids.count(); i++){ |
285 | if ( m_ids[i] != uid ){ | 285 | if ( m_ids[i] != uid ){ |
286 | copy[counter++] = m_ids[i]; | 286 | copy[counter++] = m_ids[i]; |
287 | 287 | ||
288 | }else | 288 | }else |
289 | ret_val = true; | 289 | ret_val = true; |
290 | } | 290 | } |
291 | 291 | ||
292 | copy.resize( counter ); | 292 | copy.resize( counter ); |
293 | m_ids = copy; | 293 | m_ids = copy; |
294 | 294 | ||
295 | 295 | ||
296 | return ret_val; | 296 | return ret_val; |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | #endif | 300 | #endif |
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index b77a4ab..edcd729 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,300 +1,300 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | 17 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 20 | friend class ORecordList<T>; |
21 | public: | 21 | public: |
22 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The c'tor used internally from | 25 | * The c'tor used internally from |
26 | * ORecordList | 26 | * ORecordList |
27 | */ | 27 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The standard c'tor | 31 | * The standard c'tor |
32 | */ | 32 | */ |
33 | ORecordListIterator(); | 33 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
35 | 35 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * a * operator ;) | 40 | * a * operator ;) |
41 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
42 | */ | 42 | */ |
43 | T operator*(); | 43 | T operator*(); |
44 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
46 | 46 | ||
47 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * the current item | 51 | * the current item |
52 | */ | 52 | */ |
53 | uint current()const; | 53 | uint current()const; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * the number of items | 56 | * the number of items |
57 | */ | 57 | */ |
58 | uint count()const; | 58 | uint count()const; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * sets the current item | 61 | * sets the current item |
62 | */ | 62 | */ |
63 | void setCurrent( uint cur ); | 63 | void setCurrent( uint cur ); |
64 | 64 | ||
65 | private: | 65 | private: |
66 | QArray<int> m_uids; | 66 | QArray<int> m_uids; |
67 | uint m_current; | 67 | uint m_current; |
68 | const Base* m_temp; | 68 | const Base* m_temp; |
69 | bool m_end : 1; | 69 | bool m_end : 1; |
70 | T m_record; | 70 | T m_record; |
71 | bool m_direction :1; | 71 | bool m_direction :1; |
72 | 72 | ||
73 | /* d pointer for future versions */ | 73 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 74 | class IteratorPrivate; |
75 | IteratorPrivate *d; | 75 | IteratorPrivate *d; |
76 | }; | 76 | }; |
77 | /** | 77 | /** |
78 | * The recordlist used as a return type | 78 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 79 | * from OPimAccessTemplate |
80 | */ | 80 | */ |
81 | template <class T = OPimRecord > | 81 | template <class T = OPimRecord > |
82 | class ORecordList { | 82 | class ORecordList { |
83 | public: | 83 | public: |
84 | typedef OTemplateBase<T> Base; | 84 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 85 | typedef ORecordListIterator<T> Iterator; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * c'tor | 88 | * c'tor |
89 | */ | 89 | */ |
90 | ORecordList () { | 90 | ORecordList () { |
91 | } | 91 | } |
92 | ORecordList( const QArray<int>& ids, | 92 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 93 | const Base* ); |
94 | ~ORecordList(); | 94 | ~ORecordList(); |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * the first iterator | 97 | * the first iterator |
98 | */ | 98 | */ |
99 | Iterator begin(); | 99 | Iterator begin(); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * the end | 102 | * the end |
103 | */ | 103 | */ |
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | 112 | int uidAt(uint i ); |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * Remove the contact with given uid | 115 | * Remove the contact with given uid |
116 | */ | 116 | */ |
117 | bool remove( int uid ); | 117 | bool remove( int uid ); |
118 | 118 | ||
119 | /* | 119 | /* |
120 | ConstIterator begin()const; | 120 | ConstIterator begin()const; |
121 | ConstIterator end()const; | 121 | ConstIterator end()const; |
122 | */ | 122 | */ |
123 | private: | 123 | private: |
124 | QArray<int> m_ids; | 124 | QArray<int> m_ids; |
125 | const Base* m_acc; | 125 | const Base* m_acc; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | /* ok now implement it */ | 128 | /* ok now implement it */ |
129 | template <class T> | 129 | template <class T> |
130 | ORecordListIterator<T>::ORecordListIterator() { | 130 | ORecordListIterator<T>::ORecordListIterator() { |
131 | m_current = 0; | 131 | m_current = 0; |
132 | m_temp = 0l; | 132 | m_temp = 0l; |
133 | m_end = true; | 133 | m_end = true; |
134 | m_record = T(); | 134 | m_record = T(); |
135 | /* forward */ | 135 | /* forward */ |
136 | m_direction = TRUE; | 136 | m_direction = TRUE; |
137 | } | 137 | } |
138 | template <class T> | 138 | template <class T> |
139 | ORecordListIterator<T>::~ORecordListIterator() { | 139 | ORecordListIterator<T>::~ORecordListIterator() { |
140 | /* nothing to delete */ | 140 | /* nothing to delete */ |
141 | } | 141 | } |
142 | 142 | ||
143 | template <class T> | 143 | template <class T> |
144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
145 | // qWarning("ORecordListIterator copy c'tor"); | 145 | // qWarning("ORecordListIterator copy c'tor"); |
146 | m_uids = it.m_uids; | 146 | m_uids = it.m_uids; |
147 | m_current = it.m_current; | 147 | m_current = it.m_current; |
148 | m_temp = it.m_temp; | 148 | m_temp = it.m_temp; |
149 | m_end = it.m_end; | 149 | m_end = it.m_end; |
150 | m_record = it.m_record; | 150 | m_record = it.m_record; |
151 | m_direction = it.m_direction; | 151 | m_direction = it.m_direction; |
152 | } | 152 | } |
153 | 153 | ||
154 | template <class T> | 154 | template <class T> |
155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 155 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
156 | m_uids = it.m_uids; | 156 | m_uids = it.m_uids; |
157 | m_current = it.m_current; | 157 | m_current = it.m_current; |
158 | m_temp = it.m_temp; | 158 | m_temp = it.m_temp; |
159 | m_end = it.m_end; | 159 | m_end = it.m_end; |
160 | m_record = it.m_record; | 160 | m_record = it.m_record; |
161 | 161 | ||
162 | return *this; | 162 | return *this; |
163 | } | 163 | } |
164 | 164 | ||
165 | template <class T> | 165 | template <class T> |
166 | T ORecordListIterator<T>::operator*() { | 166 | T ORecordListIterator<T>::operator*() { |
167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 167 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
168 | if (!m_end ) | 168 | if (!m_end ) |
169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 169 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
170 | m_direction ? Base::Forward : | 170 | m_direction ? Base::Forward : |
171 | Base::Reverse ); | 171 | Base::Reverse ); |
172 | else | 172 | else |
173 | m_record = T(); | 173 | m_record = T(); |
174 | 174 | ||
175 | return m_record; | 175 | return m_record; |
176 | } | 176 | } |
177 | 177 | ||
178 | template <class T> | 178 | template <class T> |
179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 179 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
180 | m_direction = true; | 180 | m_direction = true; |
181 | if (m_current < m_uids.count() ) { | 181 | if (m_current < m_uids.count() ) { |
182 | m_end = false; | 182 | m_end = false; |
183 | ++m_current; | 183 | ++m_current; |
184 | }else | 184 | }else |
185 | m_end = true; | 185 | m_end = true; |
186 | 186 | ||
187 | return *this; | 187 | return *this; |
188 | } | 188 | } |
189 | template <class T> | 189 | template <class T> |
190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 190 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
191 | m_direction = false; | 191 | m_direction = false; |
192 | if ( m_current > 0 ) { | 192 | if ( m_current > 0 ) { |
193 | --m_current; | 193 | --m_current; |
194 | m_end = false; | 194 | m_end = false; |
195 | } else | 195 | } else |
196 | m_end = true; | 196 | m_end = true; |
197 | 197 | ||
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | template <class T> | 201 | template <class T> |
202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
203 | 203 | ||
204 | /* if both are at we're the same.... */ | 204 | /* if both are at we're the same.... */ |
205 | if ( m_end == it.m_end ) return true; | 205 | if ( m_end == it.m_end ) return true; |
206 | 206 | ||
207 | if ( m_uids != it.m_uids ) return false; | 207 | if ( m_uids != it.m_uids ) return false; |
208 | if ( m_current != it.m_current ) return false; | 208 | if ( m_current != it.m_current ) return false; |
209 | if ( m_temp != it.m_temp ) return false; | 209 | if ( m_temp != it.m_temp ) return false; |
210 | 210 | ||
211 | return true; | 211 | return true; |
212 | } | 212 | } |
213 | template <class T> | 213 | template <class T> |
214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
215 | return !(*this == it ); | 215 | return !(*this == it ); |
216 | } | 216 | } |
217 | template <class T> | 217 | template <class T> |
218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
219 | const Base* t ) | 219 | const Base* t ) |
220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
221 | m_direction( false ) | 221 | m_direction( false ) |
222 | { | 222 | { |
223 | } | 223 | } |
224 | template <class T> | 224 | template <class T> |
225 | uint ORecordListIterator<T>::current()const { | 225 | uint ORecordListIterator<T>::current()const { |
226 | return m_current; | 226 | return m_current; |
227 | } | 227 | } |
228 | template <class T> | 228 | template <class T> |
229 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 229 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
230 | if( cur < m_uids.count() ) { | 230 | if( cur < m_uids.count() ) { |
231 | m_end = false; | 231 | m_end = false; |
232 | m_current= cur; | 232 | m_current= cur; |
233 | } | 233 | } |
234 | } | 234 | } |
235 | template <class T> | 235 | template <class T> |
236 | uint ORecordListIterator<T>::count()const { | 236 | uint ORecordListIterator<T>::count()const { |
237 | return m_uids.count(); | 237 | return m_uids.count(); |
238 | } | 238 | } |
239 | template <class T> | 239 | template <class T> |
240 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 240 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
241 | const Base* acc ) | 241 | const Base* acc ) |
242 | : m_ids( ids ), m_acc( acc ) | 242 | : m_ids( ids ), m_acc( acc ) |
243 | { | 243 | { |
244 | } | 244 | } |
245 | template <class T> | 245 | template <class T> |
246 | ORecordList<T>::~ORecordList() { | 246 | ORecordList<T>::~ORecordList() { |
247 | /* nothing to do here */ | 247 | /* nothing to do here */ |
248 | } | 248 | } |
249 | template <class T> | 249 | template <class T> |
250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 250 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { |
251 | Iterator it( m_ids, m_acc ); | 251 | Iterator it( m_ids, m_acc ); |
252 | return it; | 252 | return it; |
253 | } | 253 | } |
254 | template <class T> | 254 | template <class T> |
255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 255 | typename ORecordList<T>::Iterator ORecordList<T>::end() { |
256 | Iterator it( m_ids, m_acc ); | 256 | Iterator it( m_ids, m_acc ); |
257 | it.m_end = true; | 257 | it.m_end = true; |
258 | it.m_current = m_ids.count(); | 258 | it.m_current = m_ids.count(); |
259 | 259 | ||
260 | return it; | 260 | return it; |
261 | } | 261 | } |
262 | template <class T> | 262 | template <class T> |
263 | uint ORecordList<T>::count()const { | 263 | uint ORecordList<T>::count()const { |
264 | return m_ids.count(); | 264 | return m_ids.count(); |
265 | } | 265 | } |
266 | template <class T> | 266 | template <class T> |
267 | T ORecordList<T>::operator[]( uint i ) { | 267 | T ORecordList<T>::operator[]( uint i ) { |
268 | if ( i < 0 || (i+1) > m_ids.count() ) | 268 | if ( i >= m_ids.count() ) |
269 | return T(); | 269 | return T(); |
270 | /* forward */ | 270 | /* forward */ |
271 | return m_acc->find( m_ids[i], m_ids, i ); | 271 | return m_acc->find( m_ids[i], m_ids, i ); |
272 | } | 272 | } |
273 | template <class T> | 273 | template <class T> |
274 | int ORecordList<T>::uidAt( uint i ) { | 274 | int ORecordList<T>::uidAt( uint i ) { |
275 | return m_ids[i]; | 275 | return m_ids[i]; |
276 | } | 276 | } |
277 | 277 | ||
278 | template <class T> | 278 | template <class T> |
279 | bool ORecordList<T>::remove( int uid ) { | 279 | bool ORecordList<T>::remove( int uid ) { |
280 | QArray<int> copy( m_ids.count() ); | 280 | QArray<int> copy( m_ids.count() ); |
281 | int counter = 0; | 281 | int counter = 0; |
282 | bool ret_val = false; | 282 | bool ret_val = false; |
283 | 283 | ||
284 | for (uint i = 0; i < m_ids.count(); i++){ | 284 | for (uint i = 0; i < m_ids.count(); i++){ |
285 | if ( m_ids[i] != uid ){ | 285 | if ( m_ids[i] != uid ){ |
286 | copy[counter++] = m_ids[i]; | 286 | copy[counter++] = m_ids[i]; |
287 | 287 | ||
288 | }else | 288 | }else |
289 | ret_val = true; | 289 | ret_val = true; |
290 | } | 290 | } |
291 | 291 | ||
292 | copy.resize( counter ); | 292 | copy.resize( counter ); |
293 | m_ids = copy; | 293 | m_ids = copy; |
294 | 294 | ||
295 | 295 | ||
296 | return ret_val; | 296 | return ret_val; |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | #endif | 300 | #endif |