libabigail
abg-viz-dot.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright (C) 2013-2023 Red Hat, Inc.
5 
6 /// @file
7 
8 #ifndef __ABG_VIZ_DOT_H__
9 #define __ABG_VIZ_DOT_H__
10 
11 #include <abg-viz-common.h>
12 
13 namespace abigail
14 {
15 
16 /// Base class for graph nodes.
17 struct node_base
18 {
19  /// Possible derived types.
20  enum type { child, parent };
21 
22  std::string _M_id;
23  static units_type _M_count_total; // Start at zero.
24  units_type _M_count;
25  type _M_type;
26  float _M_x_space; // Column spacing.
27  float _M_y_space; // Row spacing.
28  const style& _M_style;
29 
30  explicit
31  node_base(const std::string& __id, type __t, const style& __sty)
32  : _M_id(__id), _M_count(++_M_count_total),
33  _M_type(__t), _M_x_space(0.4), _M_y_space(0.2), _M_style(__sty)
34  { }
35 };
36 
37 /// Useful constants.
38 extern const style parent_sty;
39 extern const style child_sty;
40 
41 
42 /**
43  Parent node.
44 
45  Some characteristics:
46  - name (text anchor = start ie left).
47  - background box x and y size
48  - style info
49  - (optional) template parameters
50 
51  */
52 struct parent_node : public node_base
53 {
54  parent_node(const std::string& __id)
55  : node_base(__id, node_base::parent, parent_sty)
56  { }
57 };
58 
59 
60 /**
61  Child node.
62 
63  Some characteristics:
64  - horizontal name (text anchor = start ie left).
65  - background box
66  - (optional) template parameters
67 
68  */
69 struct child_node : public node_base
70 {
71  child_node(const std::string& __id)
72  : node_base(__id, node_base::child, child_sty)
73  { }
74 };
75 
76 
77 /**
78  DOT "graph" style notation for class inheritance.
79 
80  This is a compact DOT representation of a single class inheritance.
81 
82  It is composed of the following data points for each parent
83 
84  - parent classes
85  - child classes
86  - name
87 
88  Including typographic information to compute line length, and C++
89  niceities like grouping and overload sets.
90 
91  It's constructed by creating a digraph, starting from the base node.
92  */
93 struct dot
94 {
95 
96 private:
97 
98  const std::string _M_title;
99 
100  std::ostringstream _M_sstream;
101 
102 public:
103 
104  dot(const std::string &__title)
105  : _M_title(__title)
106  { }
107 
108  // Empty when the output buffer is.
109  bool
110  empty() { return _M_sstream.str().empty(); }
111 
112  void
113  start_element();
114 
115  void
116  finish_element();
117 
118  void
119  add_title();
120 
121  void
122  add_node(const node_base&);
123 
124  void
125  add_edge(const node_base&, const node_base&);
126 
127  void
128  add_parent(const parent_node&);
129 
130  void
131  add_child_to_node(const child_node&, const node_base&);
132 
133  void
134  write();
135 
136  void
137  start()
138  {
139  this->start_element();
140  }
141 
142  void
143  finish()
144  {
145  this->finish_element();
146  this->write();
147  }
148 };
149 
150 // XXX connect external xml file to input.
151 // parse input, pick apart elements, attributes.
152 
153 }// end namespace abigail
154 
155 #endif //__ABG_VIZ_DOT_H__
Toplevel namespace for libabigail.
const style parent_sty
Useful constants.
Definition: abg-viz-dot.cc:25
Base class for graph nodes.
Definition: abg-viz-dot.h:18
type
Possible derived types.
Definition: abg-viz-dot.h:20
Datum consolidating style preferences.