author | zecke <zecke> | 2002-09-22 16:40:04 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-22 16:40:04 (UTC) |
commit | 2c398e382bf015eb4cf7302e5d79ed63f476be3a (patch) (unidiff) | |
tree | eb446c641471a39d08159e058038cc1eb0d9d5b3 | |
parent | c15b90cb32a27ece63620be60f96959f2ee6f492 (diff) | |
download | opie-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
-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 | ||||
-rw-r--r-- | libopie2/opiepim/backend/opimaccessbackend.h | 19 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 144 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimrecord.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/core/otemplatebase.h | 18 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 124 |
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 | |||
@@ -1,29 +1,36 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_BACKEND | 1 | #ifndef OPIE_PIM_ACCESS_BACKEND |
2 | #define OPIE_PIM_ACCESS_BACKEND | 2 | #define OPIE_PIM_ACCESS_BACKEND |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | 7 | ||
8 | template <class T = OPimRecord> | 8 | template <class T = OPimRecord> |
9 | class OPimAccessBackend { | 9 | 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; |
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 | ||
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 | |||
@@ -1,82 +1,118 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
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 |
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 | |||
@@ -1,17 +1,20 @@ | |||
1 | #include <qpe/categories.h> | 1 | #include <qpe/categories.h> |
2 | #include <qpe/categoryselect.h> | 2 | #include <qpe/categoryselect.h> |
3 | 3 | ||
4 | #include "opimrecord.h" | 4 | #include "opimrecord.h" |
5 | 5 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | ||
7 | |||
8 | |||
6 | OPimRecord::OPimRecord( int uid ) | 9 | OPimRecord::OPimRecord( int uid ) |
7 | : Qtopia::Record() { | 10 | : Qtopia::Record() { |
8 | 11 | ||
9 | setUid( uid ); | 12 | setUid( uid ); |
10 | } | 13 | } |
11 | OPimRecord::~OPimRecord() { | 14 | OPimRecord::~OPimRecord() { |
12 | } | 15 | } |
13 | OPimRecord::OPimRecord( const OPimRecord& rec ) | 16 | OPimRecord::OPimRecord( const OPimRecord& rec ) |
14 | : Qtopia::Record( rec ) | 17 | : Qtopia::Record( rec ) |
15 | { | 18 | { |
16 | (*this) = rec; | 19 | (*this) = rec; |
17 | } | 20 | } |
@@ -116,12 +119,15 @@ QString OPimRecord::crossToString()const { | |||
116 | //qWarning("IDS " + str ); | 119 | //qWarning("IDS " + str ); |
117 | 120 | ||
118 | return str; | 121 | return str; |
119 | } | 122 | } |
120 | /* if uid = 1 assign a new one */ | 123 | /* if uid = 1 assign a new one */ |
121 | void OPimRecord::setUid( int uid ) { | 124 | void OPimRecord::setUid( int uid ) { |
122 | 125 | ||
123 | if ( uid == 1) | 126 | if ( uid == 1) |
124 | uid = uidGen().generate(); | 127 | uid = uidGen().generate(); |
125 | 128 | ||
126 | Qtopia::Record::setUid( uid ); | 129 | Qtopia::Record::setUid( 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 | |||
@@ -95,24 +95,26 @@ public: | |||
95 | /** | 95 | /** |
96 | * | 96 | * |
97 | */ | 97 | */ |
98 | void addRelation( const QString& app, int id ); | 98 | void addRelation( const QString& app, int id ); |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * | 101 | * |
102 | */ | 102 | */ |
103 | void setRelations( const QString&, QArray<int> ids ); | 103 | void setRelations( const QString&, QArray<int> ids ); |
104 | virtual void setUid( int uid ); | 104 | virtual void setUid( int uid ); |
105 | 105 | ||
106 | protected: | 106 | protected: |
107 | Qtopia::UidGen &uidGen(); | ||
107 | QString crossToString()const; | 108 | QString crossToString()const; |
108 | 109 | ||
109 | private: | 110 | private: |
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 | ||
116 | 118 | ||
117 | 119 | ||
118 | #endif | 120 | #endif |
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 | |||
@@ -1,159 +1,165 @@ | |||
1 | 1 | ||
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 | |||
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 | ||
8 | template <class T = OPimRecord > | 39 | template <class T = OPimRecord > |
9 | class ORecordList { | 40 | 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(); |
42 | Iterator begin(); | 47 | Iterator begin(); |
43 | Iterator end(); | 48 | Iterator end(); |
44 | /* | 49 | /* |
45 | ConstIterator begin()const; | 50 | ConstIterator begin()const; |
46 | ConstIterator end()const; | 51 | ConstIterator end()const; |
47 | */ | 52 | */ |
48 | private: | 53 | private: |
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 */ |
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; |
57 | m_temp = 0l; | 62 | m_temp = 0l; |
58 | m_end = true; | 63 | m_end = true; |
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 */ |
63 | } | 68 | } |
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; |
68 | m_current = it.m_current; | 73 | m_current = it.m_current; |
69 | m_temp = it.m_temp; | 74 | m_temp = it.m_temp; |
70 | m_end = it.m_end; | 75 | m_end = it.m_end; |
71 | m_record = it.m_record; | 76 | m_record = it.m_record; |
72 | } | 77 | } |
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; |
77 | m_current = it.m_current; | 82 | m_current = it.m_current; |
78 | m_temp = it.m_temp; | 83 | m_temp = it.m_temp; |
79 | m_end = it.m_end; | 84 | m_end = it.m_end; |
80 | m_record = it.m_record; | 85 | m_record = it.m_record; |
81 | 86 | ||
82 | return *this; | 87 | return *this; |
83 | } | 88 | } |
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 ) |
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 | ||
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() ) { |
98 | m_end = false; | 103 | m_end = false; |
99 | ++m_current; | 104 | ++m_current; |
100 | }else | 105 | }else |
101 | m_end = true; | 106 | m_end = true; |
102 | 107 | ||
103 | return *this; | 108 | return *this; |
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 ) { |
108 | --m_current; | 113 | --m_current; |
109 | m_end = false; | 114 | m_end = false; |
110 | } else | 115 | } else |
111 | m_end = true; | 116 | m_end = true; |
112 | 117 | ||
113 | return *this; | 118 | return *this; |
114 | } | 119 | } |
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 | ||
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; |
121 | 126 | ||
122 | if ( m_uids != it.m_uids ) return false; | 127 | if ( m_uids != it.m_uids ) return false; |
123 | if ( m_current != it.m_current ) return false; | 128 | if ( m_current != it.m_current ) return false; |
124 | if ( m_temp != it.m_temp ) return false; | 129 | if ( m_temp != it.m_temp ) return false; |
125 | 130 | ||
126 | return true; | 131 | return true; |
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 ) |
136 | { | 141 | { |
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 ) |
142 | { | 148 | { |
143 | } | 149 | } |
144 | template <class T = ORecordList> | 150 | template <class T> |
145 | ORecordList<T>::~ORecordList() { | 151 | ORecordList<T>::~ORecordList() { |
146 | /* nothing to do here */ | 152 | /* nothing to do here */ |
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() { |
150 | Iterator it( m_ids, m_acc ); | 156 | Iterator it( m_ids, m_acc ); |
151 | return it; | 157 | return it; |
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() { |
155 | Iterator it( m_ids, m_acc ); | 161 | Iterator it( m_ids, m_acc ); |
156 | it.m_end = true; | 162 | it.m_end = true; |
157 | it.m_current = m_ids.count(); | 163 | it.m_current = m_ids.count(); |
158 | } | 164 | } |
159 | #endif | 165 | #endif |
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 | ||
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 | |||
@@ -1,29 +1,36 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_BACKEND | 1 | #ifndef OPIE_PIM_ACCESS_BACKEND |
2 | #define OPIE_PIM_ACCESS_BACKEND | 2 | #define OPIE_PIM_ACCESS_BACKEND |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | 7 | ||
8 | template <class T = OPimRecord> | 8 | template <class T = OPimRecord> |
9 | class OPimAccessBackend { | 9 | 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; |
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 | ||
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/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 | |||
@@ -1,82 +1,118 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
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 |
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 | |||
@@ -1,17 +1,20 @@ | |||
1 | #include <qpe/categories.h> | 1 | #include <qpe/categories.h> |
2 | #include <qpe/categoryselect.h> | 2 | #include <qpe/categoryselect.h> |
3 | 3 | ||
4 | #include "opimrecord.h" | 4 | #include "opimrecord.h" |
5 | 5 | ||
6 | Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); | ||
7 | |||
8 | |||
6 | OPimRecord::OPimRecord( int uid ) | 9 | OPimRecord::OPimRecord( int uid ) |
7 | : Qtopia::Record() { | 10 | : Qtopia::Record() { |
8 | 11 | ||
9 | setUid( uid ); | 12 | setUid( uid ); |
10 | } | 13 | } |
11 | OPimRecord::~OPimRecord() { | 14 | OPimRecord::~OPimRecord() { |
12 | } | 15 | } |
13 | OPimRecord::OPimRecord( const OPimRecord& rec ) | 16 | OPimRecord::OPimRecord( const OPimRecord& rec ) |
14 | : Qtopia::Record( rec ) | 17 | : Qtopia::Record( rec ) |
15 | { | 18 | { |
16 | (*this) = rec; | 19 | (*this) = rec; |
17 | } | 20 | } |
@@ -116,12 +119,15 @@ QString OPimRecord::crossToString()const { | |||
116 | //qWarning("IDS " + str ); | 119 | //qWarning("IDS " + str ); |
117 | 120 | ||
118 | return str; | 121 | return str; |
119 | } | 122 | } |
120 | /* if uid = 1 assign a new one */ | 123 | /* if uid = 1 assign a new one */ |
121 | void OPimRecord::setUid( int uid ) { | 124 | void OPimRecord::setUid( int uid ) { |
122 | 125 | ||
123 | if ( uid == 1) | 126 | if ( uid == 1) |
124 | uid = uidGen().generate(); | 127 | uid = uidGen().generate(); |
125 | 128 | ||
126 | Qtopia::Record::setUid( uid ); | 129 | Qtopia::Record::setUid( uid ); |
127 | }; | 130 | }; |
131 | Qtopia::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 | |||
@@ -95,24 +95,26 @@ public: | |||
95 | /** | 95 | /** |
96 | * | 96 | * |
97 | */ | 97 | */ |
98 | void addRelation( const QString& app, int id ); | 98 | void addRelation( const QString& app, int id ); |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * | 101 | * |
102 | */ | 102 | */ |
103 | void setRelations( const QString&, QArray<int> ids ); | 103 | void setRelations( const QString&, QArray<int> ids ); |
104 | virtual void setUid( int uid ); | 104 | virtual void setUid( int uid ); |
105 | 105 | ||
106 | protected: | 106 | protected: |
107 | Qtopia::UidGen &uidGen(); | ||
107 | QString crossToString()const; | 108 | QString crossToString()const; |
108 | 109 | ||
109 | private: | 110 | private: |
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 | ||
116 | 118 | ||
117 | 119 | ||
118 | #endif | 120 | #endif |
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 | |||
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 | ||
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 | |||
@@ -1,159 +1,165 @@ | |||
1 | 1 | ||
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 | |||
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 | ||
8 | template <class T = OPimRecord > | 39 | template <class T = OPimRecord > |
9 | class ORecordList { | 40 | 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(); |
42 | Iterator begin(); | 47 | Iterator begin(); |
43 | Iterator end(); | 48 | Iterator end(); |
44 | /* | 49 | /* |
45 | ConstIterator begin()const; | 50 | ConstIterator begin()const; |
46 | ConstIterator end()const; | 51 | ConstIterator end()const; |
47 | */ | 52 | */ |
48 | private: | 53 | private: |
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 */ |
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; |
57 | m_temp = 0l; | 62 | m_temp = 0l; |
58 | m_end = true; | 63 | m_end = true; |
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 */ |
63 | } | 68 | } |
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; |
68 | m_current = it.m_current; | 73 | m_current = it.m_current; |
69 | m_temp = it.m_temp; | 74 | m_temp = it.m_temp; |
70 | m_end = it.m_end; | 75 | m_end = it.m_end; |
71 | m_record = it.m_record; | 76 | m_record = it.m_record; |
72 | } | 77 | } |
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; |
77 | m_current = it.m_current; | 82 | m_current = it.m_current; |
78 | m_temp = it.m_temp; | 83 | m_temp = it.m_temp; |
79 | m_end = it.m_end; | 84 | m_end = it.m_end; |
80 | m_record = it.m_record; | 85 | m_record = it.m_record; |
81 | 86 | ||
82 | return *this; | 87 | return *this; |
83 | } | 88 | } |
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 ) |
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 | ||
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() ) { |
98 | m_end = false; | 103 | m_end = false; |
99 | ++m_current; | 104 | ++m_current; |
100 | }else | 105 | }else |
101 | m_end = true; | 106 | m_end = true; |
102 | 107 | ||
103 | return *this; | 108 | return *this; |
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 ) { |
108 | --m_current; | 113 | --m_current; |
109 | m_end = false; | 114 | m_end = false; |
110 | } else | 115 | } else |
111 | m_end = true; | 116 | m_end = true; |
112 | 117 | ||
113 | return *this; | 118 | return *this; |
114 | } | 119 | } |
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 | ||
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; |
121 | 126 | ||
122 | if ( m_uids != it.m_uids ) return false; | 127 | if ( m_uids != it.m_uids ) return false; |
123 | if ( m_current != it.m_current ) return false; | 128 | if ( m_current != it.m_current ) return false; |
124 | if ( m_temp != it.m_temp ) return false; | 129 | if ( m_temp != it.m_temp ) return false; |
125 | 130 | ||
126 | return true; | 131 | return true; |
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 ) |
136 | { | 141 | { |
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 ) |
142 | { | 148 | { |
143 | } | 149 | } |
144 | template <class T = ORecordList> | 150 | template <class T> |
145 | ORecordList<T>::~ORecordList() { | 151 | ORecordList<T>::~ORecordList() { |
146 | /* nothing to do here */ | 152 | /* nothing to do here */ |
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() { |
150 | Iterator it( m_ids, m_acc ); | 156 | Iterator it( m_ids, m_acc ); |
151 | return it; | 157 | return it; |
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() { |
155 | Iterator it( m_ids, m_acc ); | 161 | Iterator it( m_ids, m_acc ); |
156 | it.m_end = true; | 162 | it.m_end = true; |
157 | it.m_current = m_ids.count(); | 163 | it.m_current = m_ids.count(); |
158 | } | 164 | } |
159 | #endif | 165 | #endif |