io.hh

00001 // io.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004 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_IO_HH
00018 # define VCSN_TOOLS_IO_HH
00019 
00020 # include <vaucanson/automata/concept/handlers.hh>
00021 # include <vaucanson/automata/concept/automata_base.hh>
00022 # include <vaucanson/automata/concept/transducer_base.hh>
00023 # include <iostream>
00024 # include <string>
00025 # include <map>
00026 
00027 namespace vcsn
00028 {
00029 
00030   namespace io
00031   {
00032 
00033     /*-------.
00034     | Output |
00035     `-------*/
00036 
00037     template<typename Auto, typename TransitionConverter, typename Format>
00038     struct automaton_saver_
00039     {
00040         typedef Auto automaton_t;
00041         typedef TransitionConverter transition_converter_t;
00042         typedef Format format_t;
00043 
00044         automaton_saver_(const Auto&, const TransitionConverter&, const Format&);
00045 
00046         automaton_t& automaton();
00047         const automaton_t& automaton() const;
00048 
00049       protected:
00050         const automaton_t& a_;
00051         transition_converter_t conv_;
00052         format_t format_;
00053 
00054         template<typename A, typename E, typename F>
00055         friend std::ostream&
00056         operator<<(std::ostream&, const automaton_saver_<A, E, F>&);
00057     };
00058 
00059 
00060     template<typename Auto, typename TransitionConverter, typename Format>
00061     std::ostream&
00062     operator<<(std::ostream&,
00063                const automaton_saver_<Auto, TransitionConverter, Format>&);
00064 
00065     struct string_out
00066     {
00067         std::string check_empty_word(const std::string&) const;
00068 
00069         template<typename S, typename T>
00070         std::string operator()(const AutomataBase<S>&, const T&) const;
00071 
00072         template<typename S, typename T>
00073         std::string operator()(const TransducerBase<S>&, const T&) const;
00074 
00075     };
00076 
00077   }
00078 
00079   template<typename Auto, typename TransitionConverter, typename Format>
00080   io::automaton_saver_<Auto, TransitionConverter, Format>
00081   automaton_saver(const Auto&,
00082                   const TransitionConverter& e = TransitionConverter(),
00083                   const Format& f = Format());
00084 
00085 
00086   namespace io
00087   {
00088     /*------.
00089     | Input |
00090     `------*/
00091 
00092     template<typename Auto, typename TransitionConverter, typename Format>
00093     struct automaton_loader_
00094     {
00095         typedef Auto automaton_t;
00096         typedef TransitionConverter transition_converter_t;
00097         typedef Format format_t;
00098 
00099         automaton_loader_(automaton_t& a,
00100                           const transition_converter_t& conv,
00101                           const format_t& format,
00102                           bool merge_states);
00103 
00104         automaton_t& automaton();
00105         const automaton_t& automaton() const;
00106 
00107         hstate_t add_state(unsigned);
00108         void set_initial(unsigned, const std::string&);
00109         void set_final(unsigned, const std::string&);
00110         void add_transition(unsigned, unsigned, const std::string&);
00111         void add_spontaneous(unsigned, unsigned);
00112 
00113       protected:
00114         automaton_t& a_;
00115         transition_converter_t conv_;
00116         format_t format_;
00117         unsigned scount_;
00118         std::map<unsigned, hstate_t> smap_;
00119         bool merge_states_;
00120 
00121         template<typename A, typename E, typename F>
00122         friend std::istream&
00123         operator>>(std::istream&, automaton_loader_<A, E, F>);
00124     };
00125 
00126     template<typename Auto, typename TransitionConverter, typename Format>
00127     std::istream&
00128     operator>>(std::istream&, automaton_loader_<Auto, TransitionConverter, Format>);
00129 
00130 
00131   }
00132 
00133 
00134   template<typename Auto, typename TransitionConverter, typename Format>
00135   io::automaton_loader_<Auto, TransitionConverter, Format>
00136   automaton_loader(Auto& a,
00137                    const TransitionConverter& e = TransitionConverter(),
00138                    const Format& f = Format(),
00139                    bool merge_states = false);
00140 
00141 } // vcsn
00142 
00143 
00144 #ifndef VCSN_USE_INTERFACE_ONLY
00145 # include <vaucanson/tools/io.hxx>
00146 #endif // VCSN_USE_INTERFACE_ONLY
00147 
00148 
00149 #endif // ! VCSN_TOOLS_IO_HH

Generated on Fri Jul 28 12:18:34 2006 for Vaucanson by  doxygen 1.4.6