Euphoria
dotoutput.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 
5 
6 
7 namespace eu::core::dot
8 {
9 
10 
11 enum class NodeId : int {};
12 
13 struct Node
14 {
16  std::string label;
17 };
18 
19 struct Edge
20 {
23 };
24 
25 struct Graph
26 {
27  std::vector<Node> nodes;
28  std::vector<Edge> edges;
29 
30  Node* add_new_node(const std::string& name);
31  Edge* add_new_edge(NodeId from, NodeId to);
32 
33  void print();
34 };
35 
36 
37 template
38 <
39  typename T,
40  typename TLabelFunc,
41  typename TFindChildrenFunc
42 >
43 NodeId
45 (
46  const T& item,
47  TLabelFunc label_function,
48  TFindChildrenFunc find_children_function,
49  Graph* graph
50 )
51 {
52  const auto label = label_function(item);
53  const auto self_node = graph->add_new_node(label)->id;
54 
55  const auto children = find_children_function(item);
56  for (auto it = children.begin(); it != children.end(); ++it)
57  {
58  const auto child_node = fill_graph<T, TLabelFunc, TFindChildrenFunc>
59  (
60  *it,
61  label_function,
62  find_children_function,
63  graph
64  );
65 
66  graph->add_new_edge(self_node, child_node);
67  }
68 
69  return self_node;
70 }
71 
72 
73 template
74 <
75  typename T,
76  typename TLabelFunc,
77  typename TFindChildrenFunc
78 >
79 Graph
81 (
82  const T& item,
83  TLabelFunc label_function,
84  TFindChildrenFunc find_children_function
85 )
86 {
87  Graph graph;
88 
89  fill_graph<T, TLabelFunc, TFindChildrenFunc>
90  (
91  item,
92  label_function,
93  find_children_function,
94  &graph
95  );
96 
97  return graph;
98 }
99 
100 }
NodeId fill_graph(const T &item, TLabelFunc label_function, TFindChildrenFunc find_children_function, Graph *graph)
Definition: dotoutput.h:45
Graph create_graph(const T &item, TLabelFunc label_function, TFindChildrenFunc find_children_function)
Definition: dotoutput.h:81
std::vector< Node > nodes
Definition: dotoutput.h:27
Node * add_new_node(const std::string &name)
Definition: dotoutput.cc:14
Edge * add_new_edge(NodeId from, NodeId to)
Definition: dotoutput.cc:28
std::vector< Edge > edges
Definition: dotoutput.h:28
std::string label
Definition: dotoutput.h:16