Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index f1bcc44..d4c5fbb 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,15 +1,16 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) The Main Author <main-author@whereever.org> | 3 | Copyright (C) Holger Freyther <zecke@handhelds.org> |
4 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 5 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 6 | .=l. |
6 | .>+-= | 7 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 14 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
@@ -128,24 +129,31 @@ public: | |||
128 | /** | 129 | /** |
129 | * clears the backend and invalidates the backend | 130 | * clears the backend and invalidates the backend |
130 | */ | 131 | */ |
131 | void clear() ; | 132 | void clear() ; |
132 | 133 | ||
133 | /** | 134 | /** |
134 | * add T to the backend | 135 | * add T to the backend |
135 | * @param t The item to add. | 136 | * @param t The item to add. |
136 | * @return <i>true</i> if added successfully. | 137 | * @return <i>true</i> if added successfully. |
137 | */ | 138 | */ |
138 | virtual bool add( const T& t ) ; | 139 | virtual bool add( const T& t ) ; |
139 | bool add( const OPimRecord& ); | 140 | bool add( const OPimRecord& ); |
141 | // Needed for real generic access (eilers) | ||
142 | // Info: Take this if you are working with OPimRecord, which is a generic base class, and | ||
143 | // you need to add it into any database, you cannot generate a reference to | ||
144 | // it and casting may be not approriate, too. | ||
145 | // But take care that the accessing database is compatible to the real type of OPimRecord !! | ||
146 | bool add( const OPimRecord* ); | ||
147 | |||
140 | 148 | ||
141 | /* only the uid matters */ | 149 | /* only the uid matters */ |
142 | /** | 150 | /** |
143 | * remove T from the backend | 151 | * remove T from the backend |
144 | * @param t The item to remove | 152 | * @param t The item to remove |
145 | * @return <i>true</i> if successful. | 153 | * @return <i>true</i> if successful. |
146 | */ | 154 | */ |
147 | virtual bool remove( const T& t ); | 155 | virtual bool remove( const T& t ); |
148 | 156 | ||
149 | /** | 157 | /** |
150 | * remove the OPimRecord with uid | 158 | * remove the OPimRecord with uid |
151 | * @param uid The ID of the item to remove | 159 | * @param uid The ID of the item to remove |
@@ -262,33 +270,47 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | |||
262 | return t; | 270 | return t; |
263 | } | 271 | } |
264 | template <class T> | 272 | template <class T> |
265 | void OPimAccessTemplate<T>::clear() { | 273 | void OPimAccessTemplate<T>::clear() { |
266 | invalidateCache(); | 274 | invalidateCache(); |
267 | m_backEnd->clear(); | 275 | m_backEnd->clear(); |
268 | } | 276 | } |
269 | template <class T> | 277 | template <class T> |
270 | bool OPimAccessTemplate<T>::add( const T& t ) { | 278 | bool OPimAccessTemplate<T>::add( const T& t ) { |
271 | cache( t ); | 279 | cache( t ); |
272 | return m_backEnd->add( t ); | 280 | return m_backEnd->add( t ); |
273 | } | 281 | } |
282 | |||
274 | template <class T> | 283 | template <class T> |
275 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 284 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { |
276 | /* same type */ | 285 | /* same type */ |
277 | if ( rec.rtti() == T::rtti() ) { | 286 | T tempInstance; |
278 | const T &t = static_cast<const T&>(rec); | 287 | if ( rec.rtti() == tempInstance.rtti() ) { |
288 | const T& t = static_cast<const T&>(rec); | ||
279 | return add(t); | 289 | return add(t); |
280 | } | 290 | } |
281 | return false; | 291 | return false; |
282 | } | 292 | } |
293 | |||
294 | template <class T> | ||
295 | bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { | ||
296 | /* same type, but pointer */ | ||
297 | T tempInstance; | ||
298 | if ( rec -> rtti() == tempInstance.rtti() ) { | ||
299 | const T* t = static_cast<const T*>(rec); | ||
300 | return add( *t ); | ||
301 | } | ||
302 | return false; | ||
303 | } | ||
304 | |||
283 | template <class T> | 305 | template <class T> |
284 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 306 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
285 | return remove( t.uid() ); | 307 | return remove( t.uid() ); |
286 | } | 308 | } |
287 | template <class T> | 309 | template <class T> |
288 | bool OPimAccessTemplate<T>::remove( int uid ) { | 310 | bool OPimAccessTemplate<T>::remove( int uid ) { |
289 | m_cache.remove( uid ); | 311 | m_cache.remove( uid ); |
290 | return m_backEnd->remove( uid ); | 312 | return m_backEnd->remove( uid ); |
291 | } | 313 | } |
292 | template <class T> | 314 | template <class T> |
293 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 315 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
294 | return remove( rec.uid() ); | 316 | return remove( rec.uid() ); |