Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index e438980..55d600a 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,64 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Holger Freyther <zecke@handhelds.org> | 3 | Copyright (C) Holger Freyther <zecke@handhelds.org> |
4 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | 4 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> |
5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 30 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
31 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 31 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
32 | 32 | ||
33 | #include <qarray.h> | 33 | /* OPIE */ |
34 | |||
35 | #include <opie2/opimrecord.h> | 34 | #include <opie2/opimrecord.h> |
36 | #include <opie2/opimaccessbackend.h> | 35 | #include <opie2/opimaccessbackend.h> |
37 | #include <opie2/opimrecordlist.h> | 36 | #include <opie2/opimrecordlist.h> |
38 | 37 | ||
39 | #include <opie2/opimcache.h> | 38 | #include <opie2/opimcache.h> |
40 | #include <opie2/opimtemplatebase.h> | 39 | #include <opie2/opimtemplatebase.h> |
40 | #include <opie2/odebug.h> | ||
41 | |||
42 | /* QT */ | ||
43 | #include <qarray.h> | ||
41 | 44 | ||
42 | namespace Opie { | 45 | namespace Opie { |
43 | 46 | ||
44 | class OPimAccessTemplatePrivate; | 47 | class OPimAccessTemplatePrivate; |
45 | /** | 48 | /** |
46 | * Thats the frontend to our OPIE PIM | 49 | * Thats the frontend to our OPIE PIM |
47 | * Library. Either you want to use it's | 50 | * Library. Either you want to use it's |
48 | * interface or you want to implement | 51 | * interface or you want to implement |
49 | * your own Access lib | 52 | * your own Access lib |
50 | * Just create a OPimRecord and inherit from | 53 | * Just create a OPimRecord and inherit from |
51 | * the templates | 54 | * the templates |
52 | */ | 55 | */ |
53 | 56 | ||
54 | template <class T = OPimRecord > | 57 | template <class T = OPimRecord > |
55 | class OPimAccessTemplate : public OTemplateBase<T> { | 58 | class OPimAccessTemplate : public OTemplateBase<T> { |
56 | public: | 59 | public: |
57 | enum Access { | 60 | enum Access { |
58 | Random = 0, | 61 | Random = 0, |
59 | SortedAccess | 62 | SortedAccess |
60 | }; | 63 | }; |
61 | typedef OPimRecordList<T> List; | 64 | typedef OPimRecordList<T> List; |
62 | typedef OPimAccessBackend<T> BackEnd; | 65 | typedef OPimAccessBackend<T> BackEnd; |
63 | typedef OPimCache<T> Cache; | 66 | typedef OPimCache<T> Cache; |
64 | 67 | ||
@@ -184,104 +187,104 @@ protected: | |||
184 | void invalidateCache(); | 187 | void invalidateCache(); |
185 | 188 | ||
186 | void setBackEnd( BackEnd* end ); | 189 | void setBackEnd( BackEnd* end ); |
187 | /** | 190 | /** |
188 | * returns the backend | 191 | * returns the backend |
189 | */ | 192 | */ |
190 | BackEnd* backEnd(); | 193 | BackEnd* backEnd(); |
191 | BackEnd* m_backEnd; | 194 | BackEnd* m_backEnd; |
192 | Cache m_cache; | 195 | Cache m_cache; |
193 | 196 | ||
194 | private: | 197 | private: |
195 | OPimAccessTemplatePrivate *d; | 198 | OPimAccessTemplatePrivate *d; |
196 | 199 | ||
197 | }; | 200 | }; |
198 | 201 | ||
199 | template <class T> | 202 | template <class T> |
200 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 203 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
201 | : OTemplateBase<T>(), m_backEnd( end ) | 204 | : OTemplateBase<T>(), m_backEnd( end ) |
202 | { | 205 | { |
203 | if (end ) | 206 | if (end ) |
204 | end->setFrontend( this ); | 207 | end->setFrontend( this ); |
205 | } | 208 | } |
206 | template <class T> | 209 | template <class T> |
207 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 210 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
208 | qWarning("~OPimAccessTemplate<T>"); | 211 | owarn << "~OPimAccessTemplate<T>" << oendl; |
209 | delete m_backEnd; | 212 | delete m_backEnd; |
210 | } | 213 | } |
211 | template <class T> | 214 | template <class T> |
212 | bool OPimAccessTemplate<T>::load() { | 215 | bool OPimAccessTemplate<T>::load() { |
213 | invalidateCache(); | 216 | invalidateCache(); |
214 | return m_backEnd->load(); | 217 | return m_backEnd->load(); |
215 | } | 218 | } |
216 | template <class T> | 219 | template <class T> |
217 | bool OPimAccessTemplate<T>::reload() { | 220 | bool OPimAccessTemplate<T>::reload() { |
218 | invalidateCache(); // zecke: I think this should be added (se) | 221 | invalidateCache(); // zecke: I think this should be added (se) |
219 | return m_backEnd->reload(); | 222 | return m_backEnd->reload(); |
220 | } | 223 | } |
221 | template <class T> | 224 | template <class T> |
222 | bool OPimAccessTemplate<T>::save() { | 225 | bool OPimAccessTemplate<T>::save() { |
223 | return m_backEnd->save(); | 226 | return m_backEnd->save(); |
224 | } | 227 | } |
225 | template <class T> | 228 | template <class T> |
226 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 229 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
227 | QArray<int> ints = m_backEnd->allRecords(); | 230 | QArray<int> ints = m_backEnd->allRecords(); |
228 | List lis(ints, this ); | 231 | List lis(ints, this ); |
229 | return lis; | 232 | return lis; |
230 | } | 233 | } |
231 | template <class T> | 234 | template <class T> |
232 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 235 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
233 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 236 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
234 | List lis(ints, this ); | 237 | List lis(ints, this ); |
235 | return lis; | 238 | return lis; |
236 | } | 239 | } |
237 | template <class T> | 240 | template <class T> |
238 | QArray<int> OPimAccessTemplate<T>::records()const { | 241 | QArray<int> OPimAccessTemplate<T>::records()const { |
239 | return m_backEnd->allRecords(); | 242 | return m_backEnd->allRecords(); |
240 | } | 243 | } |
241 | template <class T> | 244 | template <class T> |
242 | typename OPimAccessTemplate<T>::List | 245 | typename OPimAccessTemplate<T>::List |
243 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 246 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { |
244 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | 247 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); |
245 | 248 | ||
246 | List lis(ints, this ); | 249 | List lis(ints, this ); |
247 | return lis; | 250 | return lis; |
248 | } | 251 | } |
249 | template <class T> | 252 | template <class T> |
250 | T OPimAccessTemplate<T>::find( int uid ) const{ | 253 | T OPimAccessTemplate<T>::find( int uid ) const{ |
251 | T t = m_backEnd->find( uid ); | 254 | T t = m_backEnd->find( uid ); |
252 | cache( t ); | 255 | cache( t ); |
253 | return t; | 256 | return t; |
254 | } | 257 | } |
255 | template <class T> | 258 | template <class T> |
256 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 259 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
257 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 260 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
258 | /* | 261 | /* |
259 | * better do T.isEmpty() | 262 | * better do T.isEmpty() |
260 | * after a find this way we would | 263 | * after a find this way we would |
261 | * avoid two finds in QCache... | 264 | * avoid two finds in QCache... |
262 | */ | 265 | */ |
263 | // qWarning("find it now %d", uid ); | 266 | // owarn << "find it now " << uid << oendl; |
264 | if (m_cache.contains( uid ) ) { | 267 | if (m_cache.contains( uid ) ) { |
265 | return m_cache.find( uid ); | 268 | return m_cache.find( uid ); |
266 | } | 269 | } |
267 | 270 | ||
268 | T t = m_backEnd->find( uid, ar, current, dir ); | 271 | T t = m_backEnd->find( uid, ar, current, dir ); |
269 | cache( t ); | 272 | cache( t ); |
270 | return t; | 273 | return t; |
271 | } | 274 | } |
272 | template <class T> | 275 | template <class T> |
273 | void OPimAccessTemplate<T>::clear() { | 276 | void OPimAccessTemplate<T>::clear() { |
274 | invalidateCache(); | 277 | invalidateCache(); |
275 | m_backEnd->clear(); | 278 | m_backEnd->clear(); |
276 | } | 279 | } |
277 | template <class T> | 280 | template <class T> |
278 | bool OPimAccessTemplate<T>::add( const T& t ) { | 281 | bool OPimAccessTemplate<T>::add( const T& t ) { |
279 | cache( t ); | 282 | cache( t ); |
280 | return m_backEnd->add( t ); | 283 | return m_backEnd->add( t ); |
281 | } | 284 | } |
282 | 285 | ||
283 | template <class T> | 286 | template <class T> |
284 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 287 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
285 | /* same type */ | 288 | /* same type */ |
286 | T tempInstance; | 289 | T tempInstance; |
287 | if ( rec.rtti() == tempInstance.rtti() ) { | 290 | if ( rec.rtti() == tempInstance.rtti() ) { |