summaryrefslogtreecommitdiff
path: root/src/PolySetEvaluator.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-11 05:37:14 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-11 05:37:14 (GMT)
commit9afeded46c0e9023002dc04ba6131adcb39762b1 (patch)
tree0096a12ce36a5b39aa18d7ec5da45c05eb3d42dd /src/PolySetEvaluator.cc
parentb087e68e5430c3dde6adfe452becbaba0f680196 (diff)
parentdc7eeb30d06a928a30ee47a765be3e5a61288d35 (diff)
Merge branch 'polyset-cleanup' into visitor
Diffstat (limited to 'src/PolySetEvaluator.cc')
-rw-r--r--src/PolySetEvaluator.cc37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc
index 56acb1d..a2bdca5 100644
--- a/src/PolySetEvaluator.cc
+++ b/src/PolySetEvaluator.cc
@@ -2,14 +2,41 @@
#include "printutils.h"
#include "polyset.h"
-PolySetEvaluator *PolySetEvaluator::global_evaluator = NULL;
+/*!
+ The task of PolySetEvaluator is to create, keep track of and cache PolySet instances.
-PolySetEvaluator::cache_entry::cache_entry(PolySet *ps) :
- ps(ps), msg(print_messages_stack.last())
+ All instances of PolySet which are not strictly temporary should be requested through this
+ class.
+*/
+
+QCache<std::string, PolySetEvaluator::cache_entry> PolySetEvaluator::cache(100000);
+
+/*!
+ Factory method returning a PolySet from the given node. If the
+ node is already cached, the cached PolySet will be returned
+ otherwise a new PolySet will be created from the node. If cache is
+ true, the newly created PolySet will be cached.
+ */
+shared_ptr<PolySet> PolySetEvaluator::getPolySet(const AbstractNode &node, bool cache)
+{
+ std::string cacheid = this->tree.getString(node);
+ if (this->cache.contains(cacheid)) {
+ PRINTF("Cache hit: %s", cacheid.substr(0, 40).c_str());
+ return this->cache[cacheid]->ps;
+ }
+
+ shared_ptr<PolySet> ps(node.evaluate_polyset(this));
+ if (cache) this->cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0);
+ return ps;
+}
+
+PolySetEvaluator::cache_entry::cache_entry(const shared_ptr<PolySet> &ps) : ps(ps)
{
+ if (print_messages_stack.size() > 0) this->msg = print_messages_stack.last();
}
-PolySetEvaluator::cache_entry::~cache_entry()
+void PolySetEvaluator::printCache()
{
- ps->unlink();
+ PRINTF("PolySets in cache: %d", cache.size());
+ PRINTF("Polygons in cache: %d", cache.totalCost());
}
contact: Jan Huwald // Impressum