Vaucanson  1.4.1
fsm_dump.hxx
1 // fsm_dump.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_TOOLS_FSM_DUMP_HXX
18 # define VCSN_TOOLS_FSM_DUMP_HXX
19 
21 # include <map>
22 # include <set>
23 # include <vaucanson/automata/concept/handlers.hh>
24 # include <vaucanson/misc/usual_macros.hh>
25 # include <vaucanson/automata/concept/automata_base.hh>
26 
27 namespace vcsn {
28 
29  namespace tools {
30 
31  /*---------.
32  | fsm_dump |
33  `---------*/
34  // Description :
35  // - Basic and non configurable pretty-printer in the 'fsm' format
36  //
37  // Constraints :
38  // - Every elements (series, state_content ...) must be printable
39  //
40  template <typename St, typename auto_t>
41  void fsm_dump(St& out, const auto_t& a)
42  {
43  AUTOMATON_TYPES(auto_t);
44  if (a.initial().size() > 1)
45  {
46  auto_t b(a);
47  hstate_t i = b.add_state();
48  for_all_initial_states(j, b)
49  b.add_spontaneous(i, *j);
50  b.clear_initial();
51  b.set_initial(i);
52  fsm_dump(out, b);
53  return ;
54  }
55  if (a.states().size() == 0)
56  return;
57 
58  typename auto_t::initial_iterator initial = a.initial().begin();
59 
60  for (delta_iterator e(a.value(), *initial); ! e.done(); e.next())
61  out << *initial << "\t" << a.dst_of(*e) << "\t"
62  << a.series_of(*e) << "\t 0"
63  << std::endl;
64  for_all_states(s, a)
65  if (!a.is_initial(*s))
66  {
67  for (delta_iterator e(a.value(), *s); ! e.done(); e.next())
68  out << *s << "\t" << a.dst_of(*e) << "\t"
69  << a.series_of(*e) << "\t 0"
70  << std::endl;
71  }
72  for_all_final_states(f, a)
73  out << *f << "\t 0" << std::endl;
74  }
75 
76  } // tools
77 
78 } // vcsn
79 
80 #endif // ! VCSN_TOOLS_FSM_DUMP_HXX