Vaucanson  1.4.1
io.hh
1 // io.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_TOOLS_IO_HH
18 # define VCSN_TOOLS_IO_HH
19 
20 # include <vaucanson/automata/concept/handlers.hh>
21 # include <vaucanson/automata/concept/automata_base.hh>
22 # include <vaucanson/automata/concept/transducer_base.hh>
23 # include <iostream>
24 # include <string>
25 # include <map>
26 
27 namespace vcsn
28 {
29 
30  namespace tools
31  {
32 
33  /*-------.
34  | Output |
35  `-------*/
36 
37  template <typename Auto, typename TransitionConverter, typename Format>
38  struct automaton_saver_
39  {
40  typedef Auto automaton_t;
41  typedef TransitionConverter transition_converter_t;
42  typedef Format format_t;
43 
44  automaton_saver_(const Auto&,
45  const TransitionConverter&,
46  const Format&);
47 
48  automaton_t& automaton();
49  const automaton_t& automaton() const;
50 
51  protected:
52  const automaton_t& a_;
53  transition_converter_t conv_;
54  format_t format_;
55 
56  template<typename A, typename E, typename F>
57  friend std::ostream&
58  operator<<(std::ostream&, const automaton_saver_<A, E, F>&);
59  };
60 
61 
62  template <typename Auto, typename TransitionConverter, typename Format>
63  std::ostream&
64  operator<<(std::ostream&,
65  const automaton_saver_<Auto, TransitionConverter, Format>&);
66 
67  struct string_out
68  {
69  std::string check_empty_word(const std::string&) const;
70 
71  template<typename S, typename T>
72  std::string operator()(const AutomataBase<S>&, const T&) const;
73 
74  template<typename S, typename T>
75  std::string operator()(const TransducerBase<S>&, const T&) const;
76 
77  };
78 
79  } // ! tools
80 
81  template <typename Auto, typename TransitionConverter, typename Format>
82  tools::automaton_saver_<Auto, TransitionConverter, Format>
83  automaton_saver(const Auto&,
84  const TransitionConverter& e = TransitionConverter(),
85  const Format& f = Format());
86 
87 
88  namespace tools
89  {
90 
91  /*-------.
92  | Output |
93  `-------*/
94 
95  template <typename RE, typename TransitionConverter, typename Format>
96  struct regexp_saver_
97  {
98  typedef RE rat_exp_t;
99  typedef TransitionConverter transition_converter_t;
100  typedef Format format_t;
101 
102  regexp_saver_(const RE&,
103  const TransitionConverter&,
104  const Format&);
105 
106  rat_exp_t& rat_exp();
107  const rat_exp_t& rat_exp() const;
108 
109  protected:
110  const rat_exp_t& r_;
111  transition_converter_t conv_;
112  format_t format_;
113 
114  template<typename A, typename E, typename F>
115  friend std::ostream&
116  operator<<(std::ostream&, const regexp_saver_<A, E, F>&);
117  };
118 
119 
120  template <typename RE, typename TransitionConverter, typename Format>
121  std::ostream&
122  operator<<(std::ostream&,
123  const regexp_saver_<RE, TransitionConverter, Format>&);
124 
125  } // ! tools
126 
127  template <typename RE, typename TransitionConverter, typename Format>
128  tools::regexp_saver_<RE, TransitionConverter, Format>
129  regexp_saver(const RE&,
130  const TransitionConverter& e = TransitionConverter(),
131  const Format& f = Format());
132 
133 
134  namespace tools
135  {
136  /*------.
137  | Input |
138  `------*/
139 
140  template <typename Auto, typename TransitionConverter, typename Format>
141  struct automaton_loader_
142  {
143  typedef Auto automaton_t;
144  typedef typename Auto::hstate_t hstate_t;
145  typedef typename Auto::htransition_t htransition_t;
146  typedef TransitionConverter transition_converter_t;
147  typedef Format format_t;
148 
149  automaton_loader_(automaton_t& a,
150  const transition_converter_t& conv,
151  const format_t& format,
152  bool merge_states);
153 
154  automaton_t& automaton();
155  const automaton_t& automaton() const;
156 
157  hstate_t add_state(unsigned);
158  void set_initial(unsigned, const std::string&);
159  void set_final(unsigned, const std::string&);
160  void add_transition(unsigned, unsigned, const std::string&);
161  void add_spontaneous(unsigned, unsigned);
162 
163  protected:
164  automaton_t& a_;
165  transition_converter_t conv_;
166  format_t format_;
167  unsigned scount_;
168  std::map<unsigned, hstate_t> smap_;
169  bool merge_states_;
170 
171  template<typename A, typename E, typename F>
172  friend std::istream&
173  operator>>(std::istream&, automaton_loader_<A, E, F>);
174  };
175 
176  template <typename Auto, typename TransitionConverter, typename Format>
177  std::istream&
178  operator>>(std::istream&, automaton_loader_<Auto, TransitionConverter, Format>);
179 
180 
181  } // ! tools
182 
183 
184  template <typename Auto, typename TransitionConverter, typename Format>
185  tools::automaton_loader_<Auto, TransitionConverter, Format>
186  automaton_loader(Auto& a,
187  const TransitionConverter& e = TransitionConverter(),
188  const Format& f = Format(),
189  bool merge_states = false);
190 
191  namespace tools
192  {
193  template <typename RE, typename TransitionConverter, typename Format>
194  struct regexp_loader_
195  {
196  typedef RE rat_exp_t;
197  typedef TransitionConverter transition_converter_t;
198  typedef Format format_t;
199 
200  regexp_loader_(rat_exp_t& r,
201  const transition_converter_t& conv,
202  const format_t& format);
203 
204  rat_exp_t& rat_exp();
205  const rat_exp_t& rat_exp() const;
206 
207  protected:
208  rat_exp_t& r_;
209  transition_converter_t conv_;
210  format_t format_;
211 
212  template <typename R, typename T, typename F>
213  friend std::istream&
214  operator>>(std::istream&, regexp_loader_<R, T, F>);
215  };
216 
217  template <typename RE, typename TransitionConverter, typename Format>
218  std::istream&
219  operator>>(std::istream&, regexp_loader_<RE, TransitionConverter, Format>);
220  } // ! tools
221 
222  template <typename RE, typename TransitionConverter, typename Format>
223  tools::regexp_loader_<RE, TransitionConverter, Format>
224  regexp_loader(RE& r,
225  const TransitionConverter& e = TransitionConverter(),
226  const Format& f = Format());
227 } // vcsn
228 
229 
230 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
231 # include <vaucanson/tools/io.hxx>
232 #endif // VCSN_USE_INTERFACE_ONLY
233 
234 
235 #endif // ! VCSN_TOOLS_IO_HH