summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/opimaccessbackend.h19
-rw-r--r--libopie/pim/opimaccesstemplate.h144
-rw-r--r--libopie/pim/opimrecord.cpp6
-rw-r--r--libopie/pim/opimrecord.h2
-rw-r--r--libopie/pim/orecordlist.h124
-rw-r--r--libopie/pim/otemplatebase.h18
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 {
10public: 10public:
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
27template <class T>
28OPimAccessBackend<T>::OPimAccessBackend() {
29
30}
31template <class T>
32OPimAccessBackend<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
10template <class T = OPimRecord > 12template <class T = OPimRecord >
11class OPimAccessTemplate { 13class OPimAccessTemplate : public OTemplateBase<T> {
12public: 14public:
@@ -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 }
74protected: 39protected:
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
46template <class T>
47OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
48 : OTemplateBase<T>(), m_backEnd( end )
49{
50
51}
52template <class T>
53OPimAccessTemplate<T>::~OPimAccessTemplate() {
54 qWarning("~OPimAccessTemplate<T>");
55 delete m_backEnd;
56}
57template <class T>
58void OPimAccessTemplate<T>::load() {
59 m_backEnd->load();
60}
61template <class T>
62void OPimAccessTemplate<T>::reload() {
63 m_backEnd->reload();
64}
65template <class T>
66void OPimAccessTemplate<T>::save() {
67 m_backEnd->save();
68}
69template <class T>
70OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
71 QArray<int> ints = m_backEnd->allRecords();
72 List lis(ints, this );
73 return lis;
74}
75template <class T>
76OPimAccessTemplate<T>::List
77OPimAccessTemplate<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}
83template <class T>
84T OPimAccessTemplate<T>::find( int uid ) {
85 T t = m_backEnd->find( uid );
86 return t;
87}
88template <class T>
89void OPimAccessTemplate<T>::clear() {
90 invalidateCache();
91 m_backEnd->clear();
92}
93template <class T>
94bool OPimAccessTemplate<T>::add( const T& t ) {
95 return m_backEnd->add( t );
96}
97template <class T>
98bool OPimAccessTemplate<T>::remove( const T& t ) {
99 return m_backEnd->remove( t.uid() );
100}
101template <class T>
102bool OPimAccessTemplate<T>::remove( int uid ) {
103 return m_backEnd->remove( uid );
104}
105template <class T>
106bool OPimAccessTemplate<T>::replace( const T& t ) {
107 return m_backEnd->replace( t );
108}
109template <class T>
110void OPimAccessTemplate<T>::invalidateCache() {
111
112}
113template <class T>
114OPimAccessTemplate<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
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7
8
6OPimRecord::OPimRecord( int uid ) 9OPimRecord::OPimRecord( int uid )
@@ -127 +130,4 @@ void OPimRecord::setUid( int uid ) {
127}; 130};
131Qtopia::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:
106protected: 106protected:
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
11template <class T = OPimRecord>
12class ORecordListIterator {
13public:
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
27private:
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 {
10public: 41public:
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 */
54template <class T= OPimRecord> 59template <class T>
55ORecordList<T>::Iterator::Iterator() { 60ORecordListIterator<T>::ORecordListIterator() {
56 m_current = 0; 61 m_current = 0;
@@ -59,4 +64,4 @@ ORecordList<T>::Iterator::Iterator() {
59} 64}
60template <class T= OPimRecord> 65template <class T>
61ORecordList<T>::Iterator::~Iterator() { 66ORecordListIterator<T>::~ORecordListIterator() {
62/* nothing to delete */ 67/* nothing to delete */
@@ -64,4 +69,4 @@ ORecordList<T>::Iterator::~Iterator() {
64 69
65template <class T = OPimRecord> 70template <class T>
66ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { 71ORecordListIterator<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
74template <class T = OPimRecord> 79template <class T>
75ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) { 80ORecordListIterator<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
85template <class T = OPimRecord> 90template <class T>
86T &ORecordList<T>::Iterator::operator*() { 91T &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
95template <class T = OPimRecord> 100template <class T>
96ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { 101ORecordListIterator<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}
105template <class T = OPimRecord> 110template <class T>
106ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { 111ORecordListIterator<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
116template <class T = OPimRecord> 121template <class T>
117bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) { 122bool 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}
128template <class T = ORecordList> 133template <class T>
129bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) { 134bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) {
130 return !(*this == it ); 135 return !(*this == it );
131} 136}
132template <class T = ORecordList> 137template <class T>
133ORecordList<T>::Iterator::Iterator( const QArray<int> uids, 138ORecordListIterator<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}
138template <class T = ORecordList> 143
144template <class T>
139ORecordList<T>::ORecordList( const QArray<int>& ids, 145ORecordList<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}
144template <class T = ORecordList> 150template <class T>
145ORecordList<T>::~ORecordList() { 151ORecordList<T>::~ORecordList() {
@@ -147,3 +153,3 @@ ORecordList<T>::~ORecordList() {
147} 153}
148template <class T = ORecordList> 154template <class T>
149ORecordList<T>::Iterator ORecordList<T>::begin() { 155ORecordList<T>::Iterator ORecordList<T>::begin() {
@@ -152,3 +158,3 @@ ORecordList<T>::Iterator ORecordList<T>::begin() {
152} 158}
153template <class T = ORecordList> 159template <class T>
154ORecordList<T>::Iterator ORecordList<T>::end() { 160ORecordList<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
6template <class T = OPimRecord>
7class OTemplateBase {
8public:
9 OTemplateBase() {
10 };
11 virtual ~OTemplateBase() {
12 }
13 virtual T find( int uid ) = 0;
14
15};
16
17
18#endif