TreeDebugView.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "TextDebugView.hpp"
4 #include <unordered_set>
5 
6 namespace iv
7 {
8 
14 {
15 public:
16  enum class Style
17  {
20  };
21 
22  enum class BoxStyle
23  {
24  Solid,
25  Dotted,
26 
27  Default = Solid
28  };
29 
30 public:
32 
33  void Push( const char * node_name, BoxStyle box_style = BoxStyle::Default );
34  void Pop();
35 
36  void Separator();
37 
38  void Write( Style style, TextDebugView * target );
39  void Clear();
40 
41 protected:
42  virtual void print_line( const char * prefix, const char * line, const char * postfix ) override;
43 
44 private:
45  struct Node
46  {
47  Node * parent;
48  std::string name;
49  BoxStyle box_style;
50 
51  std::vector< std::string > lines;
52  std::vector< Node * > children;
53  std::unordered_set< size_t > separators;
54 
55  Node( Node * parent, const char * name, BoxStyle box_style ) :
56  parent( parent ),
57  name( name ),
58  box_style( box_style )
59  {
60  }
61 
62  ~Node()
63  {
64  for( Node * n : children )
65  delete n;
66  }
67 
68  Node( Node const & ) = delete;
69  Node( Node && ) = delete;
70 
71  Node & operator=( Node const & ) = delete;
72  Node & operator=( Node && ) = delete;
73  };
74 
75  void draw_node_children( Style style, TextDebugView * target, Node * node );
76 
77 private:
78  Node root;
79  Node * current;
80 };
81 
82 }