Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 3b30a73..75bb33c 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,201 +1,208 @@ | |||
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 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | ||
17 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
18 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | ||
19 | public: | 21 | public: |
20 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
21 | 23 | ||
22 | /** | 24 | /** |
23 | * The c'tor used internally from | 25 | * The c'tor used internally from |
24 | * ORecordList | 26 | * ORecordList |
25 | */ | 27 | */ |
26 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
27 | 29 | ||
28 | /** | 30 | /** |
29 | * The standard c'tor | 31 | * The standard c'tor |
30 | */ | 32 | */ |
31 | ORecordListIterator(); | 33 | ORecordListIterator(); |
32 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
33 | 35 | ||
34 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
35 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
36 | 38 | ||
37 | /** | 39 | /** |
38 | * a * operator ;) | 40 | * a * operator ;) |
39 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
40 | */ | 42 | */ |
41 | T &operator*(); | 43 | T &operator*(); |
42 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
43 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
44 | 46 | ||
45 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
46 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
47 | 49 | ||
48 | private: | 50 | private: |
49 | QArray<int> m_uids; | 51 | QArray<int> m_uids; |
50 | int m_current; | 52 | int m_current; |
51 | const Base* m_temp; | 53 | const Base* m_temp; |
52 | bool m_end : 1; | 54 | bool m_end : 1; |
53 | T m_record; | 55 | T m_record; |
54 | 56 | ||
55 | /* d pointer for future versions */ | 57 | /* d pointer for future versions */ |
56 | class IteratorPrivate; | 58 | class IteratorPrivate; |
57 | IteratorPrivate *d; | 59 | IteratorPrivate *d; |
58 | }; | 60 | }; |
59 | /** | 61 | /** |
60 | * The recordlist used as a return type | 62 | * The recordlist used as a return type |
61 | * from OPimAccessTemplate | 63 | * from OPimAccessTemplate |
62 | */ | 64 | */ |
63 | template <class T = OPimRecord > | 65 | template <class T = OPimRecord > |
64 | class ORecordList { | 66 | class ORecordList { |
65 | public: | 67 | public: |
66 | typedef OTemplateBase<T> Base; | 68 | typedef OTemplateBase<T> Base; |
67 | typedef ORecordListIterator<T> Iterator; | 69 | typedef ORecordListIterator<T> Iterator; |
68 | 70 | ||
69 | /** | 71 | /** |
70 | * c'tor | 72 | * c'tor |
71 | */ | 73 | */ |
72 | ORecordList( const QArray<int>& ids, | 74 | ORecordList( const QArray<int>& ids, |
73 | const Base* ); | 75 | const Base* ); |
74 | ~ORecordList(); | 76 | ~ORecordList(); |
75 | 77 | ||
76 | /** | 78 | /** |
77 | * the first iterator | 79 | * the first iterator |
78 | */ | 80 | */ |
79 | Iterator begin(); | 81 | Iterator begin(); |
80 | 82 | ||
81 | /** | 83 | /** |
82 | * the end | 84 | * the end |
83 | */ | 85 | */ |
84 | Iterator end(); | 86 | Iterator end(); |
85 | /* | 87 | /* |
86 | ConstIterator begin()const; | 88 | ConstIterator begin()const; |
87 | ConstIterator end()const; | 89 | ConstIterator end()const; |
88 | */ | 90 | */ |
89 | private: | 91 | private: |
90 | QArray<int> m_ids; | 92 | QArray<int> m_ids; |
91 | const Base* m_acc; | 93 | const Base* m_acc; |
92 | }; | 94 | }; |
93 | 95 | ||
94 | /* ok now implement it */ | 96 | /* ok now implement it */ |
95 | template <class T> | 97 | template <class T> |
96 | ORecordListIterator<T>::ORecordListIterator() { | 98 | ORecordListIterator<T>::ORecordListIterator() { |
97 | m_current = 0; | 99 | m_current = 0; |
98 | m_temp = 0l; | 100 | m_temp = 0l; |
99 | m_end = true; | 101 | m_end = true; |
100 | } | 102 | } |
101 | template <class T> | 103 | template <class T> |
102 | ORecordListIterator<T>::~ORecordListIterator() { | 104 | ORecordListIterator<T>::~ORecordListIterator() { |
103 | /* nothing to delete */ | 105 | /* nothing to delete */ |
104 | } | 106 | } |
105 | 107 | ||
106 | template <class T> | 108 | template <class T> |
107 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 109 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
110 | qWarning("ORecordListIterator"); | ||
108 | m_uids = it.m_uids; | 111 | m_uids = it.m_uids; |
109 | m_current = it.m_current; | 112 | m_current = it.m_current; |
110 | m_temp = it.m_temp; | 113 | m_temp = it.m_temp; |
111 | m_end = it.m_end; | 114 | m_end = it.m_end; |
112 | m_record = it.m_record; | 115 | m_record = it.m_record; |
113 | } | 116 | } |
114 | 117 | ||
115 | template <class T> | 118 | template <class T> |
116 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 119 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
117 | m_uids = it.m_uids; | 120 | m_uids = it.m_uids; |
118 | m_current = it.m_current; | 121 | m_current = it.m_current; |
119 | m_temp = it.m_temp; | 122 | m_temp = it.m_temp; |
120 | m_end = it.m_end; | 123 | m_end = it.m_end; |
121 | m_record = it.m_record; | 124 | m_record = it.m_record; |
122 | 125 | ||
123 | return *this; | 126 | return *this; |
124 | } | 127 | } |
125 | 128 | ||
126 | template <class T> | 129 | template <class T> |
127 | T &ORecordListIterator<T>::operator*() { | 130 | T &ORecordListIterator<T>::operator*() { |
131 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); | ||
128 | if (!m_end ) | 132 | if (!m_end ) |
129 | m_record = m_temp->find( m_uids[m_current] ); | 133 | m_record = m_temp->find( m_uids[m_current] ); |
130 | else | 134 | else |
131 | m_record = T(); | 135 | m_record = T(); |
132 | 136 | ||
133 | return m_record; | 137 | return m_record; |
134 | } | 138 | } |
135 | 139 | ||
136 | template <class T> | 140 | template <class T> |
137 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 141 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
138 | if (m_current < m_uids.count() ) { | 142 | if (m_current < (int)m_uids.count() ) { |
139 | m_end = false; | 143 | m_end = false; |
140 | ++m_current; | 144 | ++m_current; |
141 | }else | 145 | }else |
142 | m_end = true; | 146 | m_end = true; |
143 | 147 | ||
144 | return *this; | 148 | return *this; |
145 | } | 149 | } |
146 | template <class T> | 150 | template <class T> |
147 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 151 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
148 | if ( m_current > 0 ) { | 152 | if ( m_current > 0 ) { |
149 | --m_current; | 153 | --m_current; |
150 | m_end = false; | 154 | m_end = false; |
151 | } else | 155 | } else |
152 | m_end = true; | 156 | m_end = true; |
153 | 157 | ||
154 | return *this; | 158 | return *this; |
155 | } | 159 | } |
156 | 160 | ||
157 | template <class T> | 161 | template <class T> |
158 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 162 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
159 | 163 | ||
160 | /* if both are at we're the same.... */ | 164 | /* if both are at we're the same.... */ |
161 | if ( m_end == it.m_end ) return true; | 165 | if ( m_end == it.m_end ) return true; |
162 | 166 | ||
163 | if ( m_uids != it.m_uids ) return false; | 167 | if ( m_uids != it.m_uids ) return false; |
164 | if ( m_current != it.m_current ) return false; | 168 | if ( m_current != it.m_current ) return false; |
165 | if ( m_temp != it.m_temp ) return false; | 169 | if ( m_temp != it.m_temp ) return false; |
166 | 170 | ||
167 | return true; | 171 | return true; |
168 | } | 172 | } |
169 | template <class T> | 173 | template <class T> |
170 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 174 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
171 | return !(*this == it ); | 175 | return !(*this == it ); |
172 | } | 176 | } |
173 | template <class T> | 177 | template <class T> |
174 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 178 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
175 | const Base* t ) | 179 | const Base* t ) |
176 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) | 180 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) |
177 | { | 181 | { |
178 | } | 182 | } |
179 | 183 | ||
180 | template <class T> | 184 | template <class T> |
181 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 185 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
182 | const Base* acc ) | 186 | const Base* acc ) |
183 | : m_ids( ids ), m_acc( acc ) | 187 | : m_ids( ids ), m_acc( acc ) |
184 | { | 188 | { |
185 | } | 189 | } |
186 | template <class T> | 190 | template <class T> |
187 | ORecordList<T>::~ORecordList() { | 191 | ORecordList<T>::~ORecordList() { |
188 | /* nothing to do here */ | 192 | /* nothing to do here */ |
189 | } | 193 | } |
190 | template <class T> | 194 | template <class T> |
191 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 195 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
196 | qWarning("ORecordList::begin"); | ||
192 | Iterator it( m_ids, m_acc ); | 197 | Iterator it( m_ids, m_acc ); |
193 | return it; | 198 | return it; |
194 | } | 199 | } |
195 | template <class T> | 200 | template <class T> |
196 | ORecordList<T>::Iterator ORecordList<T>::end() { | 201 | ORecordList<T>::Iterator ORecordList<T>::end() { |
197 | Iterator it( m_ids, m_acc ); | 202 | Iterator it( m_ids, m_acc ); |
198 | it.m_end = true; | 203 | it.m_end = true; |
199 | it.m_current = m_ids.count(); | 204 | it.m_current = m_ids.count(); |
205 | |||
206 | return it; | ||
200 | } | 207 | } |
201 | #endif | 208 | #endif |