-rw-r--r-- | libopie/pim/otemplatebase.h | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/libopie/pim/otemplatebase.h b/libopie/pim/otemplatebase.h index b855919..29fb6ec 100644 --- a/libopie/pim/otemplatebase.h +++ b/libopie/pim/otemplatebase.h | |||
@@ -1,32 +1,91 @@ | |||
1 | #ifndef OPIE_TEMPLATE_BASE_H | 1 | #ifndef OPIE_TEMPLATE_BASE_H |
2 | #define OPIE_TEMPLATE_BASE_H | 2 | #define OPIE_TEMPLATE_BASE_H |
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 | */ | ||
17 | struct 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 | */ |
11 | template <class T = OPimRecord> | 41 | template <class T = OPimRecord> |
12 | class OTemplateBase { | 42 | class OTemplateBase : public OPimBase { |
13 | public: | 43 | public: |
14 | enum CacheDirection { Forward=0, Reverse }; | 44 | enum CacheDirection { Forward=0, Reverse }; |
15 | OTemplateBase() { | 45 | OTemplateBase() { |
16 | }; | 46 | }; |
17 | virtual ~OTemplateBase() { | 47 | virtual ~OTemplateBase() { |
18 | } | 48 | } |
19 | virtual T find( int uid )const = 0; | 49 | virtual T find( int uid )const = 0; |
20 | 50 | ||
21 | /** | 51 | /** |
22 | * read ahead find | 52 | * read ahead find |
23 | */ | 53 | */ |
24 | virtual T find( int uid, const QArray<int>& items, | 54 | virtual T find( int uid, const QArray<int>& items, |
25 | uint current, CacheDirection dir = Forward )const = 0; | 55 | uint current, CacheDirection dir = Forward )const = 0; |
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 | */ | ||
69 | template <class T> | ||
70 | int | ||
71 | OTemplateBase<T>::rtti() { | ||
72 | return T::rtti(); | ||
73 | } | ||
74 | template <class T> | ||
75 | OPimRecord* OTemplateBase<T>::record()const { | ||
76 | T* t = new T; | ||
77 | return t; | ||
78 | } | ||
79 | template <class T> | ||
80 | OPimRecord* OTemplateBase<T>::record(int uid )const { | ||
81 | T t2 = find(uid ); | ||
82 | T* t1 = new T(t2); | ||
83 | |||
84 | return t1; | ||
85 | }; | ||
86 | template <class T> | ||
87 | T* OTemplateBase<T>::rec() { | ||
88 | return new T; | ||
89 | } | ||
31 | 90 | ||
32 | #endif | 91 | #endif |