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