summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/orecordlist.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/orecordlist.h230
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
@@ -28,13 +28,16 @@
28*/ 28*/
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>
36#include <opie2/opimrecord.h> 35#include <opie2/opimrecord.h>
37 36
38namespace Opie { 37/* QT */
38#include <qarray.h>
39
40namespace Opie
41{
39 42
40class ORecordListIteratorPrivate; 43class ORecordListIteratorPrivate;
@@ -48,7 +51,9 @@ class ORecordListIteratorPrivate;
48template <class T> class ORecordList; 51template <class T> class ORecordList;
49template <class T = OPimRecord> 52template <class T = OPimRecord>
50class ORecordListIterator { 53class ORecordListIterator
54{
51 friend class ORecordList<T>; 55 friend class ORecordList<T>;
52public: 56
57 public:
53 typedef OTemplateBase<T> Base; 58 typedef OTemplateBase<T> Base;
54 59
@@ -66,5 +71,5 @@ public:
66 71
67 ORecordListIterator( const ORecordListIterator& ); 72 ORecordListIterator( const ORecordListIterator& );
68 ORecordListIterator &operator=(const ORecordListIterator& ); 73 ORecordListIterator &operator=( const ORecordListIterator& );
69 74
70 /** 75 /**
@@ -82,10 +87,10 @@ public:
82 * the current item 87 * the current item
83 */ 88 */
84 uint current()const; 89 uint current() const;
85 90
86 /** 91 /**
87 * the number of items 92 * the number of items
88 */ 93 */
89 uint count()const; 94 uint count() const;
90 95
91 /** 96 /**
@@ -94,5 +99,5 @@ public:
94 void setCurrent( uint cur ); 99 void setCurrent( uint cur );
95 100
96private: 101 private:
97 QArray<int> m_uids; 102 QArray<int> m_uids;
98 uint m_current; 103 uint m_current;
@@ -100,5 +105,5 @@ private:
100 bool m_end : 1; 105 bool m_end : 1;
101 T m_record; 106 T m_record;
102 bool m_direction :1; 107 bool m_direction : 1;
103 108
104 /* d pointer for future versions */ 109 /* d pointer for future versions */
@@ -106,4 +111,5 @@ private:
106}; 111};
107 112
113
108class ORecordListPrivate; 114class ORecordListPrivate;
109/** 115/**
@@ -112,6 +118,7 @@ class ORecordListPrivate;
112 */ 118 */
113template <class T = OPimRecord > 119template <class T = OPimRecord >
114class ORecordList { 120class ORecordList
115public: 121{
122 public:
116 typedef OTemplateBase<T> Base; 123 typedef OTemplateBase<T> Base;
117 typedef ORecordListIterator<T> Iterator; 124 typedef ORecordListIterator<T> Iterator;
@@ -120,7 +127,7 @@ public:
120 * c'tor 127 * c'tor
121 */ 128 */
122 ORecordList () { 129 ORecordList ()
123 } 130 {}
124ORecordList( const QArray<int>& ids, 131 ORecordList( const QArray<int>& ids,
125 const Base* ); 132 const Base* );
126 ~ORecordList(); 133 ~ORecordList();
@@ -139,12 +146,12 @@ ORecordList( const QArray<int>& ids,
139 * the number of items in the list 146 * the number of items in the list
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 );
150 157
@@ -153,5 +160,5 @@ ORecordList( const QArray<int>& ids,
153 ConstIterator end()const; 160 ConstIterator end()const;
154 */ 161 */
155private: 162 private:
156 QArray<int> m_ids; 163 QArray<int> m_ids;
157 const Base* m_acc; 164 const Base* m_acc;
@@ -159,7 +166,9 @@ private:
159}; 166};
160 167
168
161/* ok now implement it */ 169/* ok now implement it */
162template <class T> 170template <class T>
163ORecordListIterator<T>::ORecordListIterator() { 171ORecordListIterator<T>::ORecordListIterator()
172{
164 m_current = 0; 173 m_current = 0;
165 m_temp = 0l; 174 m_temp = 0l;
@@ -169,12 +178,17 @@ ORecordListIterator<T>::ORecordListIterator() {
169 m_direction = TRUE; 178 m_direction = TRUE;
170} 179}
180
181
171template <class T> 182template <class T>
172ORecordListIterator<T>::~ORecordListIterator() { 183ORecordListIterator<T>::~ORecordListIterator()
173/* nothing to delete */ 184{
185 /* nothing to delete */
174} 186}
175 187
188
176template <class T> 189template <class T>
177ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 190ORecordListIterator<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;
180 m_current = it.m_current; 194 m_current = it.m_current;
@@ -185,6 +199,8 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
185} 199}
186 200
201
187template <class T> 202template <class T>
188ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 203ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it )
204{
189 m_uids = it.m_uids; 205 m_uids = it.m_uids;
190 m_current = it.m_current; 206 m_current = it.m_current;
@@ -196,11 +212,13 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIter
196} 212}
197 213
214
198template <class T> 215template <class T>
199T ORecordListIterator<T>::operator*() { 216T 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
206 m_record = T(); 224 m_record = T();
@@ -209,22 +227,31 @@ T ORecordListIterator<T>::operator*() {
209} 227}
210 228
229
211template <class T> 230template <class T>
212ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 231ORecordListIterator<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;
219 241
220 return *this; 242 return *this;
221} 243}
244
245
222template <class T> 246template <class T>
223ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 247ORecordListIterator<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;
230 257
@@ -232,6 +259,8 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
232} 259}
233 260
261
234template <class T> 262template <class T>
235bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 263bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it )
264{
236 265
237 /* if both are at we're the same.... */ 266 /* if both are at we're the same.... */
@@ -244,50 +273,73 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
244 return true; 273 return true;
245} 274}
275
276
246template <class T> 277template <class T>
247bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 278bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it )
248 return !(*this == it ); 279{
280 return !( *this == it );
249} 281}
282
283
250template <class T> 284template <class T>
251ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, 285ORecordListIterator<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
260template <class T> 296template <class T>
261uint ORecordListIterator<T>::current()const { 297uint ORecordListIterator<T>::current() const
298{
262 return m_current; 299 return m_current;
263} 300}
301
302
264template <class T> 303template <class T>
265void ORecordListIterator<T>::setCurrent( uint cur ) { 304void 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 }
270} 311}
271template <class T> 312template <class T>
272uint ORecordListIterator<T>::count()const { 313uint ORecordListIterator<T>::count() const
314{
273 return m_uids.count(); 315 return m_uids.count();
274} 316}
317
318
275template <class T> 319template <class T>
276ORecordList<T>::ORecordList( const QArray<int>& ids, 320ORecordList<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
281template <class T> 326template <class T>
282ORecordList<T>::~ORecordList() { 327ORecordList<T>::~ORecordList()
283/* nothing to do here */ 328{
329 /* nothing to do here */
284} 330}
331
332
285template <class T> 333template <class T>
286typename ORecordList<T>::Iterator ORecordList<T>::begin() { 334typename ORecordList<T>::Iterator ORecordList<T>::begin()
335{
287 Iterator it( m_ids, m_acc ); 336 Iterator it( m_ids, m_acc );
288 return it; 337 return it;
289} 338}
339
340
290template <class T> 341template <class T>
291typename ORecordList<T>::Iterator ORecordList<T>::end() { 342typename ORecordList<T>::Iterator ORecordList<T>::end()
343{
292 Iterator it( m_ids, m_acc ); 344 Iterator it( m_ids, m_acc );
293 it.m_end = true; 345 it.m_end = true;
@@ -296,39 +348,53 @@ typename ORecordList<T>::Iterator ORecordList<T>::end() {
296 return it; 348 return it;
297} 349}
350
351
298template <class T> 352template <class T>
299uint ORecordList<T>::count()const { 353uint ORecordList<T>::count() const
300return m_ids.count(); 354{
355 return m_ids.count();
301} 356}
357
358
302template <class T> 359template <class T>
303T ORecordList<T>::operator[]( uint i ) { 360T ORecordList<T>::operator[] ( uint i )
361{
304 if ( i >= m_ids.count() ) 362 if ( i >= m_ids.count() )
305 return T(); 363 return T();
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}
309template <class T>
310int ORecordList<T>::uidAt( uint i ) {
311 return m_ids[i];
312} 366}
313 367
368
314template <class T> 369template <class T>
315bool ORecordList<T>::remove( int uid ) { 370int 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 376template <class T>
325 ret_val = true; 377bool 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}
334 400