Vaucanson 1.4
|
00001 // transducer_ops.hxx: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group. 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // The complete GNU General Public Licence Notice can be found as the 00013 // `COPYING' file in the root directory. 00014 // 00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 #ifndef VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX 00018 # define VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX 00019 00020 # include <vaucanson/algebra/concept/monoid_base.hh> 00021 00022 namespace vcsn { 00023 00024 #define AutoType(Type) \ 00025 typename Element<S, T>::Type 00026 00027 template <class S, class T> 00028 typename Element<S, T>::input_monoid_elt_t 00029 op_input_of(const TransducerBase<S>& s, 00030 const T& v, 00031 typename automaton_traits<T>::htransition_t e) 00032 { 00033 return op_word_of(s, v, e); 00034 } 00035 00036 template <class S, class T> 00037 typename Element<S, T>::output_series_set_elt_t 00038 op_output_of(const TransducerBase<S>& s, 00039 const T& v, 00040 typename automaton_traits<T>::htransition_t e) 00041 { 00042 AutoType(series_set_elt_t) is = op_series_of(s, v, e); 00043 precondition(is.supp().size() == 1); 00044 return 00045 is.get(AutoType(monoid_elt_t) (is.structure().monoid(), 00046 *is.supp().begin())); 00047 } 00048 00049 template <class S, class T> 00050 typename automaton_traits<T>::htransition_t 00051 op_add_io_transition(const TransducerBase<S>& s, 00052 T& v, 00053 typename automaton_traits<T>::hstate_t from, 00054 typename automaton_traits<T>::hstate_t to, 00055 AutoType(input_monoid_elt_t) input_w, 00056 AutoType(output_monoid_elt_t) output_w, 00057 AutoType(output_semiring_elt_t) w) 00058 { 00059 AutoType(output_series_set_elt_t) os(s.series().semiring()); 00060 os.assoc(output_w, w); 00061 AutoType(series_set_elt_t) is(s.series()); 00062 is.assoc(input_w, os); 00063 return op_add_series_transition(s, v, from, to, is); 00064 } 00065 00066 template <class S, class T> 00067 typename automaton_traits<T>::htransition_t 00068 op_add_i_transition(const TransducerBase<S>& s, 00069 T& v, 00070 typename automaton_traits<T>::hstate_t from, 00071 typename automaton_traits<T>::hstate_t to, 00072 AutoType(input_letter_t) i, 00073 AutoType(output_semiring_elt_t) w) 00074 { 00075 AutoType(input_monoid_elt_t) input_w(s.series().monoid(), i); 00076 AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid()); 00077 AutoType(output_series_set_elt_t) os(s.series().semiring()); 00078 os.assoc(output_w, w); 00079 AutoType(series_set_elt_t) is(s.series()); 00080 is.assoc(input_w, os); 00081 return op_add_series_transition(s, v, from, to, is); 00082 } 00083 00084 template <class S, class T> 00085 typename automaton_traits<T>::htransition_t 00086 op_add_o_transition(const TransducerBase<S>& s, 00087 T& v, 00088 typename automaton_traits<T>::hstate_t from, 00089 typename automaton_traits<T>::hstate_t to, 00090 AutoType(input_letter_t) o, 00091 AutoType(output_semiring_elt_t) w) 00092 { 00093 AutoType(input_monoid_elt_t) input_w(s.series().monoid()); 00094 AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid(), o); 00095 AutoType(output_series_set_elt_t) os(s.series().semiring()); 00096 os.assoc(output_w, w); 00097 AutoType(series_set_elt_t) is(s.series()); 00098 is.assoc(input_w, os); 00099 return op_add_series_transition(s, v, from, to, is); 00100 } 00101 00102 template <class S, class T> 00103 AutoType(series_set_elt_t) 00104 make_series(const TransducerBase<S>& s, 00105 AutoType(output_monoid_elt_value_t) o) 00106 { 00107 AutoType(input_monoid_elt_t) empty = 00108 algebra::identity_as<AutoType(input_monoid_elt_value_t)>:: 00109 of(s.series().monoid()); 00110 AutoType(output_semiring_elt_t) semi_id = 00111 algebra::identity_as<AutoType(output_semiring_elt_value_t)>:: 00112 of(s.series().semiring().semiring()); 00113 00114 AutoType(input_monoid_elt_t) input_w(s.series().monoid()); 00115 AutoType(output_series_set_elt_t) os (s.series().semiring()); 00116 00117 Element<AutoType(output_monoid_t), AutoType(output_monoid_elt_value_t)> 00118 o_elt (s.series().semiring().monoid(), o); 00119 os.assoc(o_elt, semi_id); 00120 AutoType(series_set_elt_t) is (s.series()); 00121 is.assoc(empty, os); 00122 return is; 00123 } 00124 00125 template <class S, class T> 00126 void 00127 op_set_o_final(const TransducerBase<S>& s, 00128 T& v, 00129 typename automaton_traits<T>::hstate_t final, 00130 AutoType(output_monoid_elt_value_t) o) 00131 { 00132 AutoType(series_set_elt_t) is = make_series<S, T>(s, o); 00133 op_set_final(s, v, final, is); 00134 } 00135 00136 template <class S, class T> 00137 void 00138 op_set_o_initial(const TransducerBase<S>& s, 00139 T& v, 00140 typename automaton_traits<T>::hstate_t initial, 00141 AutoType(output_monoid_elt_value_t) o) 00142 { 00143 AutoType(series_set_elt_t) is = make_series<S, T>(s, o); 00144 op_set_initial(s, v, initial, is); 00145 } 00146 00147 } // vcsn 00148 00149 #undef AutoType 00150 00151 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX