diff options
Diffstat (limited to 'src/nodedumper.h')
-rw-r--r-- | src/nodedumper.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nodedumper.h b/src/nodedumper.h new file mode 100644 index 0000000..efaf4fa --- /dev/null +++ b/src/nodedumper.h @@ -0,0 +1,40 @@ +#ifndef NODEDUMPER_H_ +#define NODEDUMPER_H_ + +#include <string> +#include <map> +#include <list> +#include "visitor.h" +#include "nodecache.h" + +using std::string; +using std::map; +using std::list; + +class NodeDumper : public Visitor +{ +public: + /*! If idPrefix is true, we will output "n<id>:" in front of each node, + which is useful for debugging. */ + NodeDumper(NodeCache &cache, bool idPrefix = false) : + cache(cache), idprefix(idPrefix), root(NULL) { } + virtual ~NodeDumper() {} + + virtual Response visit(State &state, const AbstractNode &node); + +private: + void handleVisitedChildren(const State &state, const AbstractNode &node); + bool isCached(const AbstractNode &node) const; + void handleIndent(const State &state); + string dumpChildren(const AbstractNode &node); + + NodeCache &cache; + bool idprefix; + + string currindent; + const AbstractNode *root; + typedef list<const AbstractNode *> ChildList; + map<int, ChildList> visitedchildren; +}; + +#endif |