summaryrefslogtreecommitdiff
authorzecke <zecke>2002-09-22 16:40:04 (UTC)
committer zecke <zecke>2002-09-22 16:40:04 (UTC)
commit2c398e382bf015eb4cf7302e5d79ed63f476be3a (patch) (unidiff)
treeeb446c641471a39d08159e058038cc1eb0d9d5b3
parentc15b90cb32a27ece63620be60f96959f2ee6f492 (diff)
downloadopie-2c398e382bf015eb4cf7302e5d79ed63f476be3a.zip
opie-2c398e382bf015eb4cf7302e5d79ed63f476be3a.tar.gz
opie-2c398e382bf015eb4cf7302e5d79ed63f476be3a.tar.bz2
Ok now it compiles again... heureka
I had to create templatebase so orecordlist and opimaccesstemplate do not have circular dependency otherwise just compile fixes to my templaes and i did not make them inline
Diffstat (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
-rw-r--r--libopie2/opiepim/backend/opimaccessbackend.h19
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h144
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp6
-rw-r--r--libopie2/opiepim/core/opimrecord.h2
-rw-r--r--libopie2/opiepim/core/otemplatebase.h18
-rw-r--r--libopie2/opiepim/orecordlist.h124
12 files changed, 388 insertions, 238 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
@@ -8,22 +8,29 @@
8template <class T = OPimRecord> 8template <class T = OPimRecord>
9class OPimAccessBackend { 9class OPimAccessBackend {
10public: 10public:
11 OPimAccessBackend() { 11 OPimAccessBackend();
12 } 12 virtual ~OPimAccessBackend();
13 ~OPimAccessBackend() {
14 }
15 virtual void load() = 0; 13 virtual void load() = 0;
16 virtual void reload() = 0; 14 virtual void reload() = 0;
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;
20 virtual T find(int uid ) = 0; 18 virtual T find(int uid ) = 0;
21 virtual void clear() = 0; 19 virtual void clear() = 0;
22 virtual bool add( const T& t ) = 0; 20 virtual bool add( const T& t ) = 0;
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
26 24
27}; 25};
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
@@ -7,76 +7,112 @@
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
10template <class T = OPimRecord > 12template <class T = OPimRecord >
11class OPimAccessTemplate { 13class OPimAccessTemplate : public OTemplateBase<T> {
12public: 14public:
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 }
74protected: 39protected:
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
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
@@ -3,6 +3,9 @@
3 3
4#include "opimrecord.h" 4#include "opimrecord.h"
5 5
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7
8
6OPimRecord::OPimRecord( int uid ) 9OPimRecord::OPimRecord( int uid )
7 : Qtopia::Record() { 10 : Qtopia::Record() {
8 11
@@ -125,3 +128,6 @@ void OPimRecord::setUid( int uid ) {
125 128
126 Qtopia::Record::setUid( uid ); 129 Qtopia::Record::setUid( 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
@@ -104,12 +104,14 @@ public:
104 virtual void setUid( int uid ); 104 virtual void setUid( int uid );
105 105
106protected: 106protected:
107 Qtopia::UidGen &uidGen();
107 QString crossToString()const; 108 QString crossToString()const;
108 109
109private: 110private:
110 class OPimRecordPrivate; 111 class OPimRecordPrivate;
111 OPimRecordPrivate *d; 112 OPimRecordPrivate *d;
112 QMap<QString, QArray<int> > m_relations; 113 QMap<QString, QArray<int> > m_relations;
114 static Qtopia::UidGen m_uidGen;
113 115
114}; 116};
115 117
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
@@ -2,42 +2,47 @@
2#ifndef OPIE_RECORD_LIST_H 2#ifndef OPIE_RECORD_LIST_H
3#define OPIE_RECORD_LIST_H 3#define OPIE_RECORD_LIST_H
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
8template <class T = OPimRecord > 39template <class T = OPimRecord >
9class ORecordList { 40class 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();
42 Iterator begin(); 47 Iterator begin();
43 Iterator end(); 48 Iterator end();
@@ -47,23 +52,23 @@ public:
47 */ 52 */
48private: 53private:
49 QArray<int> m_ids; 54 QArray<int> m_ids;
50 OPimAccessTemplate<T>* m_acc; 55 const Base* m_acc;
51}; 56};
52 57
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;
57 m_temp = 0l; 62 m_temp = 0l;
58 m_end = true; 63 m_end = true;
59} 64}
60template <class T= OPimRecord> 65template <class T>
61ORecordList<T>::Iterator::~Iterator() { 66ORecordListIterator<T>::~ORecordListIterator() {
62/* nothing to delete */ 67/* nothing to delete */
63} 68}
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;
68 m_current = it.m_current; 73 m_current = it.m_current;
69 m_temp = it.m_temp; 74 m_temp = it.m_temp;
@@ -71,8 +76,8 @@ ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
71 m_record = it.m_record; 76 m_record = it.m_record;
72} 77}
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;
77 m_current = it.m_current; 82 m_current = it.m_current;
78 m_temp = it.m_temp; 83 m_temp = it.m_temp;
@@ -82,18 +87,18 @@ ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>
82 return *this; 87 return *this;
83} 88}
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 )
88 m_record = m_temp->find( m_uids[m_current] ); 93 m_record = m_temp->find( m_uids[m_current] );
89 else 94 else
90 m_record = T; 95 m_record = T();
91 96
92 return m_record; 97 return m_record;
93} 98}
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() ) {
98 m_end = false; 103 m_end = false;
99 ++m_current; 104 ++m_current;
@@ -102,8 +107,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
102 107
103 return *this; 108 return *this;
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 ) {
108 --m_current; 113 --m_current;
109 m_end = false; 114 m_end = false;
@@ -113,8 +118,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
113 return *this; 118 return *this;
114} 119}
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
119 /* if both are at we're the same.... */ 124 /* if both are at we're the same.... */
120 if ( m_end == it.m_end ) return true; 125 if ( m_end == it.m_end ) return true;
@@ -125,32 +130,33 @@ bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it )
125 130
126 return true; 131 return true;
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 )
136{ 141{
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 )
142{ 148{
143} 149}
144template <class T = ORecordList> 150template <class T>
145ORecordList<T>::~ORecordList() { 151ORecordList<T>::~ORecordList() {
146/* nothing to do here */ 152/* nothing to do here */
147} 153}
148template <class T = ORecordList> 154template <class T>
149ORecordList<T>::Iterator ORecordList<T>::begin() { 155ORecordList<T>::Iterator ORecordList<T>::begin() {
150 Iterator it( m_ids, m_acc ); 156 Iterator it( m_ids, m_acc );
151 return it; 157 return it;
152} 158}
153template <class T = ORecordList> 159template <class T>
154ORecordList<T>::Iterator ORecordList<T>::end() { 160ORecordList<T>::Iterator ORecordList<T>::end() {
155 Iterator it( m_ids, m_acc ); 161 Iterator it( m_ids, m_acc );
156 it.m_end = true; 162 it.m_end = true;
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
diff --git a/libopie2/opiepim/backend/opimaccessbackend.h b/libopie2/opiepim/backend/opimaccessbackend.h
index d9af589..8e744e7 100644
--- a/libopie2/opiepim/backend/opimaccessbackend.h
+++ b/libopie2/opiepim/backend/opimaccessbackend.h
@@ -8,22 +8,29 @@
8template <class T = OPimRecord> 8template <class T = OPimRecord>
9class OPimAccessBackend { 9class OPimAccessBackend {
10public: 10public:
11 OPimAccessBackend() { 11 OPimAccessBackend();
12 } 12 virtual ~OPimAccessBackend();
13 ~OPimAccessBackend() {
14 }
15 virtual void load() = 0; 13 virtual void load() = 0;
16 virtual void reload() = 0; 14 virtual void reload() = 0;
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;
20 virtual T find(int uid ) = 0; 18 virtual T find(int uid ) = 0;
21 virtual void clear() = 0; 19 virtual void clear() = 0;
22 virtual bool add( const T& t ) = 0; 20 virtual bool add( const T& t ) = 0;
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
26 24
27}; 25};
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/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f2a241d..e0708e1 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -7,76 +7,112 @@
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
10template <class T = OPimRecord > 12template <class T = OPimRecord >
11class OPimAccessTemplate { 13class OPimAccessTemplate : public OTemplateBase<T> {
12public: 14public:
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 }
74protected: 39protected:
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
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/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 88b6fde..60cdbf3 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -3,6 +3,9 @@
3 3
4#include "opimrecord.h" 4#include "opimrecord.h"
5 5
6Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
7
8
6OPimRecord::OPimRecord( int uid ) 9OPimRecord::OPimRecord( int uid )
7 : Qtopia::Record() { 10 : Qtopia::Record() {
8 11
@@ -125,3 +128,6 @@ void OPimRecord::setUid( int uid ) {
125 128
126 Qtopia::Record::setUid( uid ); 129 Qtopia::Record::setUid( uid );
127}; 130};
131Qtopia::UidGen &OPimRecord::uidGen() {
132 return m_uidGen;
133}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 297ff12..e4d33d6 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -104,12 +104,14 @@ public:
104 virtual void setUid( int uid ); 104 virtual void setUid( int uid );
105 105
106protected: 106protected:
107 Qtopia::UidGen &uidGen();
107 QString crossToString()const; 108 QString crossToString()const;
108 109
109private: 110private:
110 class OPimRecordPrivate; 111 class OPimRecordPrivate;
111 OPimRecordPrivate *d; 112 OPimRecordPrivate *d;
112 QMap<QString, QArray<int> > m_relations; 113 QMap<QString, QArray<int> > m_relations;
114 static Qtopia::UidGen m_uidGen;
113 115
114}; 116};
115 117
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h
new file mode 100644
index 0000000..41cc934
--- a/dev/null
+++ b/libopie2/opiepim/core/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
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h
index 65c2169..a3955b0 100644
--- a/libopie2/opiepim/orecordlist.h
+++ b/libopie2/opiepim/orecordlist.h
@@ -2,42 +2,47 @@
2#ifndef OPIE_RECORD_LIST_H 2#ifndef OPIE_RECORD_LIST_H
3#define OPIE_RECORD_LIST_H 3#define OPIE_RECORD_LIST_H
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
8template <class T = OPimRecord > 39template <class T = OPimRecord >
9class ORecordList { 40class 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();
42 Iterator begin(); 47 Iterator begin();
43 Iterator end(); 48 Iterator end();
@@ -47,23 +52,23 @@ public:
47 */ 52 */
48private: 53private:
49 QArray<int> m_ids; 54 QArray<int> m_ids;
50 OPimAccessTemplate<T>* m_acc; 55 const Base* m_acc;
51}; 56};
52 57
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;
57 m_temp = 0l; 62 m_temp = 0l;
58 m_end = true; 63 m_end = true;
59} 64}
60template <class T= OPimRecord> 65template <class T>
61ORecordList<T>::Iterator::~Iterator() { 66ORecordListIterator<T>::~ORecordListIterator() {
62/* nothing to delete */ 67/* nothing to delete */
63} 68}
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;
68 m_current = it.m_current; 73 m_current = it.m_current;
69 m_temp = it.m_temp; 74 m_temp = it.m_temp;
@@ -71,8 +76,8 @@ ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) {
71 m_record = it.m_record; 76 m_record = it.m_record;
72} 77}
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;
77 m_current = it.m_current; 82 m_current = it.m_current;
78 m_temp = it.m_temp; 83 m_temp = it.m_temp;
@@ -82,18 +87,18 @@ ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>
82 return *this; 87 return *this;
83} 88}
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 )
88 m_record = m_temp->find( m_uids[m_current] ); 93 m_record = m_temp->find( m_uids[m_current] );
89 else 94 else
90 m_record = T; 95 m_record = T();
91 96
92 return m_record; 97 return m_record;
93} 98}
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() ) {
98 m_end = false; 103 m_end = false;
99 ++m_current; 104 ++m_current;
@@ -102,8 +107,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() {
102 107
103 return *this; 108 return *this;
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 ) {
108 --m_current; 113 --m_current;
109 m_end = false; 114 m_end = false;
@@ -113,8 +118,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() {
113 return *this; 118 return *this;
114} 119}
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
119 /* if both are at we're the same.... */ 124 /* if both are at we're the same.... */
120 if ( m_end == it.m_end ) return true; 125 if ( m_end == it.m_end ) return true;
@@ -125,32 +130,33 @@ bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it )
125 130
126 return true; 131 return true;
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 )
136{ 141{
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 )
142{ 148{
143} 149}
144template <class T = ORecordList> 150template <class T>
145ORecordList<T>::~ORecordList() { 151ORecordList<T>::~ORecordList() {
146/* nothing to do here */ 152/* nothing to do here */
147} 153}
148template <class T = ORecordList> 154template <class T>
149ORecordList<T>::Iterator ORecordList<T>::begin() { 155ORecordList<T>::Iterator ORecordList<T>::begin() {
150 Iterator it( m_ids, m_acc ); 156 Iterator it( m_ids, m_acc );
151 return it; 157 return it;
152} 158}
153template <class T = ORecordList> 159template <class T>
154ORecordList<T>::Iterator ORecordList<T>::end() { 160ORecordList<T>::Iterator ORecordList<T>::end() {
155 Iterator it( m_ids, m_acc ); 161 Iterator it( m_ids, m_acc );
156 it.m_end = true; 162 it.m_end = true;