2011-09-11 13:07:18 +04:00
|
|
|
#include "CGALCache.h"
|
|
|
|
#include "printutils.h"
|
|
|
|
#include "CGAL_Nef_polyhedron.h"
|
|
|
|
|
|
|
|
CGALCache *CGALCache::inst = NULL;
|
|
|
|
|
2012-01-08 05:45:58 +04:00
|
|
|
CGALCache::CGALCache(size_t limit) : cache(limit)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-10 02:59:53 +04:00
|
|
|
const CGAL_Nef_polyhedron &CGALCache::get(const std::string &id) const
|
2011-09-11 13:07:18 +04:00
|
|
|
{
|
2012-01-10 02:59:53 +04:00
|
|
|
const CGAL_Nef_polyhedron &N = *this->cache[id];
|
2011-12-26 22:15:51 +04:00
|
|
|
#ifdef DEBUG
|
2013-11-21 10:25:15 +04:00
|
|
|
PRINTB("CGAL Cache hit: %s (%d bytes)", id.substr(0, 40) % N.memsize());
|
2011-12-26 22:15:51 +04:00
|
|
|
#endif
|
2012-01-10 02:59:53 +04:00
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGALCache::insert(const std::string &id, const CGAL_Nef_polyhedron &N)
|
|
|
|
{
|
2013-11-21 10:25:15 +04:00
|
|
|
bool inserted = this->cache.insert(id, new CGAL_Nef_polyhedron(N), N.memsize());
|
2012-01-10 02:59:53 +04:00
|
|
|
#ifdef DEBUG
|
2013-11-21 10:25:15 +04:00
|
|
|
if (inserted) PRINTB("CGAL Cache insert: %s (%d bytes)", id.substr(0, 40) % N.memsize());
|
|
|
|
else PRINTB("CGAL Cache insert failed: %s (%d bytes)", id.substr(0, 40) % N.memsize());
|
2012-01-10 02:59:53 +04:00
|
|
|
#endif
|
|
|
|
return inserted;
|
2011-09-11 13:07:18 +04:00
|
|
|
}
|
|
|
|
|
2012-01-06 22:10:33 +04:00
|
|
|
size_t CGALCache::maxSize() const
|
|
|
|
{
|
|
|
|
return this->cache.maxCost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGALCache::setMaxSize(size_t limit)
|
|
|
|
{
|
|
|
|
this->cache.setMaxCost(limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGALCache::clear()
|
|
|
|
{
|
|
|
|
cache.clear();
|
|
|
|
}
|
|
|
|
|
2011-09-11 13:07:18 +04:00
|
|
|
void CGALCache::print()
|
|
|
|
{
|
2012-01-25 06:11:12 +04:00
|
|
|
PRINTB("CGAL Polyhedrons in cache: %d", this->cache.size());
|
|
|
|
PRINTB("CGAL cache size in bytes: %d", this->cache.totalCost());
|
2011-09-11 13:07:18 +04:00
|
|
|
}
|