-rw-r--r-- | libopie/pim/opimaccessbackend.h | 19 | ||||
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 144 | ||||
-rw-r--r-- | libopie/pim/opimrecord.cpp | 6 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 124 | ||||
-rw-r--r-- | libopie/pim/otemplatebase.h | 18 |
6 files changed, 194 insertions, 119 deletions
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h index d9af589..8e744e7 100644 --- a/libopie/pim/opimaccessbackend.h +++ b/libopie/pim/opimaccessbackend.h | |||
@@ -10,6 +10,4 @@ class OPimAccessBackend { | |||
10 | public: | 10 | public: |
11 | OPimAccessBackend() { | 11 | OPimAccessBackend(); |
12 | } | 12 | virtual ~OPimAccessBackend(); |
13 | ~OPimAccessBackend() { | ||
14 | } | ||
15 | virtual void load() = 0; | 13 | virtual void load() = 0; |
@@ -17,3 +15,3 @@ public: | |||
17 | virtual void save() = 0; | 15 | virtual void save() = 0; |
18 | virtual QArray<int> allRecords() = 0; | 16 | virtual QArray<int> allRecords()const = 0; |
19 | virtual QArray<int> queryByExample( const T& t, int sort ) = 0; | 17 | virtual QArray<int> queryByExample( const T& t, int sort ) = 0; |
@@ -23,3 +21,3 @@ public: | |||
23 | virtual bool remove( int uid ) = 0; | 21 | virtual bool remove( int uid ) = 0; |
24 | virtual void replace( const T& t ) = 0; | 22 | virtual bool replace( const T& t ) = 0; |
25 | 23 | ||
@@ -28,2 +26,11 @@ public: | |||
28 | 26 | ||
27 | template <class T> | ||
28 | OPimAccessBackend<T>::OPimAccessBackend() { | ||
29 | |||
30 | } | ||
31 | template <class T> | ||
32 | OPimAccessBackend<T>::~OPimAccessBackend() { | ||
33 | |||
34 | } | ||
35 | |||
29 | #endif | 36 | #endif |
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 | |||
@@ -9,4 +9,6 @@ | |||
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: |
@@ -14,17 +16,7 @@ public: | |||
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 | ||
@@ -34,45 +26,17 @@ public: | |||
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; |
@@ -81,2 +45,74 @@ protected: | |||
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 |
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index 88b6fde..60cdbf3 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp | |||
@@ -5,2 +5,5 @@ | |||
5 | 5 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | ||
7 | |||
8 | |||
6 | OPimRecord::OPimRecord( int uid ) | 9 | OPimRecord::OPimRecord( int uid ) |
@@ -127 +130,4 @@ void OPimRecord::setUid( int uid ) { | |||
127 | }; | 130 | }; |
131 | Qtopia::UidGen &OPimRecord::uidGen() { | ||
132 | return m_uidGen; | ||
133 | } | ||
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index 297ff12..e4d33d6 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h | |||
@@ -106,2 +106,3 @@ public: | |||
106 | protected: | 106 | protected: |
107 | Qtopia::UidGen &uidGen(); | ||
107 | QString crossToString()const; | 108 | QString crossToString()const; |
@@ -112,2 +113,3 @@ private: | |||
112 | QMap<QString, QArray<int> > m_relations; | 113 | QMap<QString, QArray<int> > m_relations; |
114 | static Qtopia::UidGen m_uidGen; | ||
113 | 115 | ||
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 65c2169..a3955b0 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -4,4 +4,35 @@ | |||
4 | 4 | ||
5 | #include <opie/opimaccesstemplate.h> | 5 | #include <qarray.h> |
6 | #include <opie/opimrecord.h> | 6 | |
7 | #include "otemplatebase.h" | ||
8 | #include "opimrecord.h" | ||
9 | |||
10 | |||
11 | template <class T = OPimRecord> | ||
12 | class ORecordListIterator { | ||
13 | public: | ||
14 | typedef OTemplateBase<T> Base; | ||
15 | ORecordListIterator( const QArray<int>, const Base* ); | ||
16 | ORecordListIterator(); | ||
17 | ~ORecordListIterator(); | ||
18 | ORecordListIterator( const ORecordListIterator& ); | ||
19 | ORecordListIterator &operator=(const ORecordListIterator& ); | ||
20 | T &operator*(); | ||
21 | ORecordListIterator &operator++(); | ||
22 | ORecordListIterator &operator--(); | ||
23 | |||
24 | bool operator==( const ORecordListIterator& it ); | ||
25 | bool operator!=( const ORecordListIterator& it ); | ||
26 | |||
27 | private: | ||
28 | QArray<int> m_uids; | ||
29 | int m_current; | ||
30 | const Base* m_temp; | ||
31 | bool m_end : 1; | ||
32 | T m_record; | ||
33 | |||
34 | /* d pointer for future versions */ | ||
35 | class IteratorPrivate; | ||
36 | IteratorPrivate *d; | ||
37 | }; | ||
7 | 38 | ||
@@ -10,32 +41,6 @@ class ORecordList { | |||
10 | public: | 41 | public: |
11 | class Iterator { | 42 | typedef OTemplateBase<T> Base; |
12 | friend class ORecordList; | 43 | typedef ORecordListIterator<T> Iterator; |
13 | public: | ||
14 | Iterator(); | ||
15 | ~Iterator(); | ||
16 | Iterator(const Iterator& ); | ||
17 | Iterator &operator=(const Iterator& ); | ||
18 | T &operator*(); | ||
19 | Iterator &operator++(); | ||
20 | Iterator &operator--(); | ||
21 | |||
22 | bool operator==( const Iterator& it ); | ||
23 | bool operator!=( const Iterator& it ); | ||
24 | |||
25 | private: | ||
26 | Iterator( const QArray<int>, | ||
27 | OPimAccessTemplate<T>* ); | ||
28 | |||
29 | QArray<int> m_uids; | ||
30 | int m_current; | ||
31 | OPimAccessTemplate* m_temp; | ||
32 | bool m_end : 1; | ||
33 | T m_record; | ||
34 | |||
35 | /* d pointer for future versions */ | ||
36 | class IteratorPrivate; | ||
37 | IteratorPrivate *d; | ||
38 | }; | ||
39 | ORecordList( const QArray<int>& ids, | 44 | ORecordList( const QArray<int>& ids, |
40 | OPimAccessTemplate<T>* acc ); | 45 | const Base* ); |
41 | ~ORecordList(); | 46 | ~ORecordList(); |
@@ -49,3 +54,3 @@ private: | |||
49 | QArray<int> m_ids; | 54 | QArray<int> m_ids; |
50 | OPimAccessTemplate<T>* m_acc; | 55 | const Base* m_acc; |
51 | }; | 56 | }; |
@@ -53,4 +58,4 @@ private: | |||
53 | /* ok now implement it */ | 58 | /* ok now implement it */ |
54 | template <class T= OPimRecord> | 59 | template <class T> |
55 | ORecordList<T>::Iterator::Iterator() { | 60 | ORecordListIterator<T>::ORecordListIterator() { |
56 | m_current = 0; | 61 | m_current = 0; |
@@ -59,4 +64,4 @@ ORecordList<T>::Iterator::Iterator() { | |||
59 | } | 64 | } |
60 | template <class T= OPimRecord> | 65 | template <class T> |
61 | ORecordList<T>::Iterator::~Iterator() { | 66 | ORecordListIterator<T>::~ORecordListIterator() { |
62 | /* nothing to delete */ | 67 | /* nothing to delete */ |
@@ -64,4 +69,4 @@ ORecordList<T>::Iterator::~Iterator() { | |||
64 | 69 | ||
65 | template <class T = OPimRecord> | 70 | template <class T> |
66 | ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { | 71 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
67 | m_uids = it.m_uids; | 72 | m_uids = it.m_uids; |
@@ -73,4 +78,4 @@ ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { | |||
73 | 78 | ||
74 | template <class T = OPimRecord> | 79 | template <class T> |
75 | ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) { | 80 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
76 | m_uids = it.m_uids; | 81 | m_uids = it.m_uids; |
@@ -84,4 +89,4 @@ ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T> | |||
84 | 89 | ||
85 | template <class T = OPimRecord> | 90 | template <class T> |
86 | T &ORecordList<T>::Iterator::operator*() { | 91 | T &ORecordListIterator<T>::operator*() { |
87 | if (!m_end ) | 92 | if (!m_end ) |
@@ -89,3 +94,3 @@ T &ORecordList<T>::Iterator::operator*() { | |||
89 | else | 94 | else |
90 | m_record = T; | 95 | m_record = T(); |
91 | 96 | ||
@@ -94,4 +99,4 @@ T &ORecordList<T>::Iterator::operator*() { | |||
94 | 99 | ||
95 | template <class T = OPimRecord> | 100 | template <class T> |
96 | ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { | 101 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
97 | if (m_current < m_uids.count() ) { | 102 | if (m_current < m_uids.count() ) { |
@@ -104,4 +109,4 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { | |||
104 | } | 109 | } |
105 | template <class T = OPimRecord> | 110 | template <class T> |
106 | ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { | 111 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
107 | if ( m_current > 0 ) { | 112 | if ( m_current > 0 ) { |
@@ -115,4 +120,4 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { | |||
115 | 120 | ||
116 | template <class T = OPimRecord> | 121 | template <class T> |
117 | bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) { | 122 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
118 | 123 | ||
@@ -127,9 +132,9 @@ bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) | |||
127 | } | 132 | } |
128 | template <class T = ORecordList> | 133 | template <class T> |
129 | bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) { | 134 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
130 | return !(*this == it ); | 135 | return !(*this == it ); |
131 | } | 136 | } |
132 | template <class T = ORecordList> | 137 | template <class T> |
133 | ORecordList<T>::Iterator::Iterator( const QArray<int> uids, | 138 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
134 | OPimAccessTemplate<T>* t ) | 139 | const Base* t ) |
135 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) | 140 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) |
@@ -137,5 +142,6 @@ ORecordList<T>::Iterator::Iterator( const QArray<int> uids, | |||
137 | } | 142 | } |
138 | template <class T = ORecordList> | 143 | |
144 | template <class T> | ||
139 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 145 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
140 | OPimAccessTemplate<T>* acc ) | 146 | const Base* acc ) |
141 | : m_ids( ids ), m_acc( acc ) | 147 | : m_ids( ids ), m_acc( acc ) |
@@ -143,3 +149,3 @@ ORecordList<T>::ORecordList( const QArray<int>& ids, | |||
143 | } | 149 | } |
144 | template <class T = ORecordList> | 150 | template <class T> |
145 | ORecordList<T>::~ORecordList() { | 151 | ORecordList<T>::~ORecordList() { |
@@ -147,3 +153,3 @@ ORecordList<T>::~ORecordList() { | |||
147 | } | 153 | } |
148 | template <class T = ORecordList> | 154 | template <class T> |
149 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 155 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
@@ -152,3 +158,3 @@ ORecordList<T>::Iterator ORecordList<T>::begin() { | |||
152 | } | 158 | } |
153 | template <class T = ORecordList> | 159 | template <class T> |
154 | ORecordList<T>::Iterator ORecordList<T>::end() { | 160 | ORecordList<T>::Iterator ORecordList<T>::end() { |
diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h new file mode 100644 index 0000000..41cc934 --- a/dev/null +++ b/libopie/pim/otemplatebase.h | |||
@@ -0,0 +1,18 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | ||
2 | #define OPIE_TEMPLATE_BASE_H | ||
3 | |||
4 | #include "opimrecord.h" | ||
5 | |||
6 | template <class T = OPimRecord> | ||
7 | class OTemplateBase { | ||
8 | public: | ||
9 | OTemplateBase() { | ||
10 | }; | ||
11 | virtual ~OTemplateBase() { | ||
12 | } | ||
13 | virtual T find( int uid ) = 0; | ||
14 | |||
15 | }; | ||
16 | |||
17 | |||
18 | #endif | ||