From a05c10c9744020be31c3038b2de3401b5cc673fb Mon Sep 17 00:00:00 2001 From: zecke Date: Fri, 20 Sep 2002 12:59:29 +0000 Subject: Our new common template based start for Accessing and Manipulating the Records The CROSS_REFERENCE branch will get ported to it. We use templates for several reasons They allow us to share code and to be easily extended I've to make them not inline to save memory... I've to port all DBs and Record related classes --- (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h new file mode 100644 index 0000000..f2a241d --- a/dev/null +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -0,0 +1,82 @@ +#ifndef OPIE_PIM_ACCESS_TEMPLATE_H +#define OPIE_PIM_ACCESS_TEMPLATE_H + +#include + +#include +#include +#include + +template +class OPimAccessTemplate { +public: + typedef ORecordList List; + typedef OPimAccessBackend BackEnd; + OPimAccessTemplate( BackEnd* end) + : m_backEnd( end ) { + } + ~OPimAccessTemplate() { + delete m_backEnd; + } + virtual void load() { + m_backEnd->load(); + } + virtual void reload() { + m_backEnd->reload(); + } + virtual void save() { + m_backEnd->save(); + } + + /* + *do array to Records conversion + * QArray ids + */ + virtual List allRecords()const { + QArray ints = m_backEnd->allRecords(); + + List lis( ints, this ); + return lis; + } + virtual List queryByExample( const T& t, int sortOrder ) { + QArray ints = m_backEnd->query( t, sortOrder ); + List lis( ints, this ); + + return lis; + } + /* implement QCache here */ + virtual T find( int uid ) { + T t = m_backEnd->find( uid ); + return t; + } + + /* invalidate cache here */ + virtual void clear() { + invalidateCache(); + m_backEnd->clear(); + } + virtual bool add( const T& t ) { + return m_backEnd->add( t ); + } + + /* only the uid matters */ + virtual bool remove( const T& t ) { + /* remove from cache */ + return m_backEnd->remove( t.uid() ); + } + virtual bool remove( int uid ) { + /* remove from cache */ + return m_backEnd->remove(uid); + } + virtual bool replace( const T& t) { + return m_backEnd->replace( t ); + } +protected: + void invalidateCache() { + + } + BackEnd* m_backEnd; + +}; + +#endif -- cgit v0.9.0.2