-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 40 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 |
2 files changed, 45 insertions, 11 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 55d600a..6f01b46 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -35,7 +35,6 @@ | |||
35 | #include <opie2/opimaccessbackend.h> | 35 | #include <opie2/opimaccessbackend.h> |
36 | #include <opie2/opimrecordlist.h> | 36 | #include <opie2/opimrecordlist.h> |
37 | 37 | ||
38 | #include <opie2/opimcache.h> | ||
39 | #include <opie2/opimtemplatebase.h> | 38 | #include <opie2/opimtemplatebase.h> |
40 | #include <opie2/odebug.h> | 39 | #include <opie2/odebug.h> |
41 | 40 | ||
@@ -128,6 +127,7 @@ public: | |||
128 | virtual T find( int uid, const QArray<int>&, | 127 | virtual T find( int uid, const QArray<int>&, |
129 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | 128 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; |
130 | 129 | ||
130 | |||
131 | /* invalidate cache here */ | 131 | /* invalidate cache here */ |
132 | /** | 132 | /** |
133 | * clears the backend and invalidates the backend | 133 | * clears the backend and invalidates the backend |
@@ -139,13 +139,15 @@ public: | |||
139 | * @param t The item to add. | 139 | * @param t The item to add. |
140 | * @return <i>true</i> if added successfully. | 140 | * @return <i>true</i> if added successfully. |
141 | */ | 141 | */ |
142 | virtual bool add( const T& t ) ; | 142 | virtual bool add( const T& t ) ; |
143 | |||
143 | bool add( const OPimRecord& ); | 144 | bool add( const OPimRecord& ); |
144 | // Needed for real generic access (eilers) | 145 | /** |
145 | // Info: Take this if you are working with OPimRecord, which is a generic base class, and | 146 | * Add an Opie PimRecord. |
146 | // you need to add it into any database, you cannot generate a reference to | 147 | * Info: Take this if you are working with OPimRecords and you need to add it into any database. |
147 | // it and casting may be not approriate, too. | 148 | * But take care that the accessing database is compatible to the real type of OPimRecord !! |
148 | // But take care that the accessing database is compatible to the real type of OPimRecord !! | 149 | * Otherwise this access will be rejected ! |
150 | */ | ||
149 | bool add( const OPimRecord* ); | 151 | bool add( const OPimRecord* ); |
150 | 152 | ||
151 | 153 | ||
@@ -176,6 +178,7 @@ public: | |||
176 | /** | 178 | /** |
177 | * @internal | 179 | * @internal |
178 | */ | 180 | */ |
181 | virtual T cacheFind( int uid )const; | ||
179 | void cache( const T& )const; | 182 | void cache( const T& )const; |
180 | void setSaneCacheSize( int ); | 183 | void setSaneCacheSize( int ); |
181 | 184 | ||
@@ -192,6 +195,7 @@ protected: | |||
192 | */ | 195 | */ |
193 | BackEnd* backEnd(); | 196 | BackEnd* backEnd(); |
194 | BackEnd* m_backEnd; | 197 | BackEnd* m_backEnd; |
198 | |||
195 | Cache m_cache; | 199 | Cache m_cache; |
196 | 200 | ||
197 | private: | 201 | private: |
@@ -218,7 +222,7 @@ bool OPimAccessTemplate<T>::load() { | |||
218 | } | 222 | } |
219 | template <class T> | 223 | template <class T> |
220 | bool OPimAccessTemplate<T>::reload() { | 224 | bool OPimAccessTemplate<T>::reload() { |
221 | invalidateCache(); // zecke: I think this should be added (se) | 225 | invalidateCache(); |
222 | return m_backEnd->reload(); | 226 | return m_backEnd->reload(); |
223 | } | 227 | } |
224 | template <class T> | 228 | template <class T> |
@@ -251,10 +255,22 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime | |||
251 | } | 255 | } |
252 | template <class T> | 256 | template <class T> |
253 | T OPimAccessTemplate<T>::find( int uid ) const{ | 257 | T OPimAccessTemplate<T>::find( int uid ) const{ |
258 | // First search in cache.. | ||
259 | if ( m_cache.contains( uid ) ) | ||
260 | return m_cache.find( uid ); | ||
261 | |||
254 | T t = m_backEnd->find( uid ); | 262 | T t = m_backEnd->find( uid ); |
255 | cache( t ); | 263 | cache( t ); |
264 | |||
256 | return t; | 265 | return t; |
257 | } | 266 | } |
267 | |||
268 | template <class T> | ||
269 | T OPimAccessTemplate<T>::cacheFind( int uid ) const | ||
270 | { | ||
271 | return m_cache.find( uid ); | ||
272 | } | ||
273 | |||
258 | template <class T> | 274 | template <class T> |
259 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 275 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
260 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | 276 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { |
@@ -264,7 +280,7 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | |||
264 | * avoid two finds in QCache... | 280 | * avoid two finds in QCache... |
265 | */ | 281 | */ |
266 | // owarn << "find it now " << uid << oendl; | 282 | // owarn << "find it now " << uid << oendl; |
267 | if (m_cache.contains( uid ) ) { | 283 | if ( m_cache.contains( uid ) ) { |
268 | return m_cache.find( uid ); | 284 | return m_cache.find( uid ); |
269 | } | 285 | } |
270 | 286 | ||
@@ -284,12 +300,14 @@ bool OPimAccessTemplate<T>::add( const T& t ) { | |||
284 | } | 300 | } |
285 | 301 | ||
286 | template <class T> | 302 | template <class T> |
287 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 303 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) { |
288 | /* same type */ | 304 | /* same type */ |
289 | T tempInstance; | 305 | T tempInstance; |
290 | if ( rec.rtti() == tempInstance.rtti() ) { | 306 | if ( rec.rtti() == tempInstance.rtti() ) { |
291 | const T& t = static_cast<const T&>(rec); | 307 | const T& t = static_cast<const T&>(rec); |
292 | return add(t); | 308 | return add(t); |
309 | } else { | ||
310 | owarn << "Adding not possible: Objecttype mismatch" << oendl; | ||
293 | } | 311 | } |
294 | return false; | 312 | return false; |
295 | } | 313 | } |
@@ -301,6 +319,8 @@ bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { | |||
301 | if ( rec -> rtti() == tempInstance.rtti() ) { | 319 | if ( rec -> rtti() == tempInstance.rtti() ) { |
302 | const T* t = static_cast<const T*>(rec); | 320 | const T* t = static_cast<const T*>(rec); |
303 | return add( *t ); | 321 | return add( *t ); |
322 | } else { | ||
323 | owarn << "Adding not possible: Objecttype mismatch" << oendl; | ||
304 | } | 324 | } |
305 | return false; | 325 | return false; |
306 | } | 326 | } |
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index b48dfed..ec9a94e 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/opimrecord.h> | 33 | #include <opie2/opimrecord.h> |
34 | #include <opie2/opimcache.h> | ||
34 | 35 | ||
35 | /* QT */ | 36 | /* QT */ |
36 | #include <qarray.h> | 37 | #include <qarray.h> |
@@ -70,13 +71,15 @@ private: | |||
70 | }; | 71 | }; |
71 | /** | 72 | /** |
72 | * internal template base | 73 | * internal template base |
73 | * T needs to implement the copy c'tor!!! | 74 | * Attention: T needs to implement the copy c'tor!!! |
74 | */ | 75 | */ |
75 | class OTemplateBasePrivate; | 76 | class OTemplateBasePrivate; |
76 | template <class T = OPimRecord> | 77 | template <class T = OPimRecord> |
77 | class OTemplateBase : public OPimBase { | 78 | class OTemplateBase : public OPimBase { |
78 | public: | 79 | public: |
80 | /** Look ahead direction of cache */ | ||
79 | enum CacheDirection { Forward=0, Reverse }; | 81 | enum CacheDirection { Forward=0, Reverse }; |
82 | |||
80 | OTemplateBase() { | 83 | OTemplateBase() { |
81 | }; | 84 | }; |
82 | virtual ~OTemplateBase() { | 85 | virtual ~OTemplateBase() { |
@@ -88,12 +91,23 @@ public: | |||
88 | */ | 91 | */ |
89 | virtual T find( int uid, const QArray<int>& items, | 92 | virtual T find( int uid, const QArray<int>& items, |
90 | uint current, CacheDirection dir = Forward )const = 0; | 93 | uint current, CacheDirection dir = Forward )const = 0; |
94 | |||
95 | /** | ||
96 | * Find in Cache.. | ||
97 | * Returns empty object if nothing found. | ||
98 | */ | ||
99 | virtual T cacheFind( int uid )const = 0; | ||
100 | |||
101 | /** | ||
102 | * Put element into Cache | ||
103 | */ | ||
91 | virtual void cache( const T& )const = 0; | 104 | virtual void cache( const T& )const = 0; |
92 | virtual void setSaneCacheSize( int ) = 0; | 105 | virtual void setSaneCacheSize( int ) = 0; |
93 | 106 | ||
94 | OPimRecord* record()const; | 107 | OPimRecord* record()const; |
95 | OPimRecord* record(int uid )const; | 108 | OPimRecord* record(int uid )const; |
96 | static T* rec(); | 109 | static T* rec(); |
110 | |||
97 | 111 | ||
98 | private: | 112 | private: |
99 | OTemplateBasePrivate *d; | 113 | OTemplateBasePrivate *d; |