Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 82 |
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 | |||
10 | template <class T = OPimRecord > | ||
11 | class OPimAccessTemplate { | ||
12 | public: | ||
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 | } | ||
74 | protected: | ||
75 | void invalidateCache() { | ||
76 | |||
77 | } | ||
78 | BackEnd* m_backEnd; | ||
79 | |||
80 | }; | ||
81 | |||
82 | #endif | ||