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, 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_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 tools
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&, 
00045                          const TransitionConverter&, 
00046                          const Format&);
00047 
00048         automaton_t& automaton();
00049         const automaton_t& automaton() const;
00050 
00051       protected:
00052         const automaton_t& a_;
00053         transition_converter_t conv_;
00054         format_t format_;
00055 
00056         template<typename A, typename E, typename F>
00057         friend std::ostream&
00058         operator<<(std::ostream&, const automaton_saver_<A, E, F>&);
00059     };
00060 
00061 
00062     template<typename Auto, typename TransitionConverter, typename Format>
00063     std::ostream&
00064     operator<<(std::ostream&,
00065                const automaton_saver_<Auto, TransitionConverter, Format>&);
00066 
00067     struct string_out
00068     {
00069         std::string check_empty_word(const std::string&) const;
00070 
00071         template<typename S, typename T>
00072         std::string operator()(const AutomataBase<S>&, const T&) const;
00073 
00074         template<typename S, typename T>
00075         std::string operator()(const TransducerBase<S>&, const T&) const;
00076 
00077     };
00078 
00079   }
00080 
00081   template<typename Auto, typename TransitionConverter, typename Format>
00082   tools::automaton_saver_<Auto, TransitionConverter, Format>
00083   automaton_saver(const Auto&,
00084                   const TransitionConverter& e = TransitionConverter(),
00085                   const Format& f = Format());
00086 
00087 
00088   namespace tools
00089   {
00090     /*------.
00091     | Input |
00092     `------*/
00093 
00094     template<typename Auto, typename TransitionConverter, typename Format>
00095     struct automaton_loader_
00096     {
00097         typedef Auto automaton_t;
00098         typedef TransitionConverter transition_converter_t;
00099         typedef Format format_t;
00100 
00101         automaton_loader_(automaton_t& a,
00102                           const transition_converter_t& conv,
00103                           const format_t& format,
00104                           bool merge_states);
00105 
00106         automaton_t& automaton();
00107         const automaton_t& automaton() const;
00108 
00109         hstate_t add_state(unsigned);
00110         void set_initial(unsigned, const std::string&);
00111         void set_final(unsigned, const std::string&);
00112         void add_transition(unsigned, unsigned, const std::string&);
00113         void add_spontaneous(unsigned, unsigned);
00114 
00115       protected:
00116         automaton_t& a_;
00117         transition_converter_t conv_;
00118         format_t format_;
00119         unsigned scount_;
00120         std::map<unsigned, hstate_t> smap_;
00121         bool merge_states_;
00122 
00123         template<typename A, typename E, typename F>
00124         friend std::istream&
00125         operator>>(std::istream&, automaton_loader_<A, E, F>);
00126     };
00127 
00128     template<typename Auto, typename TransitionConverter, typename Format>
00129     std::istream&
00130     operator>>(std::istream&, automaton_loader_<Auto, TransitionConverter, Format>);
00131 
00132 
00133   } //tools
00134 
00135 
00136   template<typename Auto, typename TransitionConverter, typename Format>
00137   tools::automaton_loader_<Auto, TransitionConverter, Format>
00138   automaton_loader(Auto& a,
00139                    const TransitionConverter& e = TransitionConverter(),
00140                    const Format& f = Format(),
00141                    bool merge_states = false);
00142 } // vcsn
00143 
00144 
00145 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00146 # include <vaucanson/tools/io.hxx>
00147 #endif // VCSN_USE_INTERFACE_ONLY
00148 
00149 
00150 #endif // ! VCSN_TOOLS_IO_HH

Generated on Sun Jul 29 19:35:20 2007 for Vaucanson by  doxygen 1.5.2