summaryrefslogtreecommitdiff
Unidiff
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
@@ -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
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
@@ -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
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
@@ -1,53 +1,56 @@
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
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
9 setUid( uid ); 12 setUid( uid );
10} 13}
11OPimRecord::~OPimRecord() { 14OPimRecord::~OPimRecord() {
12} 15}
13OPimRecord::OPimRecord( const OPimRecord& rec ) 16OPimRecord::OPimRecord( const OPimRecord& rec )
14 : Qtopia::Record( rec ) 17 : Qtopia::Record( rec )
15{ 18{
16 (*this) = rec; 19 (*this) = rec;
17} 20}
18 21
19OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
20 Qtopia::Record::operator=( rec ); 23 Qtopia::Record::operator=( rec );
21 m_relations = rec.m_relations; 24 m_relations = rec.m_relations;
22 25
23 return *this; 26 return *this;
24} 27}
25/* 28/*
26 * category names 29 * category names
27 */ 30 */
28QStringList OPimRecord::categoryNames()const { 31QStringList OPimRecord::categoryNames()const {
29 QStringList list; 32 QStringList list;
30 QArray<int> cats = categories(); 33 QArray<int> cats = categories();
31 Categories catDB; 34 Categories catDB;
32 catDB.load( categoryFileName() ); 35 catDB.load( categoryFileName() );
33 36
34 for (uint i = 0; i < cats.count(); i++ ) { 37 for (uint i = 0; i < cats.count(); i++ ) {
35 list << catDB.label("Todo List", cats[i] ); 38 list << catDB.label("Todo List", cats[i] );
36 } 39 }
37 40
38 return list; 41 return list;
39} 42}
40void OPimRecord::setCategoryNames( const QStringList& ) { 43void OPimRecord::setCategoryNames( const QStringList& ) {
41 44
42} 45}
43void OPimRecord::addCategoryName( const QString& ) { 46void OPimRecord::addCategoryName( const QString& ) {
44 Categories catDB; 47 Categories catDB;
45 catDB.load( categoryFileName() ); 48 catDB.load( categoryFileName() );
46 49
47 50
48} 51}
49bool OPimRecord::isEmpty()const { 52bool OPimRecord::isEmpty()const {
50 return ( uid() == 0 ); 53 return ( uid() == 0 );
51} 54}
52QStringList OPimRecord::relatedApps()const{ 55QStringList OPimRecord::relatedApps()const{
53 QStringList list; 56 QStringList list;
@@ -80,48 +83,51 @@ void OPimRecord::addRelation( const QString& app, int id ) {
80 }else{ 83 }else{
81 tmp = it.data(); 84 tmp = it.data();
82 tmp.resize( tmp.size() + 1 ); 85 tmp.resize( tmp.size() + 1 );
83 tmp[tmp.size() - 1] = id; 86 tmp[tmp.size() - 1] = id;
84 } 87 }
85 m_relations.replace( app, tmp ); 88 m_relations.replace( app, tmp );
86} 89}
87void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { 90void OPimRecord::setRelations( const QString& app, QArray<int> ids ) {
88 91
89 QMap<QString, QArray<int> >::Iterator it; 92 QMap<QString, QArray<int> >::Iterator it;
90 QArray<int> tmp; 93 QArray<int> tmp;
91 94
92 it = m_relations.find( app); 95 it = m_relations.find( app);
93 if ( it == m_relations.end() ) { 96 if ( it == m_relations.end() ) {
94 tmp = ids; 97 tmp = ids;
95 }else{ 98 }else{
96 tmp = it.data(); 99 tmp = it.data();
97 int offset = tmp.size()-1; 100 int offset = tmp.size()-1;
98 tmp.resize( tmp.size() + ids.size() ); 101 tmp.resize( tmp.size() + ids.size() );
99 for (uint i = 0; i < ids.size(); i++ ) { 102 for (uint i = 0; i < ids.size(); i++ ) {
100 tmp[offset+i] = ids[i]; 103 tmp[offset+i] = ids[i];
101 } 104 }
102 105
103 } 106 }
104 m_relations.replace( app, tmp ); 107 m_relations.replace( app, tmp );
105} 108}
106QString OPimRecord::crossToString()const { 109QString OPimRecord::crossToString()const {
107 QString str; 110 QString str;
108 QMap<QString, QArray<int> >::ConstIterator it; 111 QMap<QString, QArray<int> >::ConstIterator it;
109 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 112 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
110 QArray<int> id = it.data(); 113 QArray<int> id = it.data();
111 for ( uint i = 0; i < id.size(); ++i ) { 114 for ( uint i = 0; i < id.size(); ++i ) {
112 str += it.key() + "," + QString::number( i ) + ";"; 115 str += it.key() + "," + QString::number( i ) + ";";
113 } 116 }
114 } 117 }
115 str = str.remove( str.length()-1, 1); // strip the ; 118 str = str.remove( str.length()-1, 1); // strip the ;
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 */
121void OPimRecord::setUid( int uid ) { 124void 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};
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
@@ -59,60 +59,62 @@ public:
59 59
60 /** 60 /**
61 * the name of the Record 61 * the name of the Record
62 */ 62 */
63 virtual QString type()const = 0; 63 virtual QString type()const = 0;
64 64
65 /** 65 /**
66 * converts the internal structure to a map 66 * converts the internal structure to a map
67 */ 67 */
68 virtual QMap<int, QString> toMap()const = 0; 68 virtual QMap<int, QString> toMap()const = 0;
69 69
70 /** 70 /**
71 * key value representation of extra items 71 * key value representation of extra items
72 */ 72 */
73 virtual QMap<QString, QString> toExtraMap()const = 0; 73 virtual QMap<QString, QString> toExtraMap()const = 0;
74 74
75 /** 75 /**
76 * the name for a recordField 76 * the name for a recordField
77 */ 77 */
78 virtual QString recordField(int)const = 0; 78 virtual QString recordField(int)const = 0;
79 79
80 /** 80 /**
81 * the related apps names 81 * the related apps names
82 */ 82 */
83 QStringList relatedApps()const; 83 QStringList relatedApps()const;
84 84
85 /** 85 /**
86 * the realtions between an app 86 * the realtions between an app
87 */ 87 */
88 QArray<int> relations( const QString& app )const; 88 QArray<int> relations( const QString& app )const;
89 89
90 /** 90 /**
91 * 91 *
92 */ 92 */
93 void clearRelation( const QString& app ); 93 void clearRelation( const QString& app );
94 94
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
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
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
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();
44 /* 49 /*
45 ConstIterator begin()const; 50 ConstIterator begin()const;
46 ConstIterator end()const; 51 ConstIterator end()const;
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;
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
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;
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
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;
100 }else 105 }else
101 m_end = true; 106 m_end = true;
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;
110 } else 115 } else
111 m_end = true; 116 m_end = true;
112 117
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;
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}
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;
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
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
@@ -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
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
@@ -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
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
@@ -1,53 +1,56 @@
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
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
9 setUid( uid ); 12 setUid( uid );
10} 13}
11OPimRecord::~OPimRecord() { 14OPimRecord::~OPimRecord() {
12} 15}
13OPimRecord::OPimRecord( const OPimRecord& rec ) 16OPimRecord::OPimRecord( const OPimRecord& rec )
14 : Qtopia::Record( rec ) 17 : Qtopia::Record( rec )
15{ 18{
16 (*this) = rec; 19 (*this) = rec;
17} 20}
18 21
19OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 22OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
20 Qtopia::Record::operator=( rec ); 23 Qtopia::Record::operator=( rec );
21 m_relations = rec.m_relations; 24 m_relations = rec.m_relations;
22 25
23 return *this; 26 return *this;
24} 27}
25/* 28/*
26 * category names 29 * category names
27 */ 30 */
28QStringList OPimRecord::categoryNames()const { 31QStringList OPimRecord::categoryNames()const {
29 QStringList list; 32 QStringList list;
30 QArray<int> cats = categories(); 33 QArray<int> cats = categories();
31 Categories catDB; 34 Categories catDB;
32 catDB.load( categoryFileName() ); 35 catDB.load( categoryFileName() );
33 36
34 for (uint i = 0; i < cats.count(); i++ ) { 37 for (uint i = 0; i < cats.count(); i++ ) {
35 list << catDB.label("Todo List", cats[i] ); 38 list << catDB.label("Todo List", cats[i] );
36 } 39 }
37 40
38 return list; 41 return list;
39} 42}
40void OPimRecord::setCategoryNames( const QStringList& ) { 43void OPimRecord::setCategoryNames( const QStringList& ) {
41 44
42} 45}
43void OPimRecord::addCategoryName( const QString& ) { 46void OPimRecord::addCategoryName( const QString& ) {
44 Categories catDB; 47 Categories catDB;
45 catDB.load( categoryFileName() ); 48 catDB.load( categoryFileName() );
46 49
47 50
48} 51}
49bool OPimRecord::isEmpty()const { 52bool OPimRecord::isEmpty()const {
50 return ( uid() == 0 ); 53 return ( uid() == 0 );
51} 54}
52QStringList OPimRecord::relatedApps()const{ 55QStringList OPimRecord::relatedApps()const{
53 QStringList list; 56 QStringList list;
@@ -80,48 +83,51 @@ void OPimRecord::addRelation( const QString& app, int id ) {
80 }else{ 83 }else{
81 tmp = it.data(); 84 tmp = it.data();
82 tmp.resize( tmp.size() + 1 ); 85 tmp.resize( tmp.size() + 1 );
83 tmp[tmp.size() - 1] = id; 86 tmp[tmp.size() - 1] = id;
84 } 87 }
85 m_relations.replace( app, tmp ); 88 m_relations.replace( app, tmp );
86} 89}
87void OPimRecord::setRelations( const QString& app, QArray<int> ids ) { 90void OPimRecord::setRelations( const QString& app, QArray<int> ids ) {
88 91
89 QMap<QString, QArray<int> >::Iterator it; 92 QMap<QString, QArray<int> >::Iterator it;
90 QArray<int> tmp; 93 QArray<int> tmp;
91 94
92 it = m_relations.find( app); 95 it = m_relations.find( app);
93 if ( it == m_relations.end() ) { 96 if ( it == m_relations.end() ) {
94 tmp = ids; 97 tmp = ids;
95 }else{ 98 }else{
96 tmp = it.data(); 99 tmp = it.data();
97 int offset = tmp.size()-1; 100 int offset = tmp.size()-1;
98 tmp.resize( tmp.size() + ids.size() ); 101 tmp.resize( tmp.size() + ids.size() );
99 for (uint i = 0; i < ids.size(); i++ ) { 102 for (uint i = 0; i < ids.size(); i++ ) {
100 tmp[offset+i] = ids[i]; 103 tmp[offset+i] = ids[i];
101 } 104 }
102 105
103 } 106 }
104 m_relations.replace( app, tmp ); 107 m_relations.replace( app, tmp );
105} 108}
106QString OPimRecord::crossToString()const { 109QString OPimRecord::crossToString()const {
107 QString str; 110 QString str;
108 QMap<QString, QArray<int> >::ConstIterator it; 111 QMap<QString, QArray<int> >::ConstIterator it;
109 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 112 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
110 QArray<int> id = it.data(); 113 QArray<int> id = it.data();
111 for ( uint i = 0; i < id.size(); ++i ) { 114 for ( uint i = 0; i < id.size(); ++i ) {
112 str += it.key() + "," + QString::number( i ) + ";"; 115 str += it.key() + "," + QString::number( i ) + ";";
113 } 116 }
114 } 117 }
115 str = str.remove( str.length()-1, 1); // strip the ; 118 str = str.remove( str.length()-1, 1); // strip the ;
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 */
121void OPimRecord::setUid( int uid ) { 124void 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};
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
@@ -59,60 +59,62 @@ public:
59 59
60 /** 60 /**
61 * the name of the Record 61 * the name of the Record
62 */ 62 */
63 virtual QString type()const = 0; 63 virtual QString type()const = 0;
64 64
65 /** 65 /**
66 * converts the internal structure to a map 66 * converts the internal structure to a map
67 */ 67 */
68 virtual QMap<int, QString> toMap()const = 0; 68 virtual QMap<int, QString> toMap()const = 0;
69 69
70 /** 70 /**
71 * key value representation of extra items 71 * key value representation of extra items
72 */ 72 */
73 virtual QMap<QString, QString> toExtraMap()const = 0; 73 virtual QMap<QString, QString> toExtraMap()const = 0;
74 74
75 /** 75 /**
76 * the name for a recordField 76 * the name for a recordField
77 */ 77 */
78 virtual QString recordField(int)const = 0; 78 virtual QString recordField(int)const = 0;
79 79
80 /** 80 /**
81 * the related apps names 81 * the related apps names
82 */ 82 */
83 QStringList relatedApps()const; 83 QStringList relatedApps()const;
84 84
85 /** 85 /**
86 * the realtions between an app 86 * the realtions between an app
87 */ 87 */
88 QArray<int> relations( const QString& app )const; 88 QArray<int> relations( const QString& app )const;
89 89
90 /** 90 /**
91 * 91 *
92 */ 92 */
93 void clearRelation( const QString& app ); 93 void clearRelation( const QString& app );
94 94
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
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
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
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
@@ -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
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();
44 /* 49 /*
45 ConstIterator begin()const; 50 ConstIterator begin()const;
46 ConstIterator end()const; 51 ConstIterator end()const;
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;
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
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;
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
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;
100 }else 105 }else
101 m_end = true; 106 m_end = true;
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;
110 } else 115 } else
111 m_end = true; 116 m_end = true;
112 117
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;
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}
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;
157 it.m_current = m_ids.count(); 163 it.m_current = m_ids.count();
158} 164}
159#endif 165#endif