summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimaccesstemplate.h
authorzecke <zecke>2002-09-20 12:59:29 (UTC)
committer zecke <zecke>2002-09-20 12:59:29 (UTC)
commita05c10c9744020be31c3038b2de3401b5cc673fb (patch) (unidiff)
tree20d059bf00fc1199c34a60a8be4cb842ebfe4d14 /libopie2/opiepim/core/opimaccesstemplate.h
parent7099778ab711f78cfd86dadad1b8af993e008f38 (diff)
downloadopie-a05c10c9744020be31c3038b2de3401b5cc673fb.zip
opie-a05c10c9744020be31c3038b2de3401b5cc673fb.tar.gz
opie-a05c10c9744020be31c3038b2de3401b5cc673fb.tar.bz2
Our new common template based start for Accessing and Manipulating
the Records The CROSS_REFERENCE branch will get ported to it. We use templates for several reasons They allow us to share code and to be easily extended I've to make them not inline to save memory... I've to port all DBs and Record related classes
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
new file mode 100644
index 0000000..f2a241d
--- a/dev/null
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -0,0 +1,82 @@
1#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
2#define OPIE_PIM_ACCESS_TEMPLATE_H
3
4#include <qarray.h>
5
6#include <opie/opimrecord.h>
7#include <opie/opimaccessbackend.h>
8#include <opie/orecordlist.h>
9
10template <class T = OPimRecord >
11class OPimAccessTemplate {
12public:
13 typedef ORecordList<T> List;
14 typedef OPimAccessBackend<T> BackEnd;
15 OPimAccessTemplate( BackEnd* end)
16 : m_backEnd( end ) {
17 }
18 ~OPimAccessTemplate() {
19 delete m_backEnd;
20 }
21 virtual void load() {
22 m_backEnd->load();
23 }
24 virtual void reload() {
25 m_backEnd->reload();
26 }
27 virtual void save() {
28 m_backEnd->save();
29 }
30
31 /*
32 *do array to Records conversion
33 * QArray<int> ids
34 */
35 virtual List allRecords()const {
36 QArray<int> ints = m_backEnd->allRecords();
37
38 List lis( ints, this );
39 return lis;
40 }
41 virtual List queryByExample( const T& t, int sortOrder ) {
42 QArray<int> ints = m_backEnd->query( t, sortOrder );
43 List lis( ints, this );
44
45 return lis;
46 }
47 /* implement QCache here */
48 virtual T find( int uid ) {
49 T t = m_backEnd->find( uid );
50 return t;
51 }
52
53 /* invalidate cache here */
54 virtual void clear() {
55 invalidateCache();
56 m_backEnd->clear();
57 }
58 virtual bool add( const T& t ) {
59 return m_backEnd->add( t );
60 }
61
62 /* only the uid matters */
63 virtual bool remove( const T& t ) {
64 /* remove from cache */
65 return m_backEnd->remove( t.uid() );
66 }
67 virtual bool remove( int uid ) {
68 /* remove from cache */
69 return m_backEnd->remove(uid);
70 }
71 virtual bool replace( const T& t) {
72 return m_backEnd->replace( t );
73 }
74protected:
75 void invalidateCache() {
76
77 }
78 BackEnd* m_backEnd;
79
80};
81
82#endif