summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorlordjaxom <lordjaxom>2004-06-05 18:06:22 +0000
committerlordjaxom <lordjaxom>2004-06-05 18:06:22 +0000
commit6094765d94e4caaf0813039dff826b731f277753 (patch)
treefed79334167f26d5a81a6cae9be3f1341375a36f /cache.h
parente0c2ee1d37c0f213f22a04df71710bebe3526f85 (diff)
downloadvdr-plugin-text2skin-6094765d94e4caaf0813039dff826b731f277753.tar.gz
vdr-plugin-text2skin-6094765d94e4caaf0813039dff826b731f277753.tar.bz2
- added scrollable texts and "SymbolScrollUp" and "SymbolScrollDown"v0.0.1
- added "MenuText", "MenuEventTitle", "MenuEventShortText", "MenuEventDescription", "MenuEventTime", "MenuRecording", "SymbolEventRunning", "SymbolEventTimer" and "SymbolEventVPS" - implemented image caching - added english and german README - removed some workarounds, and added a patch to vdr to the tree (will be included in 1.3.10) - fixed two bugs when displaying replay symbols - implemented tabbed texts in menu
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/cache.h b/cache.h
new file mode 100644
index 0000000..93aff9f
--- /dev/null
+++ b/cache.h
@@ -0,0 +1,124 @@
+/*
+ * $Id: cache.h,v 1.1 2004/06/05 01:40:13 lordjaxom Exp $
+ */
+
+#ifndef VDR_TEXT2SKIN_CACHE_HPP
+#define VDR_TEXT2SKIN_CACHE_HPP
+
+#include "common.h"
+
+// template class generic cache
+
+template<class K,class D>
+class cText2SkinCache {
+private:
+ struct Item {
+ K _key;
+ D _data;
+ time_t _lastUsed;
+
+ Item *_next;
+ Item *_prev;
+
+ Item() { _next = _prev = NULL; }
+ };
+
+ typedef map <K,Item*> DataMap;
+
+ DataMap _items;
+ int _maxItems;
+ Item *_first;
+ Item *_last;
+
+ void Unlink(Item *item);
+ void Update(Item *item);
+ void Delete(Item *item);
+ void Delete(K &key, D &data);
+
+public:
+ cText2SkinCache(int maxItems);
+ ~cText2SkinCache();
+
+ bool Contains(const K &key);
+ D &operator[](const K &key);
+};
+
+template<class K,class D>
+inline void cText2SkinCache<K,D>::Unlink(Item *item) {
+ if (item == _first) {
+ _first = item->_next;
+ if (_first)
+ _first->_prev = NULL;
+ else
+ _last = NULL;
+ } else if (item == _last) {
+ _last = item->_prev;
+ _last->_next = NULL;
+ } else {
+ item->_prev->_next = item->_next;
+ item->_next->_prev = item->_prev;
+ }
+}
+
+template<class K,class D>
+inline void cText2SkinCache<K,D>::Delete(Item *item) {
+ Delete(item->_key, item->_data);
+ delete item;
+}
+
+template<class K,class D>
+inline void cText2SkinCache<K,D>::Delete(K &key, D &Data) {
+}
+
+template<class K,class D>
+inline void cText2SkinCache<K,D>::Update(Item *item) {
+ item->_lastUsed = time_ms();
+ if (item->_next != NULL || item->_prev != NULL)
+ Unlink(item);
+
+ item->_next = NULL;
+ item->_prev = _last;
+ if (_last)
+ _last->_next = item;
+ _last = item;
+ if (!_first)
+ _first = item;
+
+ while ((int)_items.size() > _maxItems) {
+ Item *aged = _first;
+ _items.erase(aged->_key);
+ Unlink(aged);
+ Delete(aged);
+ }
+}
+
+template<class K,class D>
+inline bool cText2SkinCache<K,D>::Contains(const K &key) {
+ return (_items.find(key) != _items.end());
+}
+
+template<class K,class D>
+cText2SkinCache<K,D>::cText2SkinCache(int maxItems) {
+ _maxItems = maxItems;
+ _first = _last = NULL;
+}
+
+template<class K,class D>
+cText2SkinCache<K,D>::~cText2SkinCache() {
+}
+
+template<class K,class D>
+D &cText2SkinCache<K,D>::operator[](const K &key) {
+ Item *item;
+ if (Contains(key)) {
+ item = _items[key];
+ } else {
+ item = new Item;
+ item->_key = key;
+ _items[key] = item;
+ }
+ Update(item);
+ return item->_data;
+}
+
+#endif // VDR_TEXT2SKIN_CACHE_HPP