openscad/src/Tree.cc

32 lines
785 B
C++
Raw Normal View History

#include "Tree.h"
#include "nodedumper.h"
#include <assert.h>
#include <algorithm>
2010-11-06 18:04:03 +03:00
/*!
Returns the cached string representation of the subtree rooted by \a node.
2010-11-06 18:04:03 +03:00
If node is not cached, the cache will be rebuilt.
*/
const std::string &Tree::getString(const AbstractNode &node) const
{
assert(this->root_node);
if (!this->nodecache.contains(node)) {
NodeDumper dumper(this->nodecache, false);
Traverser trav(dumper, *this->root_node, Traverser::PRE_AND_POSTFIX);
trav.execute();
assert(this->nodecache.contains(*this->root_node) &&
"NodeDumper failed to create a cache");
}
return this->nodecache[node];
}
2010-11-06 18:04:03 +03:00
/*!
Sets a new root. Will clear the existing cache.
*/
void Tree::setRoot(const AbstractNode *root)
{
this->root_node = root;
this->nodecache.clear();
}