Vaucanson  1.4.1
automaton_maker.thxx
1 // -*- C++ -*-
2 // automaton_maker.thxx: this file is part of the Vaucanson project.
3 //
4 // Vaucanson, a generic library for finite state machines.
5 //
6 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011 The Vaucanson Group.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // The complete GNU General Public Licence Notice can be found as the
14 // `COPYING' file in the root directory.
15 //
16 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
17 //
18 
19 /*
20  * CPP guard should not be inserted here as
21  * VCSN_CONTEXT_NAMESPACE could be changed.
22  */
23 
27 
28 namespace vcsn
29 {
30  namespace VCSN_GRAPH_IMPL
31  {
32  VCSN_CONTEXT_NAMESPACE
33  {
34  /*-----------------.
35  | make_automaton() |
36  `-----------------*/
37 
38  template <class InputIterator>
39  automata_set_t
40  make_automata_set(InputIterator begin,
41  InputIterator end)
42  {
43  alphabet_t alpha;
44 
45  for (InputIterator e = begin; e != end; ++e)
46  alpha.insert(*e);
47 
48  semiring_t semiring;
49  monoid_t freemonoid(alpha);
50  series_set_t series(semiring, freemonoid);
51 
52  return automata_set_t(series);
53  }
54 
55  template <class InputIterator>
56  automata_set_t
57  make_automata_set(InputIterator begin,
58  InputIterator end,
59  const monoid_rep_t& mrep,
60  const series_rep_t& srep)
61  {
62  alphabet_t alpha;
63 
64  for (InputIterator e = begin; e != end; ++e)
65  alpha.insert(*e);
66 
67  semiring_t semiring;
68  monoid_t freemonoid(alpha, mrep);
69  series_set_t series(semiring, freemonoid, srep);
70  return automata_set_t(series);
71  }
72 
73  template <class InputIterator>
74  automaton_t
75  make_automaton(InputIterator begin,
76  InputIterator end)
77  {
78  return automaton_t(make_automata_set(begin, end));
79  }
80 
81  template <class InputIterator>
82  automaton_t
83  make_automaton(InputIterator begin,
84  InputIterator end,
85  const monoid_rep_t& mrep,
86  const series_rep_t& srep)
87  {
88  return automaton_t(make_automata_set(begin, end, mrep, srep));
89  }
90 
91  template <class T>
92  automaton_t
93  make_automaton(const T& alphabet)
94  {
95  return make_automaton(alphabet.begin(), alphabet.end());
96  }
97 
98  template <class T>
99  automaton_t
100  make_automaton(const T& alphabet,
101  const monoid_rep_t& mrep,
102  const series_rep_t& srep)
103  {
104  return make_automaton(alphabet.begin(), alphabet.end(), mrep, srep);
105  }
106 
107  template <class InputIterator>
108  automaton_letter_t
109  make_automaton_letter(InputIterator begin,
110  InputIterator end)
111  {
112  return automaton_letter_t (make_automata_set(begin, end));
113  }
114 
115  template <class T>
116  automaton_letter_t
117  make_automaton_letter(const T& alphabet)
118  {
119  return make_automaton_letter(alphabet.begin(), alphabet.end());
120  }
121 
122  template <class InputIterator>
123  gen_automaton_t
124  make_gen_automaton(InputIterator begin,
125  InputIterator end)
126  {
127  return gen_automaton_t (make_automata_set(begin, end));
128  }
129 
130  template <class T>
131  gen_automaton_t
132  make_gen_automaton(const T& alphabet)
133  {
134  return make_gen_automaton(alphabet.begin(), alphabet.end());
135  }
136 
137  /*---------------.
138  | make_rat_exp() |
139  `---------------*/
140 
141  template <class Iterator>
142  rat_exp_t
143  make_rat_exp(const Iterator& begin,
144  const Iterator& end,
145  const std::string& exp,
146  const monoid_rep_t& mrep,
147  const series_rep_t& srep)
148  {
149  alphabet_t alphabet;
150  for (Iterator i = begin; i != end; ++i)
151  alphabet.insert(*i);
152  monoid_t monoid (alphabet, mrep);
153  semiring_t semiring;
154  series_set_t series (semiring, monoid, srep);
155 
156  rat_exp_t r (series);
157  std::pair<bool, std::string> p = parse(exp, r);
158 
159  postcondition_ (not p.first, p.second);
160 
161  return r;
162  }
163 
164  template <class T>
165  rat_exp_t
166  make_rat_exp(const T& alphabet,
167  const std::string& exp,
168  const monoid_rep_t& mrep,
169  const series_rep_t& srep)
170  {
171  return make_rat_exp(alphabet.begin(), alphabet.end(),
172  exp, mrep, srep);
173  }
174 
175  /*--------------.
176  | standard_of() |
177  `--------------*/
178 
179  template <class SeriesImpl>
180  automaton_t
181  do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
182  {
183  automaton_t r = make_automaton(structure.monoid().alphabet(),
184  *structure.monoid().representation(),
185  *structure.representation());
186  standard_of(r, impl);
187  return r;
188  }
189 
190  template <class SeriesSet, class SeriesImpl>
191  automaton_t
192  standard_of(const Element<SeriesSet, SeriesImpl>& e)
193  {
194  return do_standard_of(e.structure(), e.value());
195  }
196 
197  /*--------------.
198  | thompson_of() |
199  `--------------*/
200 
201  template <class SeriesImpl>
202  automaton_t
203  do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
204  {
205  automaton_t r = make_automaton(structure.monoid().alphabet(),
206  *structure.monoid().representation(),
207  *structure.representation());
208  thompson_of(r, impl);
209  return r;
210  }
211 
212  template <class SeriesSet, class SeriesImpl>
213  automaton_t
214  thompson_of(const Element<SeriesSet, SeriesImpl>& e)
215  {
216  return do_thompson_of(e.structure(), e.value());
217  }
218 
219  /*-------------.
220  | aut_to_exp() |
221  `-------------*/
222 
223  inline
224  rat_exp_t
225  aut_to_exp(const automaton_t& a)
226  {
227  return aut_to_exp(generalized(a));
228  }
229 
230  template <class Chooser>
231  rat_exp_t
232  aut_to_exp(const automaton_t& a, const Chooser& c)
233  {
234  return aut_to_exp(generalized(a), c);
235  }
236 
237  } // End of VCSN_CONTEXT_NAMESPACE.
238  } // End of VCSN_GRAPH_IMPL
239 } // End of namespace vcsn.