Diffstat (limited to 'libopie/pim/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 144 |
1 files changed, 90 insertions, 54 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index f2a241d..e0708e1 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -4,79 +4,115 @@ | |||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "otemplatebase.h" | ||
11 | |||
10 | template <class T = OPimRecord > | 12 | template <class T = OPimRecord > |
11 | class OPimAccessTemplate { | 13 | class OPimAccessTemplate : public OTemplateBase<T> { |
12 | public: | 14 | public: |
13 | typedef ORecordList<T> List; | 15 | typedef ORecordList<T> List; |
14 | typedef OPimAccessBackend<T> BackEnd; | 16 | typedef OPimAccessBackend<T> BackEnd; |
15 | OPimAccessTemplate( BackEnd* end) | 17 | OPimAccessTemplate( BackEnd* end); |
16 | : m_backEnd( end ) { | 18 | virtual ~OPimAccessTemplate(); |
17 | } | 19 | virtual void load(); |
18 | ~OPimAccessTemplate() { | 20 | virtual void reload(); |
19 | delete m_backEnd; | 21 | virtual void save(); |
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 | 22 | ||
31 | /* | 23 | /* |
32 | *do array to Records conversion | 24 | *do array to Records conversion |
33 | * QArray<int> ids | 25 | * QArray<int> ids |
34 | */ | 26 | */ |
35 | virtual List allRecords()const { | 27 | virtual List allRecords()const; |
36 | QArray<int> ints = m_backEnd->allRecords(); | 28 | virtual List queryByExample( const T& t, int sortOrder ); |
37 | 29 | virtual T find( int uid ); | |
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 | 30 | ||
53 | /* invalidate cache here */ | 31 | /* invalidate cache here */ |
54 | virtual void clear() { | 32 | virtual void clear() ; |
55 | invalidateCache(); | 33 | virtual bool add( const T& t ) ; |
56 | m_backEnd->clear(); | ||
57 | } | ||
58 | virtual bool add( const T& t ) { | ||
59 | return m_backEnd->add( t ); | ||
60 | } | ||
61 | 34 | ||
62 | /* only the uid matters */ | 35 | /* only the uid matters */ |
63 | virtual bool remove( const T& t ) { | 36 | virtual bool remove( const T& t ); |
64 | /* remove from cache */ | 37 | virtual bool remove( int uid ); |
65 | return m_backEnd->remove( t.uid() ); | 38 | virtual bool replace( const T& t) ; |
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: | 39 | protected: |
75 | void invalidateCache() { | 40 | void invalidateCache(); |
76 | 41 | BackEnd* backEnd(); | |
77 | } | ||
78 | BackEnd* m_backEnd; | 42 | BackEnd* m_backEnd; |
79 | 43 | ||
80 | }; | 44 | }; |
81 | 45 | ||
46 | template <class T> | ||
47 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | ||
48 | : OTemplateBase<T>(), m_backEnd( end ) | ||
49 | { | ||
50 | |||
51 | } | ||
52 | template <class T> | ||
53 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | ||
54 | qWarning("~OPimAccessTemplate<T>"); | ||
55 | delete m_backEnd; | ||
56 | } | ||
57 | template <class T> | ||
58 | void OPimAccessTemplate<T>::load() { | ||
59 | m_backEnd->load(); | ||
60 | } | ||
61 | template <class T> | ||
62 | void OPimAccessTemplate<T>::reload() { | ||
63 | m_backEnd->reload(); | ||
64 | } | ||
65 | template <class T> | ||
66 | void OPimAccessTemplate<T>::save() { | ||
67 | m_backEnd->save(); | ||
68 | } | ||
69 | template <class T> | ||
70 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | ||
71 | QArray<int> ints = m_backEnd->allRecords(); | ||
72 | List lis(ints, this ); | ||
73 | return lis; | ||
74 | } | ||
75 | template <class T> | ||
76 | OPimAccessTemplate<T>::List | ||
77 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | ||
78 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | ||
79 | |||
80 | List lis(ints, this ); | ||
81 | return lis; | ||
82 | } | ||
83 | template <class T> | ||
84 | T OPimAccessTemplate<T>::find( int uid ) { | ||
85 | T t = m_backEnd->find( uid ); | ||
86 | return t; | ||
87 | } | ||
88 | template <class T> | ||
89 | void OPimAccessTemplate<T>::clear() { | ||
90 | invalidateCache(); | ||
91 | m_backEnd->clear(); | ||
92 | } | ||
93 | template <class T> | ||
94 | bool OPimAccessTemplate<T>::add( const T& t ) { | ||
95 | return m_backEnd->add( t ); | ||
96 | } | ||
97 | template <class T> | ||
98 | bool OPimAccessTemplate<T>::remove( const T& t ) { | ||
99 | return m_backEnd->remove( t.uid() ); | ||
100 | } | ||
101 | template <class T> | ||
102 | bool OPimAccessTemplate<T>::remove( int uid ) { | ||
103 | return m_backEnd->remove( uid ); | ||
104 | } | ||
105 | template <class T> | ||
106 | bool OPimAccessTemplate<T>::replace( const T& t ) { | ||
107 | return m_backEnd->replace( t ); | ||
108 | } | ||
109 | template <class T> | ||
110 | void OPimAccessTemplate<T>::invalidateCache() { | ||
111 | |||
112 | } | ||
113 | template <class T> | ||
114 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | ||
115 | return m_backEnd; | ||
116 | } | ||
117 | |||
82 | #endif | 118 | #endif |