Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index edcd729..5211f57 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,33 +1,34 @@ | |||
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 | class ORecordListIteratorPrivate; | ||
10 | /** | 11 | /** |
11 | * Our List Iterator | 12 | * Our List Iterator |
12 | * it behaves like STL or Qt | 13 | * it behaves like STL or Qt |
13 | * | 14 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 15 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 16 | * doSomeCoolStuff( (*it) ); |
16 | */ | 17 | */ |
17 | template <class T> class ORecordList; | 18 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 19 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 20 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 21 | friend class ORecordList<T>; |
21 | public: | 22 | public: |
22 | typedef OTemplateBase<T> Base; | 23 | typedef OTemplateBase<T> Base; |
23 | 24 | ||
24 | /** | 25 | /** |
25 | * The c'tor used internally from | 26 | * The c'tor used internally from |
26 | * ORecordList | 27 | * ORecordList |
27 | */ | 28 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 29 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 30 | ||
30 | /** | 31 | /** |
31 | * The standard c'tor | 32 | * The standard c'tor |
32 | */ | 33 | */ |
33 | ORecordListIterator(); | 34 | ORecordListIterator(); |
@@ -50,100 +51,102 @@ public: | |||
50 | /** | 51 | /** |
51 | * the current item | 52 | * the current item |
52 | */ | 53 | */ |
53 | uint current()const; | 54 | uint current()const; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * the number of items | 57 | * the number of items |
57 | */ | 58 | */ |
58 | uint count()const; | 59 | uint count()const; |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * sets the current item | 62 | * sets the current item |
62 | */ | 63 | */ |
63 | void setCurrent( uint cur ); | 64 | void setCurrent( uint cur ); |
64 | 65 | ||
65 | private: | 66 | private: |
66 | QArray<int> m_uids; | 67 | QArray<int> m_uids; |
67 | uint m_current; | 68 | uint m_current; |
68 | const Base* m_temp; | 69 | const Base* m_temp; |
69 | bool m_end : 1; | 70 | bool m_end : 1; |
70 | T m_record; | 71 | T m_record; |
71 | bool m_direction :1; | 72 | bool m_direction :1; |
72 | 73 | ||
73 | /* d pointer for future versions */ | 74 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 75 | ORecordListIteratorPrivate *d; |
75 | IteratorPrivate *d; | ||
76 | }; | 76 | }; |
77 | |||
78 | class ORecordListPrivate; | ||
77 | /** | 79 | /** |
78 | * The recordlist used as a return type | 80 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 81 | * from OPimAccessTemplate |
80 | */ | 82 | */ |
81 | template <class T = OPimRecord > | 83 | template <class T = OPimRecord > |
82 | class ORecordList { | 84 | class ORecordList { |
83 | public: | 85 | public: |
84 | typedef OTemplateBase<T> Base; | 86 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 87 | typedef ORecordListIterator<T> Iterator; |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * c'tor | 90 | * c'tor |
89 | */ | 91 | */ |
90 | ORecordList () { | 92 | ORecordList () { |
91 | } | 93 | } |
92 | ORecordList( const QArray<int>& ids, | 94 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 95 | const Base* ); |
94 | ~ORecordList(); | 96 | ~ORecordList(); |
95 | 97 | ||
96 | /** | 98 | /** |
97 | * the first iterator | 99 | * the first iterator |
98 | */ | 100 | */ |
99 | Iterator begin(); | 101 | Iterator begin(); |
100 | 102 | ||
101 | /** | 103 | /** |
102 | * the end | 104 | * the end |
103 | */ | 105 | */ |
104 | Iterator end(); | 106 | Iterator end(); |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * the number of items in the list | 109 | * the number of items in the list |
108 | */ | 110 | */ |
109 | uint count()const; | 111 | uint count()const; |
110 | 112 | ||
111 | T operator[]( uint i ); | 113 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | 114 | int uidAt(uint i ); |
113 | 115 | ||
114 | /** | 116 | /** |
115 | * Remove the contact with given uid | 117 | * Remove the contact with given uid |
116 | */ | 118 | */ |
117 | bool remove( int uid ); | 119 | bool remove( int uid ); |
118 | 120 | ||
119 | /* | 121 | /* |
120 | ConstIterator begin()const; | 122 | ConstIterator begin()const; |
121 | ConstIterator end()const; | 123 | ConstIterator end()const; |
122 | */ | 124 | */ |
123 | private: | 125 | private: |
124 | QArray<int> m_ids; | 126 | QArray<int> m_ids; |
125 | const Base* m_acc; | 127 | const Base* m_acc; |
128 | ORecordListPrivate *d; | ||
126 | }; | 129 | }; |
127 | 130 | ||
128 | /* ok now implement it */ | 131 | /* ok now implement it */ |
129 | template <class T> | 132 | template <class T> |
130 | ORecordListIterator<T>::ORecordListIterator() { | 133 | ORecordListIterator<T>::ORecordListIterator() { |
131 | m_current = 0; | 134 | m_current = 0; |
132 | m_temp = 0l; | 135 | m_temp = 0l; |
133 | m_end = true; | 136 | m_end = true; |
134 | m_record = T(); | 137 | m_record = T(); |
135 | /* forward */ | 138 | /* forward */ |
136 | m_direction = TRUE; | 139 | m_direction = TRUE; |
137 | } | 140 | } |
138 | template <class T> | 141 | template <class T> |
139 | ORecordListIterator<T>::~ORecordListIterator() { | 142 | ORecordListIterator<T>::~ORecordListIterator() { |
140 | /* nothing to delete */ | 143 | /* nothing to delete */ |
141 | } | 144 | } |
142 | 145 | ||
143 | template <class T> | 146 | template <class T> |
144 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 147 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
145 | // qWarning("ORecordListIterator copy c'tor"); | 148 | // qWarning("ORecordListIterator copy c'tor"); |
146 | m_uids = it.m_uids; | 149 | m_uids = it.m_uids; |
147 | m_current = it.m_current; | 150 | m_current = it.m_current; |
148 | m_temp = it.m_temp; | 151 | m_temp = it.m_temp; |
149 | m_end = it.m_end; | 152 | m_end = it.m_end; |
@@ -199,48 +202,51 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | |||
199 | } | 202 | } |
200 | 203 | ||
201 | template <class T> | 204 | template <class T> |
202 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 205 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
203 | 206 | ||
204 | /* if both are at we're the same.... */ | 207 | /* if both are at we're the same.... */ |
205 | if ( m_end == it.m_end ) return true; | 208 | if ( m_end == it.m_end ) return true; |
206 | 209 | ||
207 | if ( m_uids != it.m_uids ) return false; | 210 | if ( m_uids != it.m_uids ) return false; |
208 | if ( m_current != it.m_current ) return false; | 211 | if ( m_current != it.m_current ) return false; |
209 | if ( m_temp != it.m_temp ) return false; | 212 | if ( m_temp != it.m_temp ) return false; |
210 | 213 | ||
211 | return true; | 214 | return true; |
212 | } | 215 | } |
213 | template <class T> | 216 | template <class T> |
214 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 217 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
215 | return !(*this == it ); | 218 | return !(*this == it ); |
216 | } | 219 | } |
217 | template <class T> | 220 | template <class T> |
218 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 221 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
219 | const Base* t ) | 222 | const Base* t ) |
220 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 223 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
221 | m_direction( false ) | 224 | m_direction( false ) |
222 | { | 225 | { |
226 | /* if the list is empty we're already at the end of the list */ | ||
227 | if (uids.count() == 0 ) | ||
228 | m_end = true; | ||
223 | } | 229 | } |
224 | template <class T> | 230 | template <class T> |
225 | uint ORecordListIterator<T>::current()const { | 231 | uint ORecordListIterator<T>::current()const { |
226 | return m_current; | 232 | return m_current; |
227 | } | 233 | } |
228 | template <class T> | 234 | template <class T> |
229 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 235 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
230 | if( cur < m_uids.count() ) { | 236 | if( cur < m_uids.count() ) { |
231 | m_end = false; | 237 | m_end = false; |
232 | m_current= cur; | 238 | m_current= cur; |
233 | } | 239 | } |
234 | } | 240 | } |
235 | template <class T> | 241 | template <class T> |
236 | uint ORecordListIterator<T>::count()const { | 242 | uint ORecordListIterator<T>::count()const { |
237 | return m_uids.count(); | 243 | return m_uids.count(); |
238 | } | 244 | } |
239 | template <class T> | 245 | template <class T> |
240 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 246 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
241 | const Base* acc ) | 247 | const Base* acc ) |
242 | : m_ids( ids ), m_acc( acc ) | 248 | : m_ids( ids ), m_acc( acc ) |
243 | { | 249 | { |
244 | } | 250 | } |
245 | template <class T> | 251 | template <class T> |
246 | ORecordList<T>::~ORecordList() { | 252 | ORecordList<T>::~ORecordList() { |