Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opimaccessbackend.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) The Main Author <main-author@whereever.org>
00004               =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005             .=l.
00006            .>+-=
00007  _;:,     .>    :=|.         This program is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This program is distributed in the hope that
00015      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00019 ..}^=.=       =       ;      Library General Public License for more
00020 ++=   -.     .`     .:       details.
00021  :     =  ...= . :.=-
00022  -.   .:....=;==+<;          You should have received a copy of the GNU
00023   -_. . .   )=.  =           Library General Public License along with
00024     --        :-=`           this library; see the file COPYING.LIB.
00025                              If not, write to the Free Software Foundation,
00026                              Inc., 59 Temple Place - Suite 330,
00027                              Boston, MA 02111-1307, USA.
00028 */
00029 #ifndef OPIE_PIM_ACCESS_BACKEND
00030 #define OPIE_PIM_ACCESS_BACKEND
00031 
00032 #include <qarray.h>
00033 #include <qdatetime.h>
00034 
00035 #include <opie2/opimtemplatebase.h>
00036 #include <opie2/opimrecord.h>
00037 #include <opie2/opimbackendoccurrence.h>
00038 
00039 namespace Opie {
00040 class OPimAccessBackendPrivate;
00041 
00052 template <class T = OPimRecord>
00053 class OPimAccessBackend {
00054 public:
00055     typedef OTemplateBase<T> Frontend;
00056 
00058     OPimAccessBackend(int access = 0);
00059     virtual ~OPimAccessBackend();
00061 
00063     virtual bool load() = 0;
00064     virtual bool reload() = 0;
00065     virtual bool save() = 0;
00066     virtual void clear() = 0;
00068 
00070     // FIXME: Uncommented some of the abstract functions below. This should be removed as they are implemented in 
00071     // all typespecifc backenends (eilers) 
00078     virtual const uint querySettings() const = 0;
00079 
00085     virtual bool hasQuerySettings (uint querySettings) const = 0;
00087 
00088 
00090     virtual UIDArray allRecords()const = 0;
00091     virtual UIDArray matchRegexp(const QRegExp &r) const;
00092     virtual UIDArray queryByExample( const UIDArray&, const T& t, 
00093                                      int settings, const QDateTime& d = QDateTime() )const = 0;
00094     virtual UIDArray queryByExample( const T& t, int settings, const QDateTime& d = QDateTime() )const;
00095     virtual UIDArray queryByExample( const OPimRecord* rec, int settings, const QDateTime& d = QDateTime() )const;
00096     virtual UIDArray sorted( const UIDArray&, bool asc, int sortOrder, int sortFilter,  const QArray<int>& cats )const = 0;
00097     virtual UIDArray sorted( bool asc, int sortOrder, int sortFilter, const QArray<int>& cats )const;
00098     virtual OPimBackendOccurrence::List occurrences( const QDate& start, const QDate& end)const;
00099     virtual OPimBackendOccurrence::List occurrences( const QDateTime& dt )const;
00101 
00102 
00104     virtual T find(UID uid )const  = 0;
00105     virtual T find(UID uid, const QArray<UID>& items,
00106                    uint current, typename Frontend::CacheDirection )const ;
00108 
00109 
00111     virtual bool add( const T& t ) = 0;
00112     virtual bool remove( UID uid ) = 0;
00113     virtual bool replace( const T& t ) = 0;
00115 
00116 
00117 
00118     void setFrontend( Frontend* front );
00119 
00123     void setReadAhead( uint count );
00124 protected:
00126     int access()const;
00127     void cache( const T& t )const;
00128     void setSaneCacheSize( int );
00129     uint readAhead()const;
00131 
00132 private:
00133     OPimAccessBackendPrivate *d;
00134     Frontend* m_front;
00135     uint m_read;
00136     int m_acc;
00137 
00138 };
00139 
00140 template <class T>
00141 OPimAccessBackend<T>::OPimAccessBackend(int acc)
00142     : m_acc( acc )
00143 {
00144     m_front = 0l;
00145     m_read = 20;
00146 }
00147 template <class T>
00148 OPimAccessBackend<T>::~OPimAccessBackend() {
00149 
00150 }
00151 
00152 /*
00153  * Slow but default matchRegexp Implementation
00154  * Create a Big Enough QArray and then iterate
00155  * over all Records and matchRegexp them.
00156  * At the end we will resize the array to the actual
00157  * number of items
00158  */
00159 template <class T>
00160 UIDArray OPimAccessBackend<T>::matchRegexp( const QRegExp& reg )const {
00161     UIDArray all_rec = allRecords();
00162     UIDArray result( all_rec.count() );
00163     uint used_records = 0, all_rec_count = all_rec.count();
00164 
00165     for ( uint i = 0; i < all_rec_count; ++i )
00166         if (find( all_rec[i], all_rec, i, Frontend::Forward ).match( reg ) )
00167             result[used_records++] = all_rec[i];
00168 
00169     /* shrink to fit */
00170     result.resize( used_records );
00171     return result;
00172 }
00173 
00174 template <class T>
00175 UIDArray OPimAccessBackend<T>::queryByExample( const T& rec, int settings,
00176                                                const QDateTime& datetime )const {
00177 
00178         return queryByExample( allRecords(), rec, settings, datetime );
00179 }
00180 
00181 template <class T>
00182 UIDArray OPimAccessBackend<T>::queryByExample( const OPimRecord* rec, int settings,
00183                                                const QDateTime& datetime )const {
00184     T* tmp_rec = T::safeCast( rec );
00185     UIDArray ar;
00186     if ( tmp_rec )
00187         ar = queryByExample( *tmp_rec, settings, datetime );
00188 
00189     return ar;
00190 }
00191 
00192 template <class T>
00193 UIDArray OPimAccessBackend<T>::sorted( bool asc, int order, int filter,
00194                                        const QArray<int>& cats )const {
00195     return sorted( allRecords(), asc, order, filter, cats );
00196 }
00197 
00198 template<class T>
00199 OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDate&,
00200                                                                const QDate& )const {
00201     return OPimBackendOccurrence::List();
00202 }
00203 
00204 template<class T>
00205 OPimBackendOccurrence::List OPimAccessBackend<T>::occurrences( const QDateTime& dt )const {
00206     QDate date = dt.date();
00207     return occurrences( date, date );
00208 }
00209 
00210 template <class T>
00211 void OPimAccessBackend<T>::setFrontend( Frontend* fr ) {
00212     m_front = fr;
00213 }
00214 template <class T>
00215 void OPimAccessBackend<T>::cache( const T& t )const {
00216     if ( m_front )
00217         m_front->cache( t );
00218 }
00219 
00220 template <class T>
00221 void OPimAccessBackend<T>::setSaneCacheSize( int size) {
00222     if ( m_front )
00223         m_front->setSaneCacheSize( size );
00224 }
00225 template <class T>
00226 T OPimAccessBackend<T>::find( int uid, const QArray<int>&,
00227                               uint, typename Frontend::CacheDirection ) const{
00228     qDebug( "*** Lookahead feature not supported. Fallback to default find!!" );
00229     return find( uid );
00230 }
00231 template <class T>
00232 void OPimAccessBackend<T>::setReadAhead( uint count ) {
00233     m_read = count;
00234 }
00235 template <class T>
00236 uint OPimAccessBackend<T>::readAhead()const {
00237     return m_read;
00238 }
00239 template <class T>
00240 int OPimAccessBackend<T>::access()const {
00241     return m_acc;
00242 }
00243 
00244 }
00245 
00446 #endif

Generated on Sat Nov 5 16:16:16 2005 for OPIE by  doxygen 1.4.2