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

opimtemplatebase.h

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003                              Copyright (C) Holger Freyther <zecke@handhelds.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 OTEMPLATEBASE_H
00030 #define OTEMPLATEBASE_H
00031 
00032 /* OPIE */
00033 #include <opie2/opimrecord.h>
00034 #include <opie2/opimcache.h>
00035 #include <opie2/opimoccurrence.h>
00036 #include <opie2/opimbackendoccurrence.h>
00037 
00038 /* QT */
00039 #include <qarray.h>
00040 #include <qdatetime.h>
00041 
00042 namespace Opie {
00043 
00044 class OPimBasePrivate;
00045 
00052 struct OPimBase {
00054     OPimBase();
00055     virtual ~OPimBase();
00057 
00059 
00062     virtual int rtti() const = 0;
00063     virtual OPimRecord* record()const = 0;
00064     virtual OPimRecord* record(int uid)const = 0;
00066 
00068     virtual bool add( const OPimRecord& ) = 0;
00069     virtual bool add( const OPimRecord* ) = 0;
00070 
00071     virtual bool remove( int uid ) = 0;
00072     virtual bool remove( const OPimRecord& ) = 0;
00074 
00076     virtual void clear() = 0;
00077     virtual bool load() = 0;
00078     virtual bool save() = 0;
00080 
00082     virtual QArray<UID> records()const = 0;
00084 
00090     enum QuerySettings {
00092         WildCards  = 0x0001,
00094         IgnoreCase = 0x0002,
00096         RegExp     = 0x0004, 
00098         ExactMatch = 0x0008, 
00100         MatchOne   = 0x0010, 
00102         DateDiff   = 0x0020, 
00104         DateYear   = 0x0040, 
00106         DateMonth  = 0x0080, 
00108         DateDay    = 0x0100, 
00110         LastItem   = 0xffff  
00111     };
00112 
00116     enum SortOrderBase {
00118         SortSummary = 0,
00120         SortByCategory = 1,
00122         SortByDate = 2, 
00124         SortCustom  = 10,
00126         LastSortOrderBase = 0xffff 
00127     };
00128 
00136     enum SortFilterBase {
00138         FilterOff = 0,
00140         FilterCategory = 1,
00142         FilterCustom = 1024, 
00143         LastSortFilterBase = 0xffffffff
00144     };
00145 
00146     virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0;
00147     virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings,
00148                                            const QDateTime& d = QDateTime() )const  = 0;
00149     virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
00150                                    int sortOrder, int sortFilter, int cat)const = 0;
00151     virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
00152                                    int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
00153     virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0;
00154     virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
00155     virtual OPimOccurrence::List occurrences( const QDate& start,  const QDate& end )const = 0;
00156     virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0;
00158 
00159 
00160 protected:
00161     OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const;
00162 
00163 private:
00164     OPimBasePrivate* d;
00165 };
00166 
00167 
00172 class OTemplateBasePrivate;
00173 template <class T = OPimRecord>
00174 class OTemplateBase : public OPimBase {
00175 public:
00184     enum CacheDirection {
00185         Forward=0, 
00186         Reverse    
00187     };
00188 
00189 
00191     OTemplateBase() {};
00192     virtual ~OTemplateBase() {}
00194 
00195 
00197     virtual T find( int uid )const = 0;
00198 
00202     virtual T find( int uid, const QArray<int>& items,
00203                     uint current, CacheDirection dir = Forward )const = 0;
00205 
00207 
00210     virtual void cache( const T& )const = 0;
00211     virtual void setSaneCacheSize( int ) = 0;
00212 
00213     OPimRecord* record()const;
00214     OPimRecord* record(int uid )const;
00215     static T* rec();
00217 
00218 private:
00219     OTemplateBasePrivate *d;
00220 };
00221 
00222 
00223 template <class T>
00224 OPimRecord* OTemplateBase<T>::record()const {
00225     T* t = new T;
00226     return t;
00227 }
00228 template <class T>
00229 OPimRecord* OTemplateBase<T>::record(int uid )const {
00230     T  t2 = find(uid );
00231     T* t1 = new T(t2);
00232 
00233     return t1;
00234 }
00235 
00236 template <class T>
00237 T* OTemplateBase<T>::rec() {
00238     return new T;
00239 }
00240 }
00241 
00242 #endif

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