Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 106 |
1 files changed, 71 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 @@ -7,76 +7,112 @@ #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 |