diff options
author | Marius Kintel <marius@kintel.net> | 2010-04-12 00:16:36 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2010-10-31 00:42:35 (GMT) |
commit | e8e213b3c9ce0580045ea6e7e86b00ab41d4c58b (patch) | |
tree | cb32e67b6334aa1f1dc62aa4a0686a22782e7f77 /src/nodedumper.cc | |
parent | 53a9953b7dc4ab4a366046c91529b32fb6652551 (diff) |
Another refactoring session:
o mk_cache_id() obsoleted by removing the node index from the dump
o node index output removed from each node and make optional in NodeDumper
o The visitors are no longer global, but associated with a tree
o Added Tree class to manage node trees and the (now implicit) dump cache
o Moved PolySet cache into PolySetRenderer
Diffstat (limited to 'src/nodedumper.cc')
-rw-r--r-- | src/nodedumper.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/src/nodedumper.cc b/src/nodedumper.cc index a62ad98..7d0c850 100644 --- a/src/nodedumper.cc +++ b/src/nodedumper.cc @@ -10,21 +10,31 @@ #include <iostream> #include <assert.h> -// For compatibility with old dump() output -#define NODEDUMPER_COMPAT_MODE +// For compatibility with old dump() output. +// FIXME: Only needed for testing. +//#define NODEDUMPER_COMPAT_MODE #ifdef NODEDUMPER_COMPAT_MODE #include "dxflinextrudenode.h" #include "dxfrotextrudenode.h" #include "projectionnode.h" #endif -NodeDumper *NodeDumper::global_dumper = NULL; +/*! + \class NodeDumper + + A visitor responsible for creating a text dump of a node tree. Also + contains a cache for fast retrieval of the text representation of + any node or subtree. +*/ -bool NodeDumper::isCached(const AbstractNode &node) +bool NodeDumper::isCached(const AbstractNode &node) const { return !this->cache[node].empty(); } +/*! + Indent or deindent. Must be called before we output any children. +*/ void NodeDumper::handleIndent(const State &state) { if (state.isPrefix()) { @@ -36,6 +46,11 @@ void NodeDumper::handleIndent(const State &state) } } +/*! + Dumps the block of children contained in this->visitedchildren, + including braces and indentation. + All children are assumed to be cached already. + */ string NodeDumper::dumpChildren(const AbstractNode &node) { std::stringstream dump; @@ -45,7 +60,7 @@ string NodeDumper::dumpChildren(const AbstractNode &node) for (ChildList::const_iterator iter = this->visitedchildren[node.index()].begin(); iter != this->visitedchildren[node.index()].end(); iter++) { -// FIXME: assert that cache contains **iter + assert(isCached(**iter)); dump << this->cache[**iter] << "\n"; } @@ -65,14 +80,20 @@ string NodeDumper::dumpChildren(const AbstractNode &node) return dump.str(); } - +/*! + Called for each node in the tree. + Will abort traversal if we're cached +*/ Response NodeDumper::visit(const State &state, const AbstractNode &node) { if (isCached(node)) return PruneTraversal; - else handleIndent(state); + + handleIndent(state); if (state.isPostfix()) { std::stringstream dump; - dump << this->currindent << node; + dump << this->currindent; + if (this->idprefix) dump << "n" << node.index() << ":"; + dump << node; dump << dumpChildren(node); this->cache.insert(node, dump.str()); } @@ -81,13 +102,6 @@ Response NodeDumper::visit(const State &state, const AbstractNode &node) return ContinueTraversal; } -const string &NodeDumper::getDump() const -{ - assert(this->root); -// FIXME: assert that cache contains root - return this->cache[*this->root]; -} - /*! Adds this given node to its parent's child list. Should be called for all nodes, including leaf nodes. |