Ariles
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
graphviz.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4 
5  @copyright 2020 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7 
8  @brief
9 */
10 
11 /**
12 @defgroup graphviz Graphviz
13 
14 @brief Generates diagrams ('.dot' files) representing class contents.
15 
16 The following example is generated using classes defined in @ref ariles_diagram.h
17 @image html graphviz_example.svg
18 */
19 
20 
21 #pragma once
22 
23 #define ARILES2_VISITOR_INCLUDED_graphviz
24 
26 #include <ariles2/visitors/write.h>
27 
28 #include <string>
29 
30 
31 namespace ariles2
32 {
33  namespace ns_graphviz
34  {
35  namespace impl
36  {
37  class Visitor;
38  }
39 
40 
42  {
43  public:
45  {
46  public:
47  std::string id_;
48  std::string label_;
49  std::string options_;
50 
51  public:
53  {
54  id_ = "";
55  label_ = "";
56  options_ = "";
57  }
58 
59  NodeOptions(const std::string &id)
60  {
61  id_ = id;
62  label_ = id_;
63  options_ = "";
64  }
65 
66  NodeOptions(const std::string &id, const std::string &label)
67  {
68  id_ = id;
69  label_ = label;
70  options_ = "";
71  }
72 
73  NodeOptions(const std::string &id, const std::string &label, const std::string &options)
74  {
75  id_ = id;
76  label_ = label;
77  options_ = options;
78  }
79  };
80 
81 
82  public:
83  std::string graph_options_;
84  std::string node_options_;
85 
86  public:
87  Parameters(const bool override_parameters = false) : write::Parameters(override_parameters)
88  {
89  graph_options_ = "rankdir=\"LR\"\n";
90  node_options_ = "";
91  sloppy_maps_ = true;
92  sloppy_pairs_ = true;
93  compact_arrays_ = true;
94  }
95 
96  virtual NodeOptions getDefaultNodeOptions(const std::string &id, const std::string &label) const
97  {
98  return (NodeOptions(id, label, node_options_));
99  }
100  virtual NodeOptions getArilesNodeOptions(const std::string &id, const std::string &label) const
101  {
102  return (NodeOptions(id, label, node_options_));
103  }
104  };
105 
106 
107  class Visitor : public serialization::PIMPLVisitor<write::VisitorBase<Visitor, Parameters>, impl::Visitor>
108  {
109  protected:
110  void startMap(const Parameters &, const Parameters::NodeOptions &);
111  std::string getDefaultNodeId() const;
112  std::string getDefaultNodeLabel() const;
113 
114 
115  public:
116  explicit Visitor(const std::string &file_name);
117  explicit Visitor(std::ostream &output_stream);
118 
119 
120  void flush();
121 
122  void startRoot(const std::string &name, const Parameters &);
123  void endRoot(const std::string &name);
124 
125  void startMap(const Parameters &, const std::size_t num_entries);
126  void startMapEntry(const std::string &map_name);
127  void endMapEntry();
128 
129  void startArray(const std::size_t size, const bool compact = false);
130  void endArrayElement();
131  void endArray();
132 
133 
134  template <class t_Entry>
135  void startMap(t_Entry &, const Parameters &parameters)
136  {
137  startMap(parameters, parameters.getArilesNodeOptions(getDefaultNodeId(), getDefaultNodeLabel()));
138  }
139 
141 
142 
143 #define ARILES2_BASIC_TYPE(type) void writeElement(const type &element, const Parameters &param);
144 
147 
148 #undef ARILES2_BASIC_TYPE
149  };
150 
151 
152  class Base : public entry::ConstBase<Visitor>
153  {
154  };
155 
156 
157 #define ARILES2_NAMED_ENTRY_graphviz(v, entry, name) visitor.visitMapEntry(entry, #name, parameters);
158 #define ARILES2_PARENT_graphviz(v, entry)
159 #define ARILES2_VISIT_graphviz \
160  template <class t_Visitor> \
161  void arilesVisit( \
162  t_Visitor &visitor, \
163  const typename t_Visitor::Parameters &parameters, \
164  ARILES2_IS_BASE_ENABLER(ariles2::graphviz::Visitor, t_Visitor)) const \
165  { \
166  CPPUT_TRACE_FUNCTION; \
167  CPPUT_UNUSED_ARG(visitor); \
168  CPPUT_UNUSED_ARG(parameters); \
169  arilesVisitParents(visitor, parameters); \
170  ARILES2_ENTRIES(graphviz) \
171  }
172 
173 #define ARILES2_METHODS_graphviz ARILES2_METHODS(graphviz, ARILES2_EMPTY_MACRO, const)
174 #define ARILES2_BASE_METHODS_graphviz ARILES2_BASE_METHODS(graphviz)
175  } // namespace ns_graphviz
176 } // namespace ariles2
177 
178 
179 namespace ariles2
180 {
181  /**
182  * @brief Graphviz visitor.
183  * @ingroup graphviz
184  */
185  struct graphviz
186  {
191  };
192 
193  /// @ingroup graphviz
195 } // namespace ariles2
NodeOptions(const std::string &id, const std::string &label)
Definition: graphviz.h:66
NodeOptions(const std::string &id, const std::string &label, const std::string &options)
Definition: graphviz.h:73
virtual NodeOptions getDefaultNodeOptions(const std::string &id, const std::string &label) const
Definition: graphviz.h:96
virtual NodeOptions getArilesNodeOptions(const std::string &id, const std::string &label) const
Definition: graphviz.h:100
Parameters(const bool override_parameters=false)
Definition: graphviz.h:87
std::string getDefaultNodeId() const
Definition: writer.cpp:186
void startMap(t_Entry &, const Parameters &parameters)
Definition: graphviz.h:135
std::string getDefaultNodeLabel() const
Definition: writer.cpp:195
void startRoot(const std::string &name, const Parameters &)
Definition: writer.cpp:160
void startMap(const Parameters &, const Parameters::NodeOptions &)
Definition: writer.cpp:204
void startMapEntry(const std::string &map_name)
Starts a nested map in the configuration file.
Definition: writer.cpp:225
void flush()
Flush the configuration to the output.
Definition: writer.cpp:154
void startArray(const std::size_t size, const bool compact=false)
Definition: writer.cpp:251
void endRoot(const std::string &name)
Definition: writer.cpp:180
bool sloppy_pairs_
Treat key values in maps as entry names if they are strings.
Definition: serialization.h:30
#define ARILES2_COMPLEX_NUMBER_TYPES_LIST
Definition: helpers.h:68
#define ARILES2_BASIC_TYPES_LIST
Definition: helpers.h:72
#define CPPUT_MACRO_SUBSTITUTE(macro)
Definition: misc.h:21
entry::ConstBase< const Visitor > Base
Definition: count.h:46
visitor::Parameters Parameters
Definition: count.h:26
Definition: basic.h:17
Graphviz visitor.
Definition: graphviz.h:186
ns_graphviz::Visitor Visitor
Definition: graphviz.h:188