diff options
author | Marius Kintel <marius@kintel.net> | 2011-09-09 03:53:05 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-09-09 03:53:05 (GMT) |
commit | cbba974d3ac1edeb716a1384a2262ed5447fa9e6 (patch) | |
tree | 30708ef085204435d644c4ab685b87556628d22a /src/PolySetEvaluator.cc | |
parent | 328897c1f28e0d438aa678891f8d5a45b114f267 (diff) |
Initial attempt of cleaning up polyset handling. PolySet no longer keeps a refcount, basic cache mechanism is in place, instantiating polysets are controlled through PolySetEvaluator
Diffstat (limited to 'src/PolySetEvaluator.cc')
-rw-r--r-- | src/PolySetEvaluator.cc | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc index 56acb1d..2808686 100644 --- a/src/PolySetEvaluator.cc +++ b/src/PolySetEvaluator.cc @@ -2,14 +2,31 @@ #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. +*/ + +PolySet *PolySetEvaluator::getPolySet(const AbstractNode &node) +{ + const string &cacheid = this->tree.getString(node); + if (this->cache.contains(cacheid)) return this->cache[cacheid]->ps; + + PolySet *ps = node.evaluate_polyset(this); + this->cache.insert(cacheid, new cache_entry(ps), ps?ps->polygons.size():0); + return ps; +} + +PolySetEvaluator::cache_entry::cache_entry(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", this->cache.size()); + PRINTF("Polygons in cache: %d", this->cache.totalCost()); } |