-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 34 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 |
2 files changed, 42 insertions, 8 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 55d600a..6f01b46 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -35,7 +35,6 @@ #include <opie2/opimaccessbackend.h> #include <opie2/opimrecordlist.h> -#include <opie2/opimcache.h> #include <opie2/opimtemplatebase.h> #include <opie2/odebug.h> @@ -128,6 +127,7 @@ public: virtual T find( int uid, const QArray<int>&, uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; + /* invalidate cache here */ /** * clears the backend and invalidates the backend @@ -140,12 +140,14 @@ public: * @return <i>true</i> if added successfully. */ virtual bool add( const T& t ) ; + bool add( const OPimRecord& ); - // Needed for real generic access (eilers) - // Info: Take this if you are working with OPimRecord, which is a generic base class, and - // you need to add it into any database, you cannot generate a reference to - // it and casting may be not approriate, too. - // But take care that the accessing database is compatible to the real type of OPimRecord !! + /** + * Add an Opie PimRecord. + * Info: Take this if you are working with OPimRecords and you need to add it into any database. + * But take care that the accessing database is compatible to the real type of OPimRecord !! + * Otherwise this access will be rejected ! + */ bool add( const OPimRecord* ); @@ -176,6 +178,7 @@ public: /** * @internal */ + virtual T cacheFind( int uid )const; void cache( const T& )const; void setSaneCacheSize( int ); @@ -192,6 +195,7 @@ protected: */ BackEnd* backEnd(); BackEnd* m_backEnd; + Cache m_cache; private: @@ -218,7 +222,7 @@ bool OPimAccessTemplate<T>::load() { } template <class T> bool OPimAccessTemplate<T>::reload() { - invalidateCache(); // zecke: I think this should be added (se) + invalidateCache(); return m_backEnd->reload(); } template <class T> @@ -251,10 +255,22 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime } template <class T> T OPimAccessTemplate<T>::find( int uid ) const{ + // First search in cache.. + if ( m_cache.contains( uid ) ) + return m_cache.find( uid ); + T t = m_backEnd->find( uid ); cache( t ); + return t; } + +template <class T> +T OPimAccessTemplate<T>::cacheFind( int uid ) const +{ + return m_cache.find( uid ); +} + template <class T> T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, uint current, typename OTemplateBase<T>::CacheDirection dir )const { @@ -290,6 +306,8 @@ bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { if ( rec.rtti() == tempInstance.rtti() ) { const T& t = static_cast<const T&>(rec); return add(t); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } @@ -301,6 +319,8 @@ bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { if ( rec -> rtti() == tempInstance.rtti() ) { const T* t = static_cast<const T*>(rec); return add( *t ); + } else { + owarn << "Adding not possible: Objecttype mismatch" << oendl; } return false; } diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index b48dfed..ec9a94e 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h @@ -31,6 +31,7 @@ /* OPIE */ #include <opie2/opimrecord.h> +#include <opie2/opimcache.h> /* QT */ #include <qarray.h> @@ -70,13 +71,15 @@ private: }; /** * internal template base - * T needs to implement the copy c'tor!!! + * Attention: T needs to implement the copy c'tor!!! */ class OTemplateBasePrivate; template <class T = OPimRecord> class OTemplateBase : public OPimBase { public: + /** Look ahead direction of cache */ enum CacheDirection { Forward=0, Reverse }; + OTemplateBase() { }; virtual ~OTemplateBase() { @@ -88,6 +91,16 @@ public: */ virtual T find( int uid, const QArray<int>& items, uint current, CacheDirection dir = Forward )const = 0; + + /** + * Find in Cache.. + * Returns empty object if nothing found. + */ + virtual T cacheFind( int uid )const = 0; + + /** + * Put element into Cache + */ virtual void cache( const T& )const = 0; virtual void setSaneCacheSize( int ) = 0; @@ -95,6 +108,7 @@ public: OPimRecord* record(int uid )const; static T* rec(); + private: OTemplateBasePrivate *d; }; |