00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00092
00093
00094 template<typename Auto, typename TransitionConverter, typename Format>
00095 struct automaton_loader_
00096 {
00097 typedef Auto automaton_t;
00098 typedef typename Auto::hstate_t hstate_t;
00099 typedef typename Auto::htransition_t htransition_t;
00100 typedef TransitionConverter transition_converter_t;
00101 typedef Format format_t;
00102
00103 automaton_loader_(automaton_t& a,
00104 const transition_converter_t& conv,
00105 const format_t& format,
00106 bool merge_states);
00107
00108 automaton_t& automaton();
00109 const automaton_t& automaton() const;
00110
00111 hstate_t add_state(unsigned);
00112 void set_initial(unsigned, const std::string&);
00113 void set_final(unsigned, const std::string&);
00114 void add_transition(unsigned, unsigned, const std::string&);
00115 void add_spontaneous(unsigned, unsigned);
00116
00117 protected:
00118 automaton_t& a_;
00119 transition_converter_t conv_;
00120 format_t format_;
00121 unsigned scount_;
00122 std::map<unsigned, hstate_t> smap_;
00123 bool merge_states_;
00124
00125 template<typename A, typename E, typename F>
00126 friend std::istream&
00127 operator>>(std::istream&, automaton_loader_<A, E, F>);
00128 };
00129
00130 template<typename Auto, typename TransitionConverter, typename Format>
00131 std::istream&
00132 operator>>(std::istream&, automaton_loader_<Auto, TransitionConverter, Format>);
00133
00134
00135 }
00136
00137
00138 template<typename Auto, typename TransitionConverter, typename Format>
00139 tools::automaton_loader_<Auto, TransitionConverter, Format>
00140 automaton_loader(Auto& a,
00141 const TransitionConverter& e = TransitionConverter(),
00142 const Format& f = Format(),
00143 bool merge_states = false);
00144 }
00145
00146
00147 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00148 # include <vaucanson/tools/io.hxx>
00149 #endif // VCSN_USE_INTERFACE_ONLY
00150
00151
00152 #endif // ! VCSN_TOOLS_IO_HH