fsm_dump.hxx

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       std::set<htransition_t> succ;
00060 
00061       a.deltac(succ, *initial, delta_kind::transitions());
00062       for_all_const_(std::set<htransition_t>, e, succ)
00063         out << *initial << "\t" << a.dst_of(*e) << "\t"
00064             << a.series_of(*e) << "\t 0"
00065             << std::endl;
00066       for_all_states(s, a)
00067         if (!a.is_initial(*s))
00068         {
00069           succ.clear();
00070           a.deltac(succ, *s, delta_kind::transitions());
00071           for_all_const_(std::set<htransition_t>, e, succ)
00072             out << *s << "\t" << a.dst_of(*e) << "\t"
00073                 << a.series_of(*e) << "\t 0"
00074                 << std::endl;
00075         }
00076       for_all_final_states(f, a)
00077         out << *f << "\t 0" << std::endl;
00078     }
00079 
00080   } // tools
00081 
00082 } // vcsn
00083 
00084 #endif // ! VCSN_TOOLS_FSM_DUMP_HXX

Generated on Wed Jun 13 17:00:21 2007 for Vaucanson by  doxygen 1.5.1