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 <
typename =
void>
201 const auto&
r = std::get<I>(v.sub());
203 auto name = printer.
print_(r);
205 <<
name_ <<
" -> " << name;
209 template <
size_t... I>
212 using swallow =
int[];
230 print_(v, labelset_t::indices);
241 detail::static_if<context_t::is_lat>
248 template <
typename Node>
249 std::pair<name_t, bool>
name_(
const Node& n)
253 auto p =
names_->emplace(&n, 0);
255 p.first->second =
names_->size();
256 return {p.first->second, p.second};
259 return {(*count_)++,
true};
263 template <rat::exp::type_t Type>
264 void print_(
const constant_t<Type>& n,
const char* op)
266 auto name =
name_(n);
271 <<
" [label=\"" << op <<
"\"]";
277 template <rat::exp::type_t Type>
278 void print_(
const unary_t<Type>& n,
const char* op)
280 auto name =
name_(n);
283 auto sub =
print_(n.sub());
285 << name.first <<
" [label=\"" << op <<
"\"]"
287 << name.first <<
" -> " << sub;
293 template <rat::exp::type_t Type>
294 void print_(
const variadic_t<Type>& n,
const char* op)
296 auto name =
name_(n);
301 [
this](
const auto& i)
306 << name.first <<
" [label=\"" << op <<
"\"]";
309 << name.first <<
" -> " << s;
319 <<
res <<
" [label=\"";
328 auto name =
name_(n);
332 auto sub =
print_(n.sub());
337 << name.first <<
" -> " << sub;
345 auto name =
name_(n);
348 auto sub =
print_(n.sub());
354 << name.first <<
" -> " <<
weight;
362 auto name =
name_(n);
366 << name.first <<
" [label=\"";
385 using names_t = std::unordered_map<const void*, name_t>;
387 std::shared_ptr<names_t>
names_ = std::make_shared<names_t>();
391 std::shared_ptr<unsigned>
count_ = std::make_shared<unsigned>(0);
419 template <
typename ExpSet>
422 bool physical =
false)
424 return {
rs,
out, physical};
typename super_t::node_t node_t
Actual node, without indirection.
class format fmt_
Output format.
static constexpr const char * me()
Name of this algorithm, for error messages.
dot_printer(const expressionset_t &rs, dot_printer< OtherExpSet > &other)
Construct from another dot_printer.
context_t_of< expressionset_t > context_t
void print_(const unary_t< Type > &n, const char *op)
Print a unary node.
name_t print_(const value_t &v)
Easy recursion: print an expression and return its ID.
format for_labels() const
A copy of this format, but to print labels.
const char * zero_
The constants.
VCSN_RAT_VISIT(lweight, v)
value_impl< detail::weight_tag > weight
std::shared_ptr< unsigned > count_
The node counter, used to name the nodes.
const expressionset_t & rs_
The expressionset.
std::ostream & decendl(std::ostream &o)
Decrement the indentation, print an end of line, and set the indentation.
An inner node implementing a weight.
void print_(const atom_t &n)
Print a label.
Pretty-printer for rational expressions.
void operator()(const tuple_t &v)
Entry point.
VCSN_RAT_VISIT(ldivide, v)
An input/output format for valuesets.
name_t last_name_
The name of the last visited node.
Provide a variadic mul on top of a binary mul(), and one().
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
VCSN_RAT_VISIT(shuffle, v)
VCSN_RAT_VISIT(transposition, v)
typename super_t::template variadic_t< Type > variadic_t
typename expressionset_t::identities_t identities_t
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Pretty-printer for rational expressions.
const char * add_
The expression operators.
void visit(const tuple_t &v, std::true_type) override
void print_(const lweight_t &n)
Print a left-weight.
std::unordered_map< const void *, name_t > names_t
If physical_ is enabled, register the identifiers of the nodes.
void print_(const constant_t< Type > &n, const char *op)
Print a nullary node.
VCSN_RAT_VISIT(infiltrate, v)
labelset_t_of< context_t > labelset_t
friend class dot_printer
Make it possible to view members from dot_printer's with a different template parameter.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
typename expressionset_t::const_visitor super_t
const char * conjunction_
Print as rich UTF-8 text, escaped.
auto transform(const Container &c, Fun &&fun)
Map a unary function on a container of values, and return the vector the results. ...
void print_(const variadic_t< Type > &n, const char *op)
Print a variadic node.
std::ostream & operator()(const value_t &v)
Entry point: print v as a complete Dot graph.
bool physical_
Whether to display the physical DAG rather than the logical tree.
Print as plain (ASCII) text, escaped.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
VCSN_RAT_VISIT(conjunction, v)
std::ostream & iendl(std::ostream &o)
Print an end of line, then set the indentation.
const char * transposition_
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.
dot_printer< ExpSet > make_dot_printer(const ExpSet &rs, std::ostream &out, bool physical=false)
typename super_t::template constant_t< Type > constant_t
void print_(const tuple_t &v)
Print one tape.
unsigned name_t
A type to label the node.
VCSN_RAT_VISIT(compose, v)
const char * tuple_
Tuple tape separator.
An inner node with multiple children.
std::shared_ptr< names_t > names_
A shared_ptr, to support tuples.
dot_printer(const expressionset_t &rs, std::ostream &out, bool physical=false)
A printer.
std::ostream & incendl(std::ostream &o)
Increment the indentation, print an end of line, and set the indentation.
name_t name_
The name of the tuple node.
Indentation relative functions.
format for_weights() const
A copy of this format, but to print weights.
label_t_of< context_t > label_t
typename super_t::template unary_t< Type > unary_t
std::ostream & out_
Output stream.
name_t print_(const weight_t &w)
Print a weight.
VCSN_RAT_VISIT(complement, v)
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename super_t::tuple_t tuple_t
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...
void format(format fmt)
Set output format.
void print_(const rweight_t &n)
Print a right-weight.
const char * lweight_
External product.
const char * ldivide_
Quotient.
void print_(const tuple_t &v, detail::index_sequence< I... >)
Print all the tapes.
VCSN_RAT_VISIT(rweight, v)