17 template <
typename ExpSet>
19 :
public ExpSet::const_visitor
23 using super_t =
typename expressionset_t::const_visitor;
33 using node_t =
typename super_t::node_t;
36 template <type_t Type>
38 template <type_t Type>
40 template <type_t Type>
44 constexpr
static const char*
me() {
return "dot_printer"; }
53 bool physical =
false)
65 template <
typename OtherExpSet>
79 template <
typename OtherExpSet>
88 add_ = (
rs_.identities().is_distributive() ?
" \\oplus "
96 one_ =
"\\varepsilon";
103 zero_ =
"\\emptyset";
142 raise(
"expression: invalid format: ",
fmt_);
150 <<
"edge [arrowhead = vee, arrowsize = .6]" <<
vcsn::iendl
151 <<
"node [shape = circle, style = rounded, width = 0.5]\n";
193 template <
bool = context_t::is_lat,
194 typename Dummy =
void>
202 const auto&
r = std::get<I>(v.sub());
204 auto name = printer.
print_(r);
206 <<
name_ <<
" -> " << name;
210 template <
size_t... I>
213 using swallow =
int[];
231 print_(v, labelset_t::indices);
240 template <
typename Dummy>
257 template <
typename Node>
258 std::pair<name_t, bool>
name_(
const Node& n)
262 auto p =
names_->emplace(&n, 0);
264 p.first->second =
names_->size();
265 return {p.first->second, p.second};
268 return {(*count_)++,
true};
272 template <rat::exp::type_t Type>
273 void print_(
const constant_t<Type>& n,
const char* op)
275 auto name =
name_(n);
279 <<
" [label=\"" << op <<
"\"]";
285 template <rat::exp::type_t Type>
286 void print_(
const unary_t<Type>& n,
const char* op)
288 auto name =
name_(n);
291 auto sub =
print_(n.sub());
293 << name.first <<
" [label=\"" << op <<
"\"]"
295 << name.first <<
" -> " << sub;
301 template <rat::exp::type_t Type>
302 void print_(
const variadic_t<Type>& n,
const char* op)
304 auto name =
name_(n);
309 [
this](
const auto& i)
314 << name.first <<
" [label=\"" << op <<
"\"]";
317 << name.first <<
" -> " << s;
327 <<
res <<
" [label=\"";
336 auto name =
name_(n);
340 auto sub =
print_(n.sub());
344 << name.first <<
" -> " << sub;
352 auto name =
name_(n);
355 auto sub =
print_(n.sub());
360 << name.first <<
" -> " <<
weight;
368 auto name =
name_(n);
372 out_ << name.first <<
" [label=\"";
391 using names_t = std::unordered_map<const void*, name_t>;
393 std::shared_ptr<names_t>
names_ = std::make_shared<names_t>();
397 std::shared_ptr<unsigned>
count_ = std::make_shared<unsigned>(0);
425 template <
typename ExpSet>
428 bool physical =
false)
430 return {
rs,
out, physical};
dot_printer(const expressionset_t &rs, dot_printer< OtherExpSet > &other)
Construct from another dot_printer.
context_t_of< expressionset_t > context_t
value_impl< detail::weight_tag > weight
void print_(const unary_t< Type > &n, const char *op)
Print a unary node.
dot_printer< ExpSet > make_dot_printer(const ExpSet &rs, std::ostream &out, bool physical=false)
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
name_t print_(const value_t &v)
Easy recursion: print an expression and return its ID.
void operator()(const tuple_t &)
format for_labels() const
A copy of this format, but to print labels.
#define BUILTIN_UNREACHABLE()
name_t name_
The name of the tuple node.
void visit(const tuple_t &v, std::true_type) override
std::ostream & incendl(std::ostream &o)
Increment the indentation, print an end of line, and set the indentation.
std::unordered_map< const void *, name_t > names_t
If physical_ is enabled, register the identifiers of the nodes.
const expressionset_t & rs_
The expressionset.
void print_(const atom_t &n)
Print a label.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
name_t last_name_
The name of the last visited node.
class format fmt_
Output format.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
std::ostream & iendl(std::ostream &o)
Print an end of line, then set the indentation.
static constexpr const char * me()
Name of this algorithm, for error messages.
void print_(const variadic_t< Type > &n, const char *op)
Print a variadic node.
typename super_t::template variadic_t< Type > variadic_t
void print_(const tuple_t &v, detail::index_sequence< I... >)
Print all the tapes.
std::ostream & decendl(std::ostream &o)
Decrement the indentation, print an end of line, and set the indentation.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
An inner node implementing a weight.
VCSN_RAT_VISIT(infiltrate, v)
labelset_t_of< context_t > labelset_t
typename expressionset_t::identities_t identities_t
typename expressionset_t::const_visitor super_t
VCSN_RAT_VISIT(ldivide, v)
const char * conjunction_
const char * add_
The expression operators.
void print_(const lweight_t &n)
Print a left-weight.
const char * tuple_
Tuple tape separator.
bool physical_
Whether to display the physical DAG rather than the logical tree.
friend class dot_printer
Make it possible to view members from dot_printer's with a different template parameter.
typename super_t::template unary_t< Type > unary_t
VCSN_RAT_VISIT(shuffle, v)
std::ostream & out_
Output stream.
VCSN_RAT_VISIT(transposition, v)
const char * transposition_
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
typename super_t::template constant_t< Type > constant_t
An input/output format for valuesets.
unsigned name_t
A type to label the node.
VCSN_RAT_VISIT(compose, v)
void print_(const constant_t< Type > &n, const char *op)
Print a nullary node.
Indentation relative functions.
VCSN_RAT_VISIT(complement, v)
typename super_t::tuple_t tuple_t
name_t print_(const node_t &v)
Easy recursion: print an expression and return its ID.
weight_t_of< context_t > weight_t
typename node_t::value_t value_t
A shared_ptr to node_t.
Pretty-printer for rational expressions.
Pretty-printer for rational expressions.
const char * lweight_
External product.
const char * ldivide_
Quotient.
Print as rich UTF-8 text, escaped.
VCSN_RAT_VISIT(rweight, v)
std::ostream & operator()(const value_t &v)
Entry point: print v as a complete Dot graph.
dot_printer(const expressionset_t &rs, std::ostream &out, bool physical=false)
A printer.
VCSN_RAT_VISIT(conjunction, v)
void print_(const tuple_t &v)
Print one tape.
std::pair< name_t, bool > name_(const Node &n)
The identifier for this node, and a Boolean stating whether we should traverse (again) this node...
An inner node with multiple children.
name_t print_(const weight_t &w)
Print a weight.
const char * zero_
The constants.
auto transform(const Container &c, Fun &&fun)
Map a unary function on a container of values, and return the vector the results. ...
Provide a variadic mul on top of a binary mul(), and one().
Print as plain (ASCII) text, escaped.
VCSN_RAT_VISIT(lweight, v)
std::shared_ptr< names_t > names_
A shared_ptr, to support tuples.
std::shared_ptr< unsigned > count_
The node counter, used to name the nodes.
void operator()(const tuple_t &v)
Entry point.
void format(format fmt)
Set output format.
typename super_t::node_t node_t
Actual node, without indirection.
void print_(const rweight_t &n)
Print a right-weight.
format for_weights() const
A copy of this format, but to print weights.
label_t_of< context_t > label_t