summaryrefslogtreecommitdiff
path: root/src/PolySetCache.h
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-11 07:10:31 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-11 07:10:31 (GMT)
commit18e97e0bd3f6bda4fdcd17de2a85173ba59b6b00 (patch)
tree327ec7c648e0f01a2673672ebe83c3524c971e19 /src/PolySetCache.h
parent9afeded46c0e9023002dc04ba6131adcb39762b1 (diff)
Fixed bug introduced by the new PolySet cache; string filtering done in the wrong place, refactored cache into separate class
Diffstat (limited to 'src/PolySetCache.h')
-rw-r--r--src/PolySetCache.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/PolySetCache.h b/src/PolySetCache.h
new file mode 100644
index 0000000..da51c5e
--- /dev/null
+++ b/src/PolySetCache.h
@@ -0,0 +1,34 @@
+#ifndef POLYSETCACHE_H_
+#define POLYSETCACHE_H_
+
+#include "myqhash.h"
+#include <QCache>
+#include "memory.h"
+
+class PolySetCache
+{
+public:
+ PolySetCache(size_t polygonlimit = 100000) : cache(polygonlimit) {}
+
+ static PolySetCache *instance() { if (!inst) inst = new PolySetCache; return inst; }
+
+ bool contains(const std::string &id) const { return this->cache.contains(id); }
+ shared_ptr<class PolySet> get(const std::string &id) const { return this->cache[id]->ps; }
+ void insert(const std::string &id, const shared_ptr<PolySet> &ps);
+ void clear() { cache.clear(); }
+ void print();
+
+private:
+ static PolySetCache *inst;
+
+ struct cache_entry {
+ shared_ptr<class PolySet> ps;
+ QString msg;
+ cache_entry(const shared_ptr<PolySet> &ps);
+ ~cache_entry() { }
+ };
+
+ QCache<std::string, cache_entry> cache;
+};
+
+#endif
contact: Jan Huwald // Impressum