Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 230 |
1 files changed, 148 insertions, 82 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 8f0011b..1742dcc 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -29,7 +29,6 @@ | |||
29 | 29 | ||
30 | #ifndef OPIE_RECORD_LIST_H | 30 | #ifndef ORECORDLIST_H |
31 | #define OPIE_RECORD_LIST_H | 31 | #define ORECORDLIST_H |
32 | |||
33 | #include <qarray.h> | ||
34 | 32 | ||
33 | /* OPIE */ | ||
35 | #include <opie2/otemplatebase.h> | 34 | #include <opie2/otemplatebase.h> |
@@ -37,3 +36,7 @@ | |||
37 | 36 | ||
38 | namespace Opie { | 37 | /* QT */ |
38 | #include <qarray.h> | ||
39 | |||
40 | namespace Opie | ||
41 | { | ||
39 | 42 | ||
@@ -49,5 +52,7 @@ template <class T> class ORecordList; | |||
49 | template <class T = OPimRecord> | 52 | template <class T = OPimRecord> |
50 | class ORecordListIterator { | 53 | class ORecordListIterator |
54 | { | ||
51 | friend class ORecordList<T>; | 55 | friend class ORecordList<T>; |
52 | public: | 56 | |
57 | public: | ||
53 | typedef OTemplateBase<T> Base; | 58 | typedef OTemplateBase<T> Base; |
@@ -67,3 +72,3 @@ public: | |||
67 | ORecordListIterator( const ORecordListIterator& ); | 72 | ORecordListIterator( const ORecordListIterator& ); |
68 | ORecordListIterator &operator=(const ORecordListIterator& ); | 73 | ORecordListIterator &operator=( const ORecordListIterator& ); |
69 | 74 | ||
@@ -83,3 +88,3 @@ public: | |||
83 | */ | 88 | */ |
84 | uint current()const; | 89 | uint current() const; |
85 | 90 | ||
@@ -88,3 +93,3 @@ public: | |||
88 | */ | 93 | */ |
89 | uint count()const; | 94 | uint count() const; |
90 | 95 | ||
@@ -95,3 +100,3 @@ public: | |||
95 | 100 | ||
96 | private: | 101 | private: |
97 | QArray<int> m_uids; | 102 | QArray<int> m_uids; |
@@ -101,3 +106,3 @@ private: | |||
101 | T m_record; | 106 | T m_record; |
102 | bool m_direction :1; | 107 | bool m_direction : 1; |
103 | 108 | ||
@@ -107,2 +112,3 @@ private: | |||
107 | 112 | ||
113 | |||
108 | class ORecordListPrivate; | 114 | class ORecordListPrivate; |
@@ -113,4 +119,5 @@ class ORecordListPrivate; | |||
113 | template <class T = OPimRecord > | 119 | template <class T = OPimRecord > |
114 | class ORecordList { | 120 | class ORecordList |
115 | public: | 121 | { |
122 | public: | ||
116 | typedef OTemplateBase<T> Base; | 123 | typedef OTemplateBase<T> Base; |
@@ -121,5 +128,5 @@ public: | |||
121 | */ | 128 | */ |
122 | ORecordList () { | 129 | ORecordList () |
123 | } | 130 | {} |
124 | ORecordList( const QArray<int>& ids, | 131 | ORecordList( const QArray<int>& ids, |
125 | const Base* ); | 132 | const Base* ); |
@@ -140,10 +147,10 @@ ORecordList( const QArray<int>& ids, | |||
140 | */ | 147 | */ |
141 | uint count()const; | 148 | uint count() const; |
142 | 149 | ||
143 | T operator[]( uint i ); | 150 | T operator[] ( uint i ); |
144 | int uidAt(uint i ); | 151 | int uidAt( uint i ); |
145 | 152 | ||
146 | /** | 153 | /** |
147 | * Remove the contact with given uid | 154 | * Remove the contact with given uid |
148 | */ | 155 | */ |
149 | bool remove( int uid ); | 156 | bool remove( int uid ); |
@@ -154,3 +161,3 @@ ORecordList( const QArray<int>& ids, | |||
154 | */ | 161 | */ |
155 | private: | 162 | private: |
156 | QArray<int> m_ids; | 163 | QArray<int> m_ids; |
@@ -160,5 +167,7 @@ private: | |||
160 | 167 | ||
168 | |||
161 | /* ok now implement it */ | 169 | /* ok now implement it */ |
162 | template <class T> | 170 | template <class T> |
163 | ORecordListIterator<T>::ORecordListIterator() { | 171 | ORecordListIterator<T>::ORecordListIterator() |
172 | { | ||
164 | m_current = 0; | 173 | m_current = 0; |
@@ -170,10 +179,15 @@ ORecordListIterator<T>::ORecordListIterator() { | |||
170 | } | 179 | } |
180 | |||
181 | |||
171 | template <class T> | 182 | template <class T> |
172 | ORecordListIterator<T>::~ORecordListIterator() { | 183 | ORecordListIterator<T>::~ORecordListIterator() |
173 | /* nothing to delete */ | 184 | { |
185 | /* nothing to delete */ | ||
174 | } | 186 | } |
175 | 187 | ||
188 | |||
176 | template <class T> | 189 | template <class T> |
177 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 190 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it ) |
178 | // qWarning("ORecordListIterator copy c'tor"); | 191 | { |
192 | // qWarning("ORecordListIterator copy c'tor"); | ||
179 | m_uids = it.m_uids; | 193 | m_uids = it.m_uids; |
@@ -186,4 +200,6 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | |||
186 | 200 | ||
201 | |||
187 | template <class T> | 202 | template <class T> |
188 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 203 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it ) |
204 | { | ||
189 | m_uids = it.m_uids; | 205 | m_uids = it.m_uids; |
@@ -197,9 +213,11 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIter | |||
197 | 213 | ||
214 | |||
198 | template <class T> | 215 | template <class T> |
199 | T ORecordListIterator<T>::operator*() { | 216 | T ORecordListIterator<T>::operator*() |
200 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 217 | { |
201 | if (!m_end ) | 218 | //qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
202 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 219 | if ( !m_end ) |
220 | m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, | ||
203 | m_direction ? Base::Forward : | 221 | m_direction ? Base::Forward : |
204 | Base::Reverse ); | 222 | Base::Reverse ); |
205 | else | 223 | else |
@@ -210,9 +228,13 @@ T ORecordListIterator<T>::operator*() { | |||
210 | 228 | ||
229 | |||
211 | template <class T> | 230 | template <class T> |
212 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 231 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() |
232 | { | ||
213 | m_direction = true; | 233 | m_direction = true; |
214 | if (m_current < m_uids.count() ) { | 234 | if ( m_current < m_uids.count() ) |
235 | { | ||
215 | m_end = false; | 236 | m_end = false; |
216 | ++m_current; | 237 | ++m_current; |
217 | }else | 238 | } |
239 | else | ||
218 | m_end = true; | 240 | m_end = true; |
@@ -221,9 +243,14 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | |||
221 | } | 243 | } |
244 | |||
245 | |||
222 | template <class T> | 246 | template <class T> |
223 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 247 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() |
248 | { | ||
224 | m_direction = false; | 249 | m_direction = false; |
225 | if ( m_current > 0 ) { | 250 | if ( m_current > 0 ) |
251 | { | ||
226 | --m_current; | 252 | --m_current; |
227 | m_end = false; | 253 | m_end = false; |
228 | } else | 254 | } |
255 | else | ||
229 | m_end = true; | 256 | m_end = true; |
@@ -233,4 +260,6 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | |||
233 | 260 | ||
261 | |||
234 | template <class T> | 262 | template <class T> |
235 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 263 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) |
264 | { | ||
236 | 265 | ||
@@ -245,25 +274,37 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | |||
245 | } | 274 | } |
275 | |||
276 | |||
246 | template <class T> | 277 | template <class T> |
247 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 278 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) |
248 | return !(*this == it ); | 279 | { |
280 | return !( *this == it ); | ||
249 | } | 281 | } |
282 | |||
283 | |||
250 | template <class T> | 284 | template <class T> |
251 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 285 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
252 | const Base* t ) | 286 | const Base* t ) |
253 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 287 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
254 | m_direction( false ) | 288 | m_direction( false ) |
255 | { | 289 | { |
256 | /* if the list is empty we're already at the end of the list */ | 290 | /* if the list is empty we're already at the end of the list */ |
257 | if (uids.count() == 0 ) | 291 | if ( uids.count() == 0 ) |
258 | m_end = true; | 292 | m_end = true; |
259 | } | 293 | } |
294 | |||
295 | |||
260 | template <class T> | 296 | template <class T> |
261 | uint ORecordListIterator<T>::current()const { | 297 | uint ORecordListIterator<T>::current() const |
298 | { | ||
262 | return m_current; | 299 | return m_current; |
263 | } | 300 | } |
301 | |||
302 | |||
264 | template <class T> | 303 | template <class T> |
265 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 304 | void ORecordListIterator<T>::setCurrent( uint cur ) |
266 | if( cur < m_uids.count() ) { | 305 | { |
267 | m_end = false; | 306 | if ( cur < m_uids.count() ) |
268 | m_current= cur; | 307 | { |
308 | m_end = false; | ||
309 | m_current = cur; | ||
269 | } | 310 | } |
@@ -271,5 +312,8 @@ void ORecordListIterator<T>::setCurrent( uint cur ) { | |||
271 | template <class T> | 312 | template <class T> |
272 | uint ORecordListIterator<T>::count()const { | 313 | uint ORecordListIterator<T>::count() const |
314 | { | ||
273 | return m_uids.count(); | 315 | return m_uids.count(); |
274 | } | 316 | } |
317 | |||
318 | |||
275 | template <class T> | 319 | template <class T> |
@@ -277,11 +321,16 @@ ORecordList<T>::ORecordList( const QArray<int>& ids, | |||
277 | const Base* acc ) | 321 | const Base* acc ) |
278 | : m_ids( ids ), m_acc( acc ) | 322 | : m_ids( ids ), m_acc( acc ) |
279 | { | 323 | {} |
280 | } | 324 | |
325 | |||
281 | template <class T> | 326 | template <class T> |
282 | ORecordList<T>::~ORecordList() { | 327 | ORecordList<T>::~ORecordList() |
283 | /* nothing to do here */ | 328 | { |
329 | /* nothing to do here */ | ||
284 | } | 330 | } |
331 | |||
332 | |||
285 | template <class T> | 333 | template <class T> |
286 | typename ORecordList<T>::Iterator ORecordList<T>::begin() { | 334 | typename ORecordList<T>::Iterator ORecordList<T>::begin() |
335 | { | ||
287 | Iterator it( m_ids, m_acc ); | 336 | Iterator it( m_ids, m_acc ); |
@@ -289,4 +338,7 @@ typename ORecordList<T>::Iterator ORecordList<T>::begin() { | |||
289 | } | 338 | } |
339 | |||
340 | |||
290 | template <class T> | 341 | template <class T> |
291 | typename ORecordList<T>::Iterator ORecordList<T>::end() { | 342 | typename ORecordList<T>::Iterator ORecordList<T>::end() |
343 | { | ||
292 | Iterator it( m_ids, m_acc ); | 344 | Iterator it( m_ids, m_acc ); |
@@ -297,8 +349,14 @@ typename ORecordList<T>::Iterator ORecordList<T>::end() { | |||
297 | } | 349 | } |
350 | |||
351 | |||
298 | template <class T> | 352 | template <class T> |
299 | uint ORecordList<T>::count()const { | 353 | uint ORecordList<T>::count() const |
300 | return m_ids.count(); | 354 | { |
355 | return m_ids.count(); | ||
301 | } | 356 | } |
357 | |||
358 | |||
302 | template <class T> | 359 | template <class T> |
303 | T ORecordList<T>::operator[]( uint i ) { | 360 | T ORecordList<T>::operator[] ( uint i ) |
361 | { | ||
304 | if ( i >= m_ids.count() ) | 362 | if ( i >= m_ids.count() ) |
@@ -306,28 +364,36 @@ T ORecordList<T>::operator[]( uint i ) { | |||
306 | /* forward */ | 364 | /* forward */ |
307 | return m_acc->find( m_ids[i], m_ids, i ); | 365 | return m_acc->find( m_ids[ i ], m_ids, i ); |
308 | } | ||
309 | template <class T> | ||
310 | int ORecordList<T>::uidAt( uint i ) { | ||
311 | return m_ids[i]; | ||
312 | } | 366 | } |
313 | 367 | ||
368 | |||
314 | template <class T> | 369 | template <class T> |
315 | bool ORecordList<T>::remove( int uid ) { | 370 | int ORecordList<T>::uidAt( uint i ) |
316 | QArray<int> copy( m_ids.count() ); | 371 | { |
317 | int counter = 0; | 372 | return m_ids[ i ]; |
318 | bool ret_val = false; | 373 | } |
319 | 374 | ||
320 | for (uint i = 0; i < m_ids.count(); i++){ | ||
321 | if ( m_ids[i] != uid ){ | ||
322 | copy[counter++] = m_ids[i]; | ||
323 | 375 | ||
324 | }else | 376 | template <class T> |
325 | ret_val = true; | 377 | bool ORecordList<T>::remove( int uid ) |
326 | } | 378 | { |
379 | QArray<int> copy( m_ids.count() ); | ||
380 | int counter = 0; | ||
381 | bool ret_val = false; | ||
382 | |||
383 | for ( uint i = 0; i < m_ids.count(); i++ ) | ||
384 | { | ||
385 | if ( m_ids[ i ] != uid ) | ||
386 | { | ||
387 | copy[ counter++ ] = m_ids[ i ]; | ||
388 | |||
389 | } | ||
390 | else | ||
391 | ret_val = true; | ||
392 | } | ||
327 | 393 | ||
328 | copy.resize( counter ); | 394 | copy.resize( counter ); |
329 | m_ids = copy; | 395 | m_ids = copy; |
330 | 396 | ||
331 | 397 | ||
332 | return ret_val; | 398 | return ret_val; |
333 | } | 399 | } |