Vaucanson 1.4
|
00001 // fsm_dump.hxx: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2001, 2002, 2004, 2005, 2006 The Vaucanson Group. 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // The complete GNU General Public Licence Notice can be found as the 00013 // `COPYING' file in the root directory. 00014 // 00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 #ifndef VCSN_TOOLS_FSM_DUMP_HXX 00018 # define VCSN_TOOLS_FSM_DUMP_HXX 00019 00020 # include <vaucanson/tools/fsm_dump.hh> 00021 # include <map> 00022 # include <set> 00023 # include <vaucanson/automata/concept/handlers.hh> 00024 # include <vaucanson/misc/usual_macros.hh> 00025 # include <vaucanson/automata/concept/automata_base.hh> 00026 00027 namespace vcsn { 00028 00029 namespace tools { 00030 00031 /*---------. 00032 | fsm_dump | 00033 `---------*/ 00034 // Description : 00035 // - Basic and non configurable pretty-printer in the 'fsm' format 00036 // 00037 // Constraints : 00038 // - Every elements (series, state_content ...) must be printable 00039 // 00040 template <typename St, typename auto_t> 00041 void fsm_dump(St& out, const auto_t& a) 00042 { 00043 AUTOMATON_TYPES(auto_t); 00044 if (a.initial().size() > 1) 00045 { 00046 auto_t b(a); 00047 hstate_t i = b.add_state(); 00048 for_all_initial_states(j, b) 00049 b.add_spontaneous(i, *j); 00050 b.clear_initial(); 00051 b.set_initial(i); 00052 fsm_dump(out, b); 00053 return ; 00054 } 00055 if (a.states().size() == 0) 00056 return; 00057 00058 typename auto_t::initial_iterator initial = a.initial().begin(); 00059 00060 for (delta_iterator e(a.value(), *initial); ! e.done(); e.next()) 00061 out << *initial << "\t" << a.dst_of(*e) << "\t" 00062 << a.series_of(*e) << "\t 0" 00063 << std::endl; 00064 for_all_states(s, a) 00065 if (!a.is_initial(*s)) 00066 { 00067 for (delta_iterator e(a.value(), *s); ! e.done(); e.next()) 00068 out << *s << "\t" << a.dst_of(*e) << "\t" 00069 << a.series_of(*e) << "\t 0" 00070 << std::endl; 00071 } 00072 for_all_final_states(f, a) 00073 out << *f << "\t 0" << std::endl; 00074 } 00075 00076 } // tools 00077 00078 } // vcsn 00079 00080 #endif // ! VCSN_TOOLS_FSM_DUMP_HXX