summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/pim/opimaccessbackend.h
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/pim/opimaccessbackend.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/pim/opimaccessbackend.h160
1 files changed, 160 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/opimaccessbackend.h b/noncore/unsupported/libopie/pim/opimaccessbackend.h
new file mode 100644
index 0000000..fd264fc
--- a/dev/null
+++ b/noncore/unsupported/libopie/pim/opimaccessbackend.h
@@ -0,0 +1,160 @@
1#ifndef OPIE_PIM_ACCESS_BACKEND
2#define OPIE_PIM_ACCESS_BACKEND
3
4#include <qarray.h>
5#include <qdatetime.h>
6
7#include <opie/otemplatebase.h>
8#include <opie/opimrecord.h>
9
10
11class OPimAccessBackendPrivate;
12/**
13 * OPimAccessBackend is the base class
14 * for all private backends
15 * it operates on OPimRecord as the base class
16 * and it's responsible for fast manipulating
17 * the resource the implementation takes care
18 * of
19 */
20template <class T = OPimRecord>
21class OPimAccessBackend {
22public:
23 typedef OTemplateBase<T> Frontend;
24
25 /** The access hint from the frontend */
26 OPimAccessBackend(int access = 0);
27 virtual ~OPimAccessBackend();
28
29 /**
30 * load the resource
31 */
32 virtual bool load() = 0;
33
34 /**
35 * reload the resource
36 */
37 virtual bool reload() = 0;
38
39 /**
40 * save the resource and
41 * all it's changes
42 */
43 virtual bool save() = 0;
44
45 /**
46 * return an array of
47 * all available uids
48 */
49 virtual QArray<int> allRecords()const = 0;
50
51 /**
52 * return a List of records
53 * that match the regex
54 */
55 virtual QArray<int> matchRegexp(const QRegExp &r) const = 0;
56
57 /**
58 * queryByExample for T with the given Settings
59 *
60 */
61 virtual QArray<int> queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() ) = 0;
62
63 /**
64 * find the OPimRecord with uid @param uid
65 * returns T and T.isEmpty() if nothing was found
66 */
67 virtual T find(int uid )const = 0;
68
69 virtual T find(int uid, const QArray<int>& items,
70 uint current, typename Frontend::CacheDirection )const ;
71 /**
72 * clear the back end
73 */
74 virtual void clear() = 0;
75
76 /**
77 * add T
78 */
79 virtual bool add( const T& t ) = 0;
80
81 /**
82 * remove
83 */
84 virtual bool remove( int uid ) = 0;
85
86 /**
87 * replace a record with T.uid()
88 */
89 virtual bool replace( const T& t ) = 0;
90
91 /*
92 * setTheFrontEnd!!!
93 */
94 void setFrontend( Frontend* front );
95
96 /**
97 * set the read ahead count
98 */
99 void setReadAhead( uint count );
100protected:
101 int access()const;
102 void cache( const T& t )const;
103
104 /**
105 * use a prime number here!
106 */
107 void setSaneCacheSize( int );
108
109 uint readAhead()const;
110
111private:
112 OPimAccessBackendPrivate *d;
113 Frontend* m_front;
114 uint m_read;
115 int m_acc;
116
117};
118
119template <class T>
120OPimAccessBackend<T>::OPimAccessBackend(int acc)
121 : m_acc( acc )
122{
123 m_front = 0l;
124}
125template <class T>
126OPimAccessBackend<T>::~OPimAccessBackend() {
127
128}
129template <class T>
130void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
131 m_front = fr;
132}
133template <class T>
134void OPimAccessBackend<T>::cache( const T& t )const {
135 if (m_front )
136 m_front->cache( t );
137}
138template <class T>
139void OPimAccessBackend<T>::setSaneCacheSize( int size) {
140 if (m_front )
141 m_front->setSaneCacheSize( size );
142}
143template <class T>
144T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
145 uint, typename Frontend::CacheDirection )const {
146 return find( uid );
147}
148template <class T>
149void OPimAccessBackend<T>::setReadAhead( uint count ) {
150 m_read = count;
151}
152template <class T>
153uint OPimAccessBackend<T>::readAhead()const {
154 return m_read;
155}
156template <class T>
157int OPimAccessBackend<T>::access()const {
158 return m_acc;
159}
160#endif