summaryrefslogtreecommitdiff
path: root/src/PolySetEvaluator.cc
diff options
context:
space:
mode:
authorDon Bright <hugh.m.bright@gmail.com>2011-09-12 22:40:51 (GMT)
committerDon Bright <hugh.m.bright@gmail.com>2011-09-12 22:40:51 (GMT)
commitf5f06c8e976ca45aebea42fe8c04bf7404357ac8 (patch)
tree8d0cdd2698e7806c1b12cc49e743b561e1082961 /src/PolySetEvaluator.cc
parent007c40848db9efd704694f2e7596cabed80da50f (diff)
parent5ac9162f1c67fd21737ead11d7ebc638bf4eef5f (diff)
merge
Merge remote branch 'upstream/visitor' into visitortests Conflicts: src/export.cc src/openscad.cc src/polyset.cc src/transform.cc tests/CMakeLists.txt tests/FindGLEW.cmake tests/csgtermtest.cc
Diffstat (limited to 'src/PolySetEvaluator.cc')
-rw-r--r--src/PolySetEvaluator.cc31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/PolySetEvaluator.cc b/src/PolySetEvaluator.cc
index 56acb1d..1f09127 100644
--- a/src/PolySetEvaluator.cc
+++ b/src/PolySetEvaluator.cc
@@ -1,15 +1,32 @@
+#include "PolySetCache.h"
#include "PolySetEvaluator.h"
#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.
+*/
-PolySetEvaluator::cache_entry::~cache_entry()
+/*!
+ 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)
{
- ps->unlink();
+ std::string cacheid = this->tree.getIdString(node);
+
+ if (PolySetCache::instance()->contains(cacheid)) {
+// For cache debugging
+// PRINTF("Cache hit: %s", cacheid.substr(0, 40).c_str());
+ return PolySetCache::instance()->get(cacheid);
+ }
+
+ shared_ptr<PolySet> ps(node.evaluate_polyset(this));
+ if (cache) PolySetCache::instance()->insert(cacheid, ps);
+ return ps;
}
contact: Jan Huwald // Impressum