summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimaccesstemplate.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h43
1 files changed, 38 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index ecbeb68..5826cbc 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,59 +1,89 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 29#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
2#define OPIE_PIM_ACCESS_TEMPLATE_H 30#define OPIE_PIM_ACCESS_TEMPLATE_H
3 31
4#include <qarray.h> 32#include <qarray.h>
5 33
6#include <opie/opimrecord.h> 34#include <opie2/opimrecord.h>
7#include <opie/opimaccessbackend.h> 35#include <opie2/opimaccessbackend.h>
8#include <opie/orecordlist.h> 36#include <opie2/orecordlist.h>
9 37
10#include "opimcache.h" 38#include <opie2/opimcache.h>
11#include "otemplatebase.h" 39#include <opie2/otemplatebase.h>
40
41namespace Opie {
12 42
13class OPimAccessTemplatePrivate; 43class OPimAccessTemplatePrivate;
14/** 44/**
15 * Thats the frontend to our OPIE PIM 45 * Thats the frontend to our OPIE PIM
16 * Library. Either you want to use it's 46 * Library. Either you want to use it's
17 * interface or you want to implement 47 * interface or you want to implement
18 * your own Access lib 48 * your own Access lib
19 * Just create a OPimRecord and inherit from 49 * Just create a OPimRecord and inherit from
20 * the plugins 50 * the plugins
21 */ 51 */
22 52
23template <class T = OPimRecord > 53template <class T = OPimRecord >
24class OPimAccessTemplate : public OTemplateBase<T> { 54class OPimAccessTemplate : public OTemplateBase<T> {
25public: 55public:
26 enum Access { 56 enum Access {
27 Random = 0, 57 Random = 0,
28 SortedAccess 58 SortedAccess
29 }; 59 };
30 typedef ORecordList<T> List; 60 typedef ORecordList<T> List;
31 typedef OPimAccessBackend<T> BackEnd; 61 typedef OPimAccessBackend<T> BackEnd;
32 typedef OPimCache<T> Cache; 62 typedef OPimCache<T> Cache;
33 63
34 /** 64 /**
35 * c'tor BackEnd 65 * c'tor BackEnd
36 * enum Access a small hint on how to handle the backend 66 * enum Access a small hint on how to handle the backend
37 */ 67 */
38 OPimAccessTemplate( BackEnd* end); 68 OPimAccessTemplate( BackEnd* end);
39 69
40 virtual ~OPimAccessTemplate(); 70 virtual ~OPimAccessTemplate();
41 71
42 /** 72 /**
43 * load from the backend 73 * load from the backend
44 */ 74 */
45 bool load(); 75 bool load();
46 76
47 /** Reload database. 77 /** Reload database.
48 * You should execute this function if the external database 78 * You should execute this function if the external database
49 * was changed. 79 * was changed.
50 * This function will load the external database and afterwards 80 * This function will load the external database and afterwards
51 * rejoin the local changes. Therefore the local database will be set consistent. 81 * rejoin the local changes. Therefore the local database will be set consistent.
52 */ 82 */
53 virtual bool reload(); 83 virtual bool reload();
54 84
55 /** Save contacts database. 85 /** Save contacts database.
56 * Save is more a "commit". After calling this function, all changes are public available. 86 * Save is more a "commit". After calling this function, all changes are public available.
57 * @return true if successful 87 * @return true if successful
58 */ 88 */
59 bool save(); 89 bool save();
@@ -254,49 +284,52 @@ template <class T>
254bool OPimAccessTemplate<T>::remove( const T& t ) { 284bool OPimAccessTemplate<T>::remove( const T& t ) {
255 return remove( t.uid() ); 285 return remove( t.uid() );
256} 286}
257template <class T> 287template <class T>
258bool OPimAccessTemplate<T>::remove( int uid ) { 288bool OPimAccessTemplate<T>::remove( int uid ) {
259 m_cache.remove( uid ); 289 m_cache.remove( uid );
260 return m_backEnd->remove( uid ); 290 return m_backEnd->remove( uid );
261} 291}
262template <class T> 292template <class T>
263bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 293bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
264 return remove( rec.uid() ); 294 return remove( rec.uid() );
265} 295}
266template <class T> 296template <class T>
267bool OPimAccessTemplate<T>::replace( const T& t ) { 297bool OPimAccessTemplate<T>::replace( const T& t ) {
268 m_cache.replace( t ); 298 m_cache.replace( t );
269 return m_backEnd->replace( t ); 299 return m_backEnd->replace( t );
270} 300}
271template <class T> 301template <class T>
272void OPimAccessTemplate<T>::invalidateCache() { 302void OPimAccessTemplate<T>::invalidateCache() {
273 m_cache.invalidate(); 303 m_cache.invalidate();
274} 304}
275template <class T> 305template <class T>
276typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 306typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
277 return m_backEnd; 307 return m_backEnd;
278} 308}
279template <class T> 309template <class T>
280bool OPimAccessTemplate<T>::wasChangedExternally()const { 310bool OPimAccessTemplate<T>::wasChangedExternally()const {
281 return false; 311 return false;
282} 312}
283template <class T> 313template <class T>
284void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 314void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
285 m_backEnd = end; 315 m_backEnd = end;
286 if (m_backEnd ) 316 if (m_backEnd )
287 m_backEnd->setFrontend( this ); 317 m_backEnd->setFrontend( this );
288} 318}
289template <class T> 319template <class T>
290void OPimAccessTemplate<T>::cache( const T& t ) const{ 320void OPimAccessTemplate<T>::cache( const T& t ) const{
291 /* hacky we need to work around the const*/ 321 /* hacky we need to work around the const*/
292 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 322 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
293} 323}
294template <class T> 324template <class T>
295void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 325void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
296 m_cache.setSize( size ); 326 m_cache.setSize( size );
297} 327}
298template <class T> 328template <class T>
299void OPimAccessTemplate<T>::setReadAhead( uint count ) { 329void OPimAccessTemplate<T>::setReadAhead( uint count ) {
300 m_backEnd->setReadAhead( count ); 330 m_backEnd->setReadAhead( count );
301} 331}
332
333}
334
302#endif 335#endif