summaryrefslogtreecommitdiff
path: root/src/PolySetCache.h
blob: d69f2e285cb6c6e18e8f89d77d0263b236b7dc50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef POLYSETCACHE_H_
#define POLYSETCACHE_H_

#include "cache.h"
#include "memory.h"

class PolySetCache
{
public:	
	PolySetCache(size_t memorylimit = 100*1024*1024) : cache(memorylimit) {}

	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);
	size_t maxSize() const;
	void setMaxSize(size_t limit);
	void clear() { cache.clear(); }
	void print();

private:
	static PolySetCache *inst;

	struct cache_entry {
		shared_ptr<class PolySet> ps;
		std::string msg;
		cache_entry(const shared_ptr<PolySet> &ps);
		~cache_entry() { }
	};

	Cache<std::string, cache_entry> cache;
};

#endif
contact: Jan Huwald // Impressum