summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimtemplatebase.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimtemplatebase.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
new file mode 100644
index 0000000..58cbfeb
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -0,0 +1,130 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29#ifndef OTEMPLATEBASE_H
30#define OTEMPLATEBASE_H
31
32/* OPIE */
33#include <opie2/opimrecord.h>
34
35/* QT */
36#include <qarray.h>
37
38namespace Opie {
39/**
40 * Templates do not have a base class, This is why
41 * we've this class
42 * this is here to give us the possibility
43 * to have a common base class
44 * You may not want to use that interface internaly
45 * POOR mans interface
46 */
47class OPimBasePrivate;
48struct OPimBase {
49 /**
50 * return the rtti
51 */
52 virtual int rtti()= 0;
53 virtual OPimRecord* record()const = 0;
54 virtual OPimRecord* record(int uid)const = 0;
55 virtual bool add( const OPimRecord& ) = 0;
56 virtual bool remove( int uid ) = 0;
57 virtual bool remove( const OPimRecord& ) = 0;
58 virtual void clear() = 0;
59 virtual bool load() = 0;
60 virtual bool save() = 0;
61 virtual QArray<int> records()const = 0;
62 /*
63 * ADD editing here?
64 * -zecke
65 */
66private:
67 OPimBasePrivate* d;
68
69};
70/**
71 * internal template base
72 * T needs to implement the copy c'tor!!!
73 */
74class OTemplateBasePrivate;
75template <class T = OPimRecord>
76class OTemplateBase : public OPimBase {
77public:
78 enum CacheDirection { Forward=0, Reverse };
79 OTemplateBase() {
80 };
81 virtual ~OTemplateBase() {
82 }
83 virtual T find( int uid )const = 0;
84
85 /**
86 * read ahead find
87 */
88 virtual T find( int uid, const QArray<int>& items,
89 uint current, CacheDirection dir = Forward )const = 0;
90 virtual void cache( const T& )const = 0;
91 virtual void setSaneCacheSize( int ) = 0;
92
93 /* reimplement of OPimBase */
94 int rtti();
95 OPimRecord* record()const;
96 OPimRecord* record(int uid )const;
97 static T* rec();
98
99private:
100 OTemplateBasePrivate *d;
101};
102
103/*
104 * implementation
105 */
106template <class T>
107int
108OTemplateBase<T>::rtti() {
109 return T::rtti();
110}
111template <class T>
112OPimRecord* OTemplateBase<T>::record()const {
113 T* t = new T;
114 return t;
115}
116template <class T>
117OPimRecord* OTemplateBase<T>::record(int uid )const {
118 T t2 = find(uid );
119 T* t1 = new T(t2);
120
121 return t1;
122};
123template <class T>
124T* OTemplateBase<T>::rec() {
125 return new T;
126}
127
128}
129
130#endif