summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/otemplatebase.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/otemplatebase.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/otemplatebase.h63
1 files changed, 61 insertions, 2 deletions
diff --git a/libopie2/opiepim/core/otemplatebase.h b/libopie2/opiepim/core/otemplatebase.h
index b855919..29fb6ec 100644
--- a/libopie2/opiepim/core/otemplatebase.h
+++ b/libopie2/opiepim/core/otemplatebase.h
@@ -3,13 +3,43 @@
3 3
4#include <qarray.h> 4#include <qarray.h>
5 5
6#include "opimrecord.h" 6#include <opie/opimrecord.h>
7
7 8
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 */
17struct OPimBase {
18 /**
19 * return the rtti
20 */
21 virtual int rtti()= 0;
22 virtual OPimRecord* record()const = 0;
23 virtual OPimRecord* record(int uid)const = 0;
24 virtual bool add( const OPimRecord& ) = 0;
25 virtual bool remove( int uid ) = 0;
26 virtual bool remove( const OPimRecord& ) = 0;
27 virtual void clear() = 0;
28 virtual bool load() = 0;
29 virtual bool save() = 0;
30 virtual QArray<int> records()const = 0;
31 /*
32 * ADD editing here?
33 * -zecke
34 */
35
36};
37/**
9 * internal template base 38 * internal template base
39 * T needs to implement the copy c'tor!!!
10 */ 40 */
11template <class T = OPimRecord> 41template <class T = OPimRecord>
12class OTemplateBase { 42class OTemplateBase : public OPimBase {
13public: 43public:
14 enum CacheDirection { Forward=0, Reverse }; 44 enum CacheDirection { Forward=0, Reverse };
15 OTemplateBase() { 45 OTemplateBase() {
@@ -26,7 +56,36 @@ public:
26 virtual void cache( const T& )const = 0; 56 virtual void cache( const T& )const = 0;
27 virtual void setSaneCacheSize( int ) = 0; 57 virtual void setSaneCacheSize( int ) = 0;
28 58
59 /* reimplement of OPimBase */
60 int rtti();
61 OPimRecord* record()const;
62 OPimRecord* record(int uid )const;
63 static T* rec();
29}; 64};
30 65
66/*
67 * implementation
68 */
69template <class T>
70int
71OTemplateBase<T>::rtti() {
72 return T::rtti();
73}
74template <class T>
75OPimRecord* OTemplateBase<T>::record()const {
76 T* t = new T;
77 return t;
78}
79template <class T>
80OPimRecord* OTemplateBase<T>::record(int uid )const {
81 T t2 = find(uid );
82 T* t1 = new T(t2);
83
84 return t1;
85};
86template <class T>
87T* OTemplateBase<T>::rec() {
88 return new T;
89}
31 90
32#endif 91#endif