author | zecke <zecke> | 2002-09-22 16:40:04 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-22 16:40:04 (UTC) |
commit | 2c398e382bf015eb4cf7302e5d79ed63f476be3a (patch) (side-by-side diff) | |
tree | eb446c641471a39d08159e058038cc1eb0d9d5b3 /libopie | |
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 | 106 | ||||
-rw-r--r-- | libopie/pim/opimrecord.cpp | 6 | ||||
-rw-r--r-- | libopie/pim/opimrecord.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 100 | ||||
-rw-r--r-- | libopie/pim/otemplatebase.h | 18 |
6 files changed, 163 insertions, 88 deletions
diff --git a/libopie/pim/opimaccessbackend.h b/libopie/pim/opimaccessbackend.h index d9af589..8e744e7 100644 --- a/libopie/pim/opimaccessbackend.h +++ b/libopie/pim/opimaccessbackend.h @@ -10,6 +10,4 @@ class OPimAccessBackend { public: - OPimAccessBackend() { - } - ~OPimAccessBackend() { - } + OPimAccessBackend(); + virtual ~OPimAccessBackend(); virtual void load() = 0; @@ -17,3 +15,3 @@ public: virtual void save() = 0; - virtual QArray<int> allRecords() = 0; + virtual QArray<int> allRecords()const = 0; virtual QArray<int> queryByExample( const T& t, int sort ) = 0; @@ -23,3 +21,3 @@ public: virtual bool remove( int uid ) = 0; - virtual void replace( const T& t ) = 0; + virtual bool replace( const T& t ) = 0; @@ -28,2 +26,11 @@ public: +template <class T> +OPimAccessBackend<T>::OPimAccessBackend() { + +} +template <class T> +OPimAccessBackend<T>::~OPimAccessBackend() { + +} + #endif diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index f2a241d..e0708e1 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h @@ -9,4 +9,6 @@ +#include "otemplatebase.h" + template <class T = OPimRecord > -class OPimAccessTemplate { +class OPimAccessTemplate : public OTemplateBase<T> { public: @@ -14,25 +16,57 @@ public: typedef OPimAccessBackend<T> BackEnd; - OPimAccessTemplate( BackEnd* end) - : m_backEnd( end ) { + OPimAccessTemplate( BackEnd* end); + virtual ~OPimAccessTemplate(); + virtual void load(); + virtual void reload(); + virtual void save(); + + /* + *do array to Records conversion + * QArray<int> ids + */ + virtual List allRecords()const; + virtual List queryByExample( const T& t, int sortOrder ); + virtual T find( int uid ); + + /* invalidate cache here */ + virtual void clear() ; + virtual bool add( const T& t ) ; + + /* only the uid matters */ + virtual bool remove( const T& t ); + virtual bool remove( int uid ); + virtual bool replace( const T& t) ; +protected: + void invalidateCache(); + BackEnd* backEnd(); + BackEnd* m_backEnd; + +}; + +template <class T> +OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) + : OTemplateBase<T>(), m_backEnd( end ) +{ + } - ~OPimAccessTemplate() { +template <class T> +OPimAccessTemplate<T>::~OPimAccessTemplate() { + qWarning("~OPimAccessTemplate<T>"); delete m_backEnd; } - virtual void load() { +template <class T> +void OPimAccessTemplate<T>::load() { m_backEnd->load(); } - virtual void reload() { +template <class T> +void OPimAccessTemplate<T>::reload() { m_backEnd->reload(); } - virtual void save() { +template <class T> +void OPimAccessTemplate<T>::save() { m_backEnd->save(); } - - /* - *do array to Records conversion - * QArray<int> ids - */ - virtual List allRecords()const { +template <class T> +OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { QArray<int> ints = m_backEnd->allRecords(); - List lis( ints, this ); @@ -40,10 +74,12 @@ public: } - virtual List queryByExample( const T& t, int sortOrder ) { - QArray<int> ints = m_backEnd->query( t, sortOrder ); - List lis( ints, this ); +template <class T> +OPimAccessTemplate<T>::List +OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { + QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); + List lis(ints, this ); return lis; } - /* implement QCache here */ - virtual T find( int uid ) { +template <class T> +T OPimAccessTemplate<T>::find( int uid ) { T t = m_backEnd->find( uid ); @@ -51,5 +87,4 @@ public: } - - /* invalidate cache here */ - virtual void clear() { +template <class T> +void OPimAccessTemplate<T>::clear() { invalidateCache(); @@ -57,25 +92,26 @@ public: } - virtual bool add( const T& t ) { +template <class T> +bool OPimAccessTemplate<T>::add( const T& t ) { return m_backEnd->add( t ); } - - /* only the uid matters */ - virtual bool remove( const T& t ) { - /* remove from cache */ +template <class T> +bool OPimAccessTemplate<T>::remove( const T& t ) { return m_backEnd->remove( t.uid() ); } - virtual bool remove( int uid ) { - /* remove from cache */ +template <class T> +bool OPimAccessTemplate<T>::remove( int uid ) { return m_backEnd->remove(uid); } - virtual bool replace( const T& t) { +template <class T> +bool OPimAccessTemplate<T>::replace( const T& t ) { return m_backEnd->replace( t ); } -protected: - void invalidateCache() { +template <class T> +void OPimAccessTemplate<T>::invalidateCache() { } - BackEnd* m_backEnd; - -}; +template <class T> +OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { + return m_backEnd; +} diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index 88b6fde..60cdbf3 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp @@ -5,2 +5,5 @@ +Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); + + OPimRecord::OPimRecord( int uid ) @@ -127 +130,4 @@ void OPimRecord::setUid( int uid ) { }; +Qtopia::UidGen &OPimRecord::uidGen() { + return m_uidGen; +} diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index 297ff12..e4d33d6 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h @@ -106,2 +106,3 @@ public: protected: + Qtopia::UidGen &uidGen(); QString crossToString()const; @@ -112,2 +113,3 @@ private: QMap<QString, QArray<int> > m_relations; + static Qtopia::UidGen m_uidGen; diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 65c2169..a3955b0 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -4,29 +4,28 @@ -#include <opie/opimaccesstemplate.h> -#include <opie/opimrecord.h> +#include <qarray.h> + +#include "otemplatebase.h" +#include "opimrecord.h" + template <class T = OPimRecord > -class ORecordList { +class ORecordListIterator { public: - class Iterator { - friend class ORecordList; - public: - Iterator(); - ~Iterator(); - Iterator(const Iterator& ); - Iterator &operator=(const Iterator& ); + typedef OTemplateBase<T> Base; + ORecordListIterator( const QArray<int>, const Base* ); + ORecordListIterator(); + ~ORecordListIterator(); + ORecordListIterator( const ORecordListIterator& ); + ORecordListIterator &operator=(const ORecordListIterator& ); T &operator*(); - Iterator &operator++(); - Iterator &operator--(); + ORecordListIterator &operator++(); + ORecordListIterator &operator--(); - bool operator==( const Iterator& it ); - bool operator!=( const Iterator& it ); + bool operator==( const ORecordListIterator& it ); + bool operator!=( const ORecordListIterator& it ); private: - Iterator( const QArray<int>, - OPimAccessTemplate<T>* ); - QArray<int> m_uids; int m_current; - OPimAccessTemplate* m_temp; + const Base* m_temp; bool m_end : 1; @@ -38,4 +37,10 @@ public: }; + +template <class T = OPimRecord > +class ORecordList { +public: + typedef OTemplateBase<T> Base; + typedef ORecordListIterator<T> Iterator; ORecordList( const QArray<int>& ids, - OPimAccessTemplate<T>* acc ); + const Base* ); ~ORecordList(); @@ -49,3 +54,3 @@ private: QArray<int> m_ids; - OPimAccessTemplate<T>* m_acc; + const Base* m_acc; }; @@ -53,4 +58,4 @@ private: /* ok now implement it */ -template <class T= OPimRecord> -ORecordList<T>::Iterator::Iterator() { +template <class T> +ORecordListIterator<T>::ORecordListIterator() { m_current = 0; @@ -59,4 +64,4 @@ ORecordList<T>::Iterator::Iterator() { } -template <class T= OPimRecord> -ORecordList<T>::Iterator::~Iterator() { +template <class T> +ORecordListIterator<T>::~ORecordListIterator() { /* nothing to delete */ @@ -64,4 +69,4 @@ ORecordList<T>::Iterator::~Iterator() { -template <class T = OPimRecord> -ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { +template <class T> +ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { m_uids = it.m_uids; @@ -73,4 +78,4 @@ ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { m_uids = it.m_uids; @@ -84,4 +89,4 @@ ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T> -template <class T = OPimRecord> -T &ORecordList<T>::Iterator::operator*() { +template <class T> +T &ORecordListIterator<T>::operator*() { if (!m_end ) @@ -89,3 +94,3 @@ T &ORecordList<T>::Iterator::operator*() { else - m_record = T; + m_record = T(); @@ -94,4 +99,4 @@ T &ORecordList<T>::Iterator::operator*() { -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator++() { if (m_current < m_uids.count() ) { @@ -104,4 +109,4 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { } -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator--() { if ( m_current > 0 ) { @@ -115,4 +120,4 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { -template <class T = OPimRecord> -bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) { +template <class T> +bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { @@ -127,9 +132,9 @@ bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) } -template <class T = ORecordList> -bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) { +template <class T> +bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { return !(*this == it ); } -template <class T = ORecordList> -ORecordList<T>::Iterator::Iterator( const QArray<int> uids, - OPimAccessTemplate<T>* t ) +template <class T> +ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, + const Base* t ) : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) @@ -137,5 +142,6 @@ ORecordList<T>::Iterator::Iterator( const QArray<int> uids, } -template <class T = ORecordList> + +template <class T> ORecordList<T>::ORecordList( const QArray<int>& ids, - OPimAccessTemplate<T>* acc ) + const Base* acc ) : m_ids( ids ), m_acc( acc ) @@ -143,3 +149,3 @@ ORecordList<T>::ORecordList( const QArray<int>& ids, } -template <class T = ORecordList> +template <class T> ORecordList<T>::~ORecordList() { @@ -147,3 +153,3 @@ ORecordList<T>::~ORecordList() { } -template <class T = ORecordList> +template <class T> ORecordList<T>::Iterator ORecordList<T>::begin() { @@ -152,3 +158,3 @@ ORecordList<T>::Iterator ORecordList<T>::begin() { } -template <class T = ORecordList> +template <class T> ORecordList<T>::Iterator ORecordList<T>::end() { diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h new file mode 100644 index 0000000..41cc934 --- a/dev/null +++ b/libopie/pim/otemplatebase.h @@ -0,0 +1,18 @@ +#ifndef OPIE_TEMPLATE_BASE_H +#define OPIE_TEMPLATE_BASE_H + +#include "opimrecord.h" + +template <class T = OPimRecord> +class OTemplateBase { +public: + OTemplateBase() { + }; + virtual ~OTemplateBase() { + } + virtual T find( int uid ) = 0; + +}; + + +#endif |