summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/orecordlist.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index e377447..2f4a5d3 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -44,167 +44,172 @@ public:
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
65private: 65private:
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 */
81template <class T = OPimRecord > 81template <class T = OPimRecord >
82class ORecordList { 82class ORecordList {
83public: 83public:
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, 92ORecordList( 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 // FIXME implemenent remove 113
114 /**
115 * Remove the contact with given uid
116 */
117 bool remove( int uid );
118
114 /* 119 /*
115 ConstIterator begin()const; 120 ConstIterator begin()const;
116 ConstIterator end()const; 121 ConstIterator end()const;
117 */ 122 */
118private: 123private:
119 QArray<int> m_ids; 124 QArray<int> m_ids;
120 const Base* m_acc; 125 const Base* m_acc;
121}; 126};
122 127
123/* ok now implement it */ 128/* ok now implement it */
124template <class T> 129template <class T>
125ORecordListIterator<T>::ORecordListIterator() { 130ORecordListIterator<T>::ORecordListIterator() {
126 m_current = 0; 131 m_current = 0;
127 m_temp = 0l; 132 m_temp = 0l;
128 m_end = true; 133 m_end = true;
129 m_record = T(); 134 m_record = T();
130 /* forward */ 135 /* forward */
131 m_direction = TRUE; 136 m_direction = TRUE;
132} 137}
133template <class T> 138template <class T>
134ORecordListIterator<T>::~ORecordListIterator() { 139ORecordListIterator<T>::~ORecordListIterator() {
135/* nothing to delete */ 140/* nothing to delete */
136} 141}
137 142
138template <class T> 143template <class T>
139ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { 144ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
140// qWarning("ORecordListIterator copy c'tor"); 145// qWarning("ORecordListIterator copy c'tor");
141 m_uids = it.m_uids; 146 m_uids = it.m_uids;
142 m_current = it.m_current; 147 m_current = it.m_current;
143 m_temp = it.m_temp; 148 m_temp = it.m_temp;
144 m_end = it.m_end; 149 m_end = it.m_end;
145 m_record = it.m_record; 150 m_record = it.m_record;
146 m_direction = it.m_direction; 151 m_direction = it.m_direction;
147} 152}
148 153
149template <class T> 154template <class T>
150ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { 155ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) {
151 m_uids = it.m_uids; 156 m_uids = it.m_uids;
152 m_current = it.m_current; 157 m_current = it.m_current;
153 m_temp = it.m_temp; 158 m_temp = it.m_temp;
154 m_end = it.m_end; 159 m_end = it.m_end;
155 m_record = it.m_record; 160 m_record = it.m_record;
156 161
157 return *this; 162 return *this;
158} 163}
159 164
160template <class T> 165template <class T>
161T ORecordListIterator<T>::operator*() { 166T ORecordListIterator<T>::operator*() {
162 qWarning("operator* %d %d", m_current, m_uids[m_current] ); 167 //qWarning("operator* %d %d", m_current, m_uids[m_current] );
163 if (!m_end ) 168 if (!m_end )
164 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,
165 m_direction ? Base::Forward : 170 m_direction ? Base::Forward :
166 Base::Reverse ); 171 Base::Reverse );
167 else 172 else
168 m_record = T(); 173 m_record = T();
169 174
170 return m_record; 175 return m_record;
171} 176}
172 177
173template <class T> 178template <class T>
174ORecordListIterator<T> &ORecordListIterator<T>::operator++() { 179ORecordListIterator<T> &ORecordListIterator<T>::operator++() {
175 m_direction = true; 180 m_direction = true;
176 if (m_current < m_uids.count() ) { 181 if (m_current < m_uids.count() ) {
177 m_end = false; 182 m_end = false;
178 ++m_current; 183 ++m_current;
179 }else 184 }else
180 m_end = true; 185 m_end = true;
181 186
182 return *this; 187 return *this;
183} 188}
184template <class T> 189template <class T>
185ORecordListIterator<T> &ORecordListIterator<T>::operator--() { 190ORecordListIterator<T> &ORecordListIterator<T>::operator--() {
186 m_direction = false; 191 m_direction = false;
187 if ( m_current > 0 ) { 192 if ( m_current > 0 ) {
188 --m_current; 193 --m_current;
189 m_end = false; 194 m_end = false;
190 } else 195 } else
191 m_end = true; 196 m_end = true;
192 197
193 return *this; 198 return *this;
194} 199}
195 200
196template <class T> 201template <class T>
197bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { 202bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) {
198 203
199 /* if both are at we're the same.... */ 204 /* if both are at we're the same.... */
200 if ( m_end == it.m_end ) return true; 205 if ( m_end == it.m_end ) return true;
201 206
202 if ( m_uids != it.m_uids ) return false; 207 if ( m_uids != it.m_uids ) return false;
203 if ( m_current != it.m_current ) return false; 208 if ( m_current != it.m_current ) return false;
204 if ( m_temp != it.m_temp ) return false; 209 if ( m_temp != it.m_temp ) return false;
205 210
206 return true; 211 return true;
207} 212}
208template <class T> 213template <class T>
209bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { 214bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
210 return !(*this == it ); 215 return !(*this == it );
@@ -224,49 +229,72 @@ template <class T>
224void ORecordListIterator<T>::setCurrent( uint cur ) { 229void ORecordListIterator<T>::setCurrent( uint cur ) {
225 if( cur < m_uids.count() ) { 230 if( cur < m_uids.count() ) {
226 m_end = false; 231 m_end = false;
227 m_current= cur; 232 m_current= cur;
228 } 233 }
229} 234}
230template <class T> 235template <class T>
231uint ORecordListIterator<T>::count()const { 236uint ORecordListIterator<T>::count()const {
232 return m_uids.count(); 237 return m_uids.count();
233} 238}
234template <class T> 239template <class T>
235ORecordList<T>::ORecordList( const QArray<int>& ids, 240ORecordList<T>::ORecordList( const QArray<int>& ids,
236 const Base* acc ) 241 const Base* acc )
237 : m_ids( ids ), m_acc( acc ) 242 : m_ids( ids ), m_acc( acc )
238{ 243{
239} 244}
240template <class T> 245template <class T>
241ORecordList<T>::~ORecordList() { 246ORecordList<T>::~ORecordList() {
242/* nothing to do here */ 247/* nothing to do here */
243} 248}
244template <class T> 249template <class T>
245ORecordList<T>::Iterator ORecordList<T>::begin() { 250ORecordList<T>::Iterator ORecordList<T>::begin() {
246 Iterator it( m_ids, m_acc ); 251 Iterator it( m_ids, m_acc );
247 return it; 252 return it;
248} 253}
249template <class T> 254template <class T>
250ORecordList<T>::Iterator ORecordList<T>::end() { 255ORecordList<T>::Iterator ORecordList<T>::end() {
251 Iterator it( m_ids, m_acc ); 256 Iterator it( m_ids, m_acc );
252 it.m_end = true; 257 it.m_end = true;
253 it.m_current = m_ids.count(); 258 it.m_current = m_ids.count();
254 259
255 return it; 260 return it;
256} 261}
257template <class T> 262template <class T>
258uint ORecordList<T>::count()const { 263uint ORecordList<T>::count()const {
259return m_ids.count(); 264return m_ids.count();
260} 265}
261template <class T> 266template <class T>
262T ORecordList<T>::operator[]( uint i ) { 267T ORecordList<T>::operator[]( uint i ) {
263 if ( i < 0 || (i+1) > m_ids.count() ) 268 if ( i < 0 || (i+1) > m_ids.count() )
264 return T(); 269 return T();
265 /* forward */ 270 /* forward */
266 return m_acc->find( m_ids[i], m_ids, i ); 271 return m_acc->find( m_ids[i], m_ids, i );
267} 272}
268template <class T> 273template <class T>
269int ORecordList<T>::uidAt( uint i ) { 274int ORecordList<T>::uidAt( uint i ) {
270 return m_ids[i]; 275 return m_ids[i];
271} 276}
277
278template <class T>
279bool ORecordList<T>::remove( int uid ) {
280 QArray<int> copy( m_ids.count() );
281 int counter = 0;
282 bool ret_val = false;
283
284 for (uint i = 0; i < m_ids.count(); i++){
285 if ( m_ids[i] != uid ){
286 copy[counter++] = m_ids[i];
287
288 }else
289 ret_val = true;
290 }
291
292 copy.resize( counter );
293 m_ids = copy;
294
295
296 return ret_val;
297}
298
299
272#endif 300#endif