00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00071
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
00154
00155
00156
00157
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
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