-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 106 | ||||
-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 |
4 files changed, 97 insertions, 35 deletions
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 @@ #ifndef OPIE_PIM_ACCESS_TEMPLATE_H #define OPIE_PIM_ACCESS_TEMPLATE_H #include <qarray.h> #include <opie/opimrecord.h> #include <opie/opimaccessbackend.h> #include <opie/orecordlist.h> +#include "otemplatebase.h" + template <class T = OPimRecord > -class OPimAccessTemplate { +class OPimAccessTemplate : public OTemplateBase<T> { public: typedef ORecordList<T> List; 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 ); return lis; } - 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 ); return t; } - - /* invalidate cache here */ - virtual void clear() { +template <class T> +void OPimAccessTemplate<T>::clear() { invalidateCache(); m_backEnd->clear(); } - 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; +} #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 @@ #include <qpe/categories.h> #include <qpe/categoryselect.h> #include "opimrecord.h" +Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); + + OPimRecord::OPimRecord( int uid ) : Qtopia::Record() { setUid( uid ); } OPimRecord::~OPimRecord() { } OPimRecord::OPimRecord( const OPimRecord& rec ) : Qtopia::Record( rec ) { (*this) = rec; } @@ -116,12 +119,15 @@ QString OPimRecord::crossToString()const { //qWarning("IDS " + str ); return str; } /* if uid = 1 assign a new one */ void OPimRecord::setUid( int uid ) { if ( uid == 1) uid = uidGen().generate(); Qtopia::Record::setUid( uid ); }; +Qtopia::UidGen &OPimRecord::uidGen() { + return m_uidGen; +} 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: /** * */ void addRelation( const QString& app, int id ); /** * */ void setRelations( const QString&, QArray<int> ids ); virtual void setUid( int uid ); protected: + Qtopia::UidGen &uidGen(); QString crossToString()const; private: class OPimRecordPrivate; OPimRecordPrivate *d; QMap<QString, QArray<int> > m_relations; + static Qtopia::UidGen m_uidGen; }; #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 @@ +#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 |