author | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
commit | ea3945a9bd8f9830f70b1efa133f9df13b19362f (patch) (unidiff) | |
tree | f2ea22cc50e9aa8aa73ee7dea148f41c563c9666 /libopie/pim/opimcache.h | |
parent | 1c6f490e8541626f68422e0a3a7c7281d7f5b7d3 (diff) | |
download | opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.zip opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.gz opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.bz2 |
libopie1 goes into unsupported
-rw-r--r-- | libopie/pim/opimcache.h | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/libopie/pim/opimcache.h b/libopie/pim/opimcache.h deleted file mode 100644 index 7f7cff5..0000000 --- a/libopie/pim/opimcache.h +++ b/dev/null | |||
@@ -1,131 +0,0 @@ | |||
1 | #ifndef OPIE_PIM_CACHE_H | ||
2 | #define OPIE_PIM_CACHE_H | ||
3 | |||
4 | #include <qintcache.h> | ||
5 | |||
6 | #include "opimrecord.h" | ||
7 | |||
8 | class OPimCacheItemPrivate; | ||
9 | |||
10 | template <class T = OPimRecord> | ||
11 | class OPimCacheItem { | ||
12 | public: | ||
13 | OPimCacheItem( const T& t = T() ); | ||
14 | OPimCacheItem( const OPimCacheItem& ); | ||
15 | ~OPimCacheItem(); | ||
16 | |||
17 | OPimCacheItem &operator=( const OPimCacheItem& ); | ||
18 | |||
19 | T record()const; | ||
20 | void setRecord( const T& ); | ||
21 | private: | ||
22 | T m_t; | ||
23 | OPimCacheItemPrivate *d; | ||
24 | }; | ||
25 | |||
26 | |||
27 | class OPimCachePrivate; | ||
28 | /** | ||
29 | * OPimCache for caching the items | ||
30 | * We support adding, removing | ||
31 | * and finding | ||
32 | */ | ||
33 | template <class T = OPimRecord> | ||
34 | class OPimCache { | ||
35 | public: | ||
36 | typedef OPimCacheItem<T> Item; | ||
37 | OPimCache(); | ||
38 | OPimCache( const OPimCache& ); | ||
39 | ~OPimCache(); | ||
40 | |||
41 | OPimCache &operator=( const OPimCache& ); | ||
42 | |||
43 | bool contains(int uid)const; | ||
44 | void invalidate(); | ||
45 | void setSize( int size ); | ||
46 | |||
47 | T find(int uid )const; | ||
48 | void add( const T& ); | ||
49 | void remove( int uid ); | ||
50 | void replace( const T& ); | ||
51 | |||
52 | private: | ||
53 | QIntCache<Item> m_cache; | ||
54 | OPimCachePrivate* d; | ||
55 | }; | ||
56 | |||
57 | // Implementation | ||
58 | template <class T> | ||
59 | OPimCacheItem<T>::OPimCacheItem( const T& t ) | ||
60 | : m_t(t) { | ||
61 | } | ||
62 | template <class T> | ||
63 | OPimCacheItem<T>::~OPimCacheItem() { | ||
64 | |||
65 | } | ||
66 | template <class T> | ||
67 | T OPimCacheItem<T>::record()const { | ||
68 | return m_t; | ||
69 | } | ||
70 | template <class T> | ||
71 | void OPimCacheItem<T>::setRecord( const T& t ) { | ||
72 | m_t = t; | ||
73 | } | ||
74 | // Cache | ||
75 | template <class T> | ||
76 | OPimCache<T>::OPimCache() | ||
77 | : m_cache(100, 53 ) | ||
78 | { | ||
79 | m_cache.setAutoDelete( TRUE ); | ||
80 | } | ||
81 | template <class T> | ||
82 | OPimCache<T>::~OPimCache() { | ||
83 | |||
84 | } | ||
85 | template <class T> | ||
86 | bool OPimCache<T>::contains(int uid )const { | ||
87 | Item* it = m_cache.find( uid, FALSE ); | ||
88 | if (!it) | ||
89 | return false; | ||
90 | return true; | ||
91 | } | ||
92 | template <class T> | ||
93 | void OPimCache<T>::invalidate() { | ||
94 | m_cache.clear(); | ||
95 | } | ||
96 | template <class T> | ||
97 | void OPimCache<T>::setSize( int size ) { | ||
98 | m_cache.setMaxCost( size ); | ||
99 | } | ||
100 | template <class T> | ||
101 | T OPimCache<T>::find(int uid )const { | ||
102 | Item *it = m_cache.find( uid ); | ||
103 | if (it) | ||
104 | return it->record(); | ||
105 | return T(); | ||
106 | } | ||
107 | template <class T> | ||
108 | void OPimCache<T>::add( const T& t ) { | ||
109 | Item* it = 0l; | ||
110 | it = m_cache.find(t.uid(), FALSE ); | ||
111 | |||
112 | if (it ) | ||
113 | it->setRecord( t ); | ||
114 | |||
115 | it = new Item( t ); | ||
116 | if (!m_cache.insert( t.uid(), it ) ) | ||
117 | delete it; | ||
118 | } | ||
119 | template <class T> | ||
120 | void OPimCache<T>::remove( int uid ) { | ||
121 | m_cache.remove( uid ); | ||
122 | } | ||
123 | template <class T> | ||
124 | void OPimCache<T>::replace( const T& t) { | ||
125 | Item *it = m_cache.find( t.uid() ); | ||
126 | if ( it ) { | ||
127 | it->setRecord( t ); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | #endif | ||