summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/pim/otemplatebase.h
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/pim/otemplatebase.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/pim/otemplatebase.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/otemplatebase.h b/noncore/unsupported/libopie/pim/otemplatebase.h
new file mode 100644
index 0000000..cadac74
--- a/dev/null
+++ b/noncore/unsupported/libopie/pim/otemplatebase.h
@@ -0,0 +1,98 @@
1#ifndef OPIE_TEMPLATE_BASE_H
2#define OPIE_TEMPLATE_BASE_H
3
4#include <qarray.h>
5
6#include <opie/opimrecord.h>
7
8
9/**
10 * Templates do not have a base class, This is why
11 * we've this class
12 * this is here to give us the possibility
13 * to have a common base class
14 * You may not want to use that interface internaly
15 * POOR mans interface
16 */
17class OPimBasePrivate;
18struct OPimBase {
19 /**
20 * return the rtti
21 */
22 virtual int rtti()= 0;
23 virtual OPimRecord* record()const = 0;
24 virtual OPimRecord* record(int uid)const = 0;
25 virtual bool add( const OPimRecord& ) = 0;
26 virtual bool remove( int uid ) = 0;
27 virtual bool remove( const OPimRecord& ) = 0;
28 virtual void clear() = 0;
29 virtual bool load() = 0;
30 virtual bool save() = 0;
31 virtual QArray<int> records()const = 0;
32 /*
33 * ADD editing here?
34 * -zecke
35 */
36private:
37 OPimBasePrivate* d;
38
39};
40/**
41 * internal template base
42 * T needs to implement the copy c'tor!!!
43 */
44class OTemplateBasePrivate;
45template <class T = OPimRecord>
46class OTemplateBase : public OPimBase {
47public:
48 enum CacheDirection { Forward=0, Reverse };
49 OTemplateBase() {
50 };
51 virtual ~OTemplateBase() {
52 }
53 virtual T find( int uid )const = 0;
54
55 /**
56 * read ahead find
57 */
58 virtual T find( int uid, const QArray<int>& items,
59 uint current, CacheDirection dir = Forward )const = 0;
60 virtual void cache( const T& )const = 0;
61 virtual void setSaneCacheSize( int ) = 0;
62
63 /* reimplement of OPimBase */
64 int rtti();
65 OPimRecord* record()const;
66 OPimRecord* record(int uid )const;
67 static T* rec();
68
69private:
70 OTemplateBasePrivate *d;
71};
72
73/*
74 * implementation
75 */
76template <class T>
77int
78OTemplateBase<T>::rtti() {
79 return T::rtti();
80}
81template <class T>
82OPimRecord* OTemplateBase<T>::record()const {
83 T* t = new T;
84 return t;
85}
86template <class T>
87OPimRecord* OTemplateBase<T>::record(int uid )const {
88 T t2 = find(uid );
89 T* t1 = new T(t2);
90
91 return t1;
92};
93template <class T>
94T* OTemplateBase<T>::rec() {
95 return new T;
96}
97
98#endif