Vaucanson  1.4.1
transducer.hh
1 // transducer.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, 2008 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_AUTOMATA_CONCEPT_TRANSDUCER_HH
18 # define VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HH
19 
20 # include <vaucanson/design_pattern/design_pattern.hh>
21 # include <vaucanson/automata/concept/automata.hh>
22 # include <vaucanson/automata/concept/automata_base.hh>
23 # include <vaucanson/automata/concept/transducer_base.hh>
24 
25 namespace vcsn {
26 
27  template <typename Series, typename Kind>
28  // FIXME: Rename to TransducerSet (see Trac #3)
29  struct Transducer;
30 
32  template <typename Series, typename Kind>
33  struct dynamic_traits<Transducer<Series, Kind> >
34  : dynamic_traits<TransducerBase<Series> >
35  {
36  static const bool ret = dynamic_traits<Series>::ret;
37  };
38 
40  template <typename Series, typename Kind, typename T>
41  struct MetaElement<Transducer<Series, Kind>, T>
42  : MetaElement<TransducerBase<Transducer<Series, Kind> >, T>
43  {};
44 
46  template <typename Series, typename Kind>
47  struct virtual_types<Transducer<Series, Kind> >
48  {
49  typedef Series series_set_t;
50  typedef Kind kind_t;
51  };
52 
54  template <typename Series, typename Kind>
55  class Transducer
56  : public TransducerBase<Transducer<Series, Kind> >,
57  private SetSlot<Series>
58  {
59  public:
61  typedef typename virtual_types<self_t>::series_set_t series_set_t;
62  typedef typename virtual_types<self_t>::kind_t kind_t;
63 
64  Transducer(const series_set_t&);
65 
66  const series_set_t& series() const;
67 
68  };
69 
70 
71  /*------------------------.
72  | INPUT PROJECTION TRAITS |
73  `------------------------*/
74 
75  template <typename S, typename T>
76  struct input_projection_helper
77  { };
78 
79  template <typename S, typename K, typename T>
80  struct input_projection_helper<Transducer<S, K>, T>
81  {
82  typedef Transducer<S, K> structure_t;
83 
84  typedef Element<structure_t, T> automaton_t;
85 
86  typedef typename structure_t::series_set_t::semiring_t
87  typeof_auto_series_set_t;
88 
89  typedef typename structure_t::series_set_t::monoid_t auto_monoid_t;
90 
91  typedef typename typeof_auto_series_set_t::semiring_t auto_semiring_t;
92  typedef typename algebra::mute_series_traits<typeof_auto_series_set_t,
93  auto_semiring_t,
94  auto_monoid_t>::ret
95  auto_series_set_t;
96 
97  typedef typename input_projection_traits<T>::ret auto_impl_t;
98  typedef Element<Automata<auto_series_set_t, K>, auto_impl_t> ret;
99 
100  static ret make_input_projection_automaton(const automaton_t& t);
101  };
102 
103  template <typename S, typename K, typename T>
104  struct input_projection_helper<Automata<S, K>, T>
105  {
106  typedef Automata<S, K> structure_t;
107 
108  typedef Element<structure_t, T> automaton_t;
109 
110  typedef typename structure_t::series_set_t typeof_auto_series_set_t;
111 
112  typedef typename structure_t::series_set_t::semiring_t auto_semiring_t;
113 
114  typedef typename structure_t::series_set_t::monoid_t::first_monoid_t
115  auto_monoid_t;
116 
117  typedef typename algebra::mute_series_traits<typeof_auto_series_set_t,
118  auto_semiring_t,
119  auto_monoid_t>::ret
120  auto_series_set_t;
121 
122  typedef typename fmp_input_projection_traits<T>::ret auto_impl_t;
123  typedef Element<Automata<auto_series_set_t, K>, auto_impl_t> ret;
124 
125  static ret make_input_projection_automaton(const automaton_t& t);
126  };
127 
128  /*-------------------------.
129  | OUTPUT PROJECTION TRAITS |
130  `-------------------------*/
131 
132  template <typename S, typename T>
133  struct output_projection_helper
134  { };
135 
136  // RW transducers
137  template <typename S, typename K, typename T>
138  struct output_projection_helper<Transducer<S, K>, T>
139  {
140  typedef Transducer<S, K> structure_t;
141 
142  typedef Element<structure_t, T> automaton_t;
143 
144  typedef typename structure_t::series_set_t::semiring_t
145  typeof_auto_series_set_t;
146 
147  typedef typename structure_t::series_set_t::semiring_t::monoid_t
148  auto_monoid_t;
149 
150  typedef typename typeof_auto_series_set_t::semiring_t auto_semiring_t;
151  typedef typename algebra::mute_series_traits<typeof_auto_series_set_t,
152  auto_semiring_t,
153  auto_monoid_t>::ret
154  auto_series_set_t;
155 
156  typedef typename output_projection_traits<T>::ret auto_impl_t;
157  typedef Element<Automata<auto_series_set_t, K>, auto_impl_t> ret;
158 
159  static ret make_output_projection_automaton(const automaton_t& t);
160  };
161 
162  // FMP Transducers
163  // FIXME: it should be automata over a free monoid product
164  // FIXME: we cannot use output_projection_traits, because
165  // it constructs the type by assuming that the automaton is RW
166  template <typename S, typename K, typename T>
167  struct output_projection_helper<Automata<S, K>, T>
168  {
169  typedef Automata<S, K> structure_t;
170 
171  typedef Element<structure_t, T> automaton_t;
172 
173  typedef typename structure_t::series_set_t typeof_auto_series_set_t;
174 
175  typedef typename structure_t::series_set_t::monoid_t::second_monoid_t
176  auto_monoid_t;
177 
178  typedef typename typeof_auto_series_set_t::semiring_t auto_semiring_t;
179  typedef typename algebra::mute_series_traits<typeof_auto_series_set_t,
180  auto_semiring_t,
181  auto_monoid_t>::ret
182  auto_series_set_t;
183 
184  typedef typename fmp_output_projection_traits<T>::ret auto_impl_t;
185  typedef Element<Automata<auto_series_set_t, K>, auto_impl_t> ret;
186 
187  static ret make_output_projection_automaton(const automaton_t& t);
188  };
189 
190  /*----------------.
191  | IDENTITY TRAITS |
192  `----------------*/
193 
194  template <typename S, typename K, typename T>
195  struct identity_transducer_helper
196  {
197  typedef typename S::series_set_t series_set_t;
198  typedef typename series_set_t::monoid_t monoid_t;
199  typedef typename series_set_t::semiring_t semiring_t;
200  typedef typename algebra::mute_series_traits<series_set_t, series_set_t, monoid_t>
201  ::ret tseries_set_t;
202  typedef typename extension_traits<T>::ret impl_t;
203  typedef Element<Transducer<tseries_set_t, K>, impl_t> ret;
204  };
205 
206  template <typename S, typename K, typename T>
207  typename identity_transducer_helper<S, K, T>::ret
208  partial_identity(const Element<S, T>&);
209 
210  template <typename Series, typename Kind>
211  bool
212  operator==(const Transducer<Series, Kind>&, const Transducer<Series, Kind>&);
213 
214 } // ! vcsn
215 
216 
217 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
218 # include <vaucanson/automata/concept/transducer.hxx>
219 #endif // VCSN_USE_INTERFACE_ONLY
220 
221 
222 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_HH