17 #ifndef VCSN_TOOLS_DOT_FORMAT_HXX
18 # define VCSN_TOOLS_DOT_FORMAT_HXX
23 # include <vaucanson/tools/dot_format.hh>
24 # include <vaucanson/automata/concept/handlers.hh>
25 # include <vaucanson/misc/usual_macros.hh>
32 name_escaper(std::ostream& out,
const std::string& name)
34 for (std::string::const_iterator i = name.begin(); i != name.end(); ++i)
42 inline dot::dot(
const std::string& name)
44 std::ostringstream os;
45 name_escaper(os, name);
46 name_ = std::string(
"\"") + os.str();
49 template<
typename Saver,
typename Conv>
50 void dot::operator()(std::ostream& out,
const Saver& s,
51 const Conv& conv)
const
53 typedef typename Saver::automaton_t auto_t;
54 typedef typename auto_t::hstate_t hstate_t;
56 const auto_t& a = s.automaton();
58 std::map<hstate_t, unsigned> state_map;
60 out <<
"digraph vcsn {" << std::endl
61 <<
"label=\"" << name_.c_str() + 1 <<
' ' << a <<
"\";" << std::endl
62 <<
"node [shape=circle];" << std::endl;
64 for (
typename auto_t::state_iterator i = a.states().begin();
65 i != a.states().end();
68 unsigned c = state_map[*i] = count++;
72 <<
"\" [style=invis,label=\"\",width=.01,height=.01];"
74 << name_ << count <<
"\" -> " << name_ << c
75 <<
"\" [label=\"" << conv(a.structure(), a.get_initial(*i))
76 <<
"\"];" << std::endl;
82 <<
"\" [style=invis,label=\"\",width=.01,height=.01];"
84 << name_ << c <<
"\" -> " << name_ << count
85 <<
"\" [label=\""<< conv(a.structure(), a.get_final(*i))
86 <<
"\"];" << std::endl;
89 out << name_ << c <<
"\" [label=\"" << *i <<
"\"];" << std::endl;
91 for (
typename auto_t::transition_iterator i = a.transitions().begin();
92 i != a.transitions().end();
95 out << name_ << state_map[a.src_of(*i)]
97 << name_ << state_map[a.dst_of(*i)];
98 out <<
"\" [label=\"" << conv(a.structure(), a.series_of(*i))
99 <<
"\"];" << std::endl;
101 out <<
"}" << std::endl;
104 inline transducer_dot::transducer_dot(
const std::string& name)
106 std::ostringstream os;
107 name_escaper(os, name);
108 name_ = std::string(
"\"") + os.str();
111 template<
typename Saver,
typename Conv>
112 void transducer_dot::operator()(std::ostream& out,
const Saver& s,
113 const Conv& conv)
const
115 typedef typename Saver::automaton_t auto_t;
116 AUTOMATON_TYPES(auto_t);
117 const auto_t& a = s.automaton();
119 std::map<hstate_t, unsigned> state_map;
121 out <<
"digraph vcsn {" << std::endl
122 <<
"label=\"" << name_.c_str() + 1 <<
' ' << a <<
"\";" << std::endl
123 <<
"node [shape=circle];" << std::endl;
125 for (
typename auto_t::state_iterator i = a.states().begin();
126 i != a.states().end();
129 unsigned c = state_map[*i] = count++;
130 if (a.is_initial(*i))
132 out << name_ << count
133 <<
"\" [style=invis,label=\"\",width=.01,height=.01];"
135 << name_ << count <<
"\" -> " << name_ << c <<
'"';
136 std::ostringstream o;
137 series_set_elt_t ss = a.get_initial(*i);
138 if (ss.supp().begin() == ss.supp().end())
140 for_all_const_(series_set_elt_t::support_t, s, ss.supp())
142 monoid_elt_t x(a.structure().series().monoid(), *s);
143 o << conv(a.structure(), x) <<
"|" << ss.get(x) <<
" ";
145 out <<
"[label=\"" << o.str() <<
"\"];"
151 out << name_ << count
152 <<
"\" [style=invis,label=\"\",width=.01,height=.01];"
154 << name_ << c <<
"\" -> " << name_ << count <<
'"';
155 std::ostringstream o;
156 series_set_elt_t ss = a.get_final(*i);
157 if (ss.supp().begin() == ss.supp().end())
159 for_all_const_(series_set_elt_t::support_t, s, ss.supp())
161 monoid_elt_t x(a.structure().series().monoid(), *s);
162 o << conv(a.structure(), x) <<
"|" << ss.get(x) <<
" ";
164 out <<
"[label=\"" << o.str() <<
"\"];"
168 out << name_ << c <<
"\" [label=\"" << *i <<
"\"];" << std::endl;
170 for (
typename auto_t::transition_iterator i = a.transitions().begin();
171 i != a.transitions().end();
174 out << name_ << state_map[a.src_of(*i)]
176 << name_ << state_map[a.dst_of(*i)] <<
'"';
177 std::ostringstream o;
178 series_set_elt_t ss = a.series_of(*i);
179 if (ss.supp().begin() == ss.supp().end())
181 for_all_const_(series_set_elt_t::support_t, s, ss.supp())
183 monoid_elt_t x(a.structure().series().monoid(), *s);
184 o << conv(a.structure(), x) <<
"|" << ss.get(x) <<
" ";
186 out <<
"[label=\"" << o.str() <<
"\"];"
189 out <<
"}" << std::endl;
196 #endif // ! VCSN_TOOLS_DOT_FORMAT_HXX