Vaucanson 1.4
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   } // ! tools
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     /*-------.
00092     | Output |
00093     `-------*/
00094 
00095     template <typename RE, typename TransitionConverter, typename Format>
00096     struct regexp_saver_
00097     {
00098         typedef RE rat_exp_t;
00099         typedef TransitionConverter transition_converter_t;
00100         typedef Format format_t;
00101 
00102         regexp_saver_(const RE&,
00103                       const TransitionConverter&,
00104                       const Format&);
00105 
00106         rat_exp_t& rat_exp();
00107         const rat_exp_t& rat_exp() const;
00108 
00109       protected:
00110         const rat_exp_t& r_;
00111         transition_converter_t conv_;
00112         format_t format_;
00113 
00114         template<typename A, typename E, typename F>
00115         friend std::ostream&
00116         operator<<(std::ostream&, const regexp_saver_<A, E, F>&);
00117     };
00118 
00119 
00120     template <typename RE, typename TransitionConverter, typename Format>
00121     std::ostream&
00122     operator<<(std::ostream&,
00123                const regexp_saver_<RE, TransitionConverter, Format>&);
00124 
00125   } // ! tools
00126 
00127   template <typename RE, typename TransitionConverter, typename Format>
00128   tools::regexp_saver_<RE, TransitionConverter, Format>
00129   regexp_saver(const RE&,
00130                const TransitionConverter& e = TransitionConverter(),
00131                const Format& f = Format());
00132 
00133 
00134   namespace tools
00135   {
00136     /*------.
00137     | Input |
00138     `------*/
00139 
00140     template <typename Auto, typename TransitionConverter, typename Format>
00141     struct automaton_loader_
00142     {
00143         typedef Auto automaton_t;
00144         typedef typename Auto::hstate_t hstate_t;
00145         typedef typename Auto::htransition_t htransition_t;
00146         typedef TransitionConverter transition_converter_t;
00147         typedef Format format_t;
00148 
00149         automaton_loader_(automaton_t& a,
00150                           const transition_converter_t& conv,
00151                           const format_t& format,
00152                           bool merge_states);
00153 
00154         automaton_t& automaton();
00155         const automaton_t& automaton() const;
00156 
00157         hstate_t add_state(unsigned);
00158         void set_initial(unsigned, const std::string&);
00159         void set_final(unsigned, const std::string&);
00160         void add_transition(unsigned, unsigned, const std::string&);
00161         void add_spontaneous(unsigned, unsigned);
00162 
00163       protected:
00164         automaton_t& a_;
00165         transition_converter_t conv_;
00166         format_t format_;
00167         unsigned scount_;
00168         std::map<unsigned, hstate_t> smap_;
00169         bool merge_states_;
00170 
00171         template<typename A, typename E, typename F>
00172         friend std::istream&
00173         operator>>(std::istream&, automaton_loader_<A, E, F>);
00174     };
00175 
00176     template <typename Auto, typename TransitionConverter, typename Format>
00177     std::istream&
00178     operator>>(std::istream&, automaton_loader_<Auto, TransitionConverter, Format>);
00179 
00180 
00181   } // ! tools
00182 
00183 
00184   template <typename Auto, typename TransitionConverter, typename Format>
00185   tools::automaton_loader_<Auto, TransitionConverter, Format>
00186   automaton_loader(Auto& a,
00187                    const TransitionConverter& e = TransitionConverter(),
00188                    const Format& f = Format(),
00189                    bool merge_states = false);
00190 
00191   namespace tools
00192   {
00193     template <typename RE, typename TransitionConverter, typename Format>
00194     struct regexp_loader_
00195     {
00196         typedef RE rat_exp_t;
00197         typedef TransitionConverter transition_converter_t;
00198         typedef Format format_t;
00199 
00200         regexp_loader_(rat_exp_t& r,
00201                        const transition_converter_t& conv,
00202                        const format_t& format);
00203 
00204         rat_exp_t& rat_exp();
00205         const rat_exp_t& rat_exp() const;
00206 
00207       protected:
00208         rat_exp_t& r_;
00209         transition_converter_t conv_;
00210         format_t format_;
00211 
00212         template <typename R, typename T, typename F>
00213         friend std::istream&
00214         operator>>(std::istream&, regexp_loader_<R, T, F>);
00215     };
00216 
00217     template <typename RE, typename TransitionConverter, typename Format>
00218     std::istream&
00219     operator>>(std::istream&, regexp_loader_<RE, TransitionConverter, Format>);
00220   } // ! tools
00221 
00222   template <typename RE, typename TransitionConverter, typename Format>
00223   tools::regexp_loader_<RE, TransitionConverter, Format>
00224   regexp_loader(RE& r,
00225                 const TransitionConverter& e = TransitionConverter(),
00226                 const Format& f = Format());
00227 } // vcsn
00228 
00229 
00230 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00231 # include <vaucanson/tools/io.hxx>
00232 #endif // VCSN_USE_INTERFACE_ONLY
00233 
00234 
00235 #endif // ! VCSN_TOOLS_IO_HH