summaryrefslogtreecommitdiff
path: root/libopie
authoreilers <eilers>2002-11-01 15:09:04 (UTC)
committer eilers <eilers>2002-11-01 15:09:04 (UTC)
commita098735b8749ead08c658792cc31f95e73045107 (patch) (unidiff)
tree28bd5ee97878ff3dfc7aa0e6b0c0dcd511acd3f7 /libopie
parent3fbba334274ca53bd26cd79ccd4662e529c61f40 (diff)
downloadopie-a098735b8749ead08c658792cc31f95e73045107.zip
opie-a098735b8749ead08c658792cc31f95e73045107.tar.gz
opie-a098735b8749ead08c658792cc31f95e73045107.tar.bz2
Added remove
Diffstat (limited to 'libopie') (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/orecordlist.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h
index e377447..2f4a5d3 100644
--- a/libopie/pim/orecordlist.h
+++ b/libopie/pim/orecordlist.h
@@ -97,33 +97,38 @@ public:
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();
@@ -146,33 +151,33 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) {
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;
@@ -256,17 +261,40 @@ ORecordList<T>::Iterator ORecordList<T>::end() {
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