Vaucanson  1.4.1
transducer_ops.hxx
1 // transducer_ops.hxx: 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_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX
18 # define VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX
19 
20 # include <vaucanson/algebra/concept/monoid_base.hh>
21 
22 namespace vcsn {
23 
24 #define AutoType(Type) \
25  typename Element<S, T>::Type
26 
27  template <class S, class T>
28  typename Element<S, T>::input_monoid_elt_t
29  op_input_of(const TransducerBase<S>& s,
30  const T& v,
31  typename automaton_traits<T>::htransition_t e)
32  {
33  return op_word_of(s, v, e);
34  }
35 
36  template <class S, class T>
37  typename Element<S, T>::output_series_set_elt_t
38  op_output_of(const TransducerBase<S>& s,
39  const T& v,
40  typename automaton_traits<T>::htransition_t e)
41  {
42  AutoType(series_set_elt_t) is = op_series_of(s, v, e);
43  precondition(is.supp().size() == 1);
44  return
45  is.get(AutoType(monoid_elt_t) (is.structure().monoid(),
46  *is.supp().begin()));
47  }
48 
49  template <class S, class T>
50  typename automaton_traits<T>::htransition_t
51  op_add_io_transition(const TransducerBase<S>& s,
52  T& v,
53  typename automaton_traits<T>::hstate_t from,
54  typename automaton_traits<T>::hstate_t to,
55  AutoType(input_monoid_elt_t) input_w,
56  AutoType(output_monoid_elt_t) output_w,
57  AutoType(output_semiring_elt_t) w)
58  {
59  AutoType(output_series_set_elt_t) os(s.series().semiring());
60  os.assoc(output_w, w);
61  AutoType(series_set_elt_t) is(s.series());
62  is.assoc(input_w, os);
63  return op_add_series_transition(s, v, from, to, is);
64  }
65 
66  template <class S, class T>
67  typename automaton_traits<T>::htransition_t
68  op_add_i_transition(const TransducerBase<S>& s,
69  T& v,
70  typename automaton_traits<T>::hstate_t from,
71  typename automaton_traits<T>::hstate_t to,
72  AutoType(input_letter_t) i,
73  AutoType(output_semiring_elt_t) w)
74  {
75  AutoType(input_monoid_elt_t) input_w(s.series().monoid(), i);
76  AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid());
77  AutoType(output_series_set_elt_t) os(s.series().semiring());
78  os.assoc(output_w, w);
79  AutoType(series_set_elt_t) is(s.series());
80  is.assoc(input_w, os);
81  return op_add_series_transition(s, v, from, to, is);
82  }
83 
84  template <class S, class T>
85  typename automaton_traits<T>::htransition_t
86  op_add_o_transition(const TransducerBase<S>& s,
87  T& v,
88  typename automaton_traits<T>::hstate_t from,
89  typename automaton_traits<T>::hstate_t to,
90  AutoType(input_letter_t) o,
91  AutoType(output_semiring_elt_t) w)
92  {
93  AutoType(input_monoid_elt_t) input_w(s.series().monoid());
94  AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid(), o);
95  AutoType(output_series_set_elt_t) os(s.series().semiring());
96  os.assoc(output_w, w);
97  AutoType(series_set_elt_t) is(s.series());
98  is.assoc(input_w, os);
99  return op_add_series_transition(s, v, from, to, is);
100  }
101 
102  template <class S, class T>
103  AutoType(series_set_elt_t)
104  make_series(const TransducerBase<S>& s,
105  AutoType(output_monoid_elt_value_t) o)
106  {
107  AutoType(input_monoid_elt_t) empty =
108  algebra::identity_as<AutoType(input_monoid_elt_value_t)>::
109  of(s.series().monoid());
110  AutoType(output_semiring_elt_t) semi_id =
111  algebra::identity_as<AutoType(output_semiring_elt_value_t)>::
112  of(s.series().semiring().semiring());
113 
114  AutoType(input_monoid_elt_t) input_w(s.series().monoid());
115  AutoType(output_series_set_elt_t) os (s.series().semiring());
116 
117  Element<AutoType(output_monoid_t), AutoType(output_monoid_elt_value_t)>
118  o_elt (s.series().semiring().monoid(), o);
119  os.assoc(o_elt, semi_id);
120  AutoType(series_set_elt_t) is (s.series());
121  is.assoc(empty, os);
122  return is;
123  }
124 
125  template <class S, class T>
126  void
127  op_set_o_final(const TransducerBase<S>& s,
128  T& v,
129  typename automaton_traits<T>::hstate_t final,
130  AutoType(output_monoid_elt_value_t) o)
131  {
132  AutoType(series_set_elt_t) is = make_series<S, T>(s, o);
133  op_set_final(s, v, final, is);
134  }
135 
136  template <class S, class T>
137  void
138  op_set_o_initial(const TransducerBase<S>& s,
139  T& v,
140  typename automaton_traits<T>::hstate_t initial,
141  AutoType(output_monoid_elt_value_t) o)
142  {
143  AutoType(series_set_elt_t) is = make_series<S, T>(s, o);
144  op_set_initial(s, v, initial, is);
145  }
146 
147 } // vcsn
148 
149 #undef AutoType
150 
151 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX