summaryrefslogtreecommitdiff
path: root/src/nodedumper.h
blob: aca17edb38e87a8229b8e21a47ce3d1e0e6ca0b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef NODEDUMPER_H_
#define NODEDUMPER_H_

#include <string>
#include <map>
#include <list>
#include "visitor.h"
#include "nodecache.h"

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);
	std::string dumpChildren(const AbstractNode &node);

  NodeCache &cache;
	bool idprefix;

  std::string currindent;
  const AbstractNode *root;
  typedef std::list<const AbstractNode *> ChildList;
	std::map<int, ChildList> visitedchildren;
};

#endif
contact: Jan Huwald // Impressum