transducer_ops.hxx

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               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                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   htransition_t
00051   op_add_io_transition(const TransducerBase<S>& s,
00052                        T& v,
00053                        hstate_t from,
00054                        hstate_t to,
00055                        AutoType(input_letter_t) i,
00056                        AutoType(output_letter_t) o,
00057                        AutoType(output_semiring_elt_t) w)
00058   {
00059     AutoType(input_monoid_elt_t) input_w(s.series().monoid(), i);
00060     AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid(), o);
00061     AutoType(output_series_set_elt_t) os(s.series().semiring());
00062     os.assoc(output_w, w);
00063     AutoType(series_set_elt_t) is(s.series());
00064     is.assoc(input_w, os);
00065     std::cout << "add io transition :" << o << " "
00066               << output_w << " " << w << " "
00067               << os << std::endl;
00068     return op_add_series_transition(s, v, from, to, is);
00069   }
00070 
00071   template <class S, class T>
00072   htransition_t
00073   op_add_io_transition(const TransducerBase<S>& s,
00074                        T& v,
00075                        hstate_t from,
00076                        hstate_t to,
00077                        AutoType(input_monoid_elt_t) input_w,
00078                        AutoType(output_monoid_elt_t) output_w,
00079                        AutoType(output_semiring_elt_t) w)
00080   {
00081     AutoType(output_series_set_elt_t) os(s.series().semiring());
00082     os.assoc(output_w, w);
00083     AutoType(series_set_elt_t) is(s.series());
00084     is.assoc(input_w, os);
00085     return op_add_series_transition(s, v, from, to, is);
00086   }
00087 
00088   template <class S, class T>
00089   htransition_t
00090   op_add_i_transition(const TransducerBase<S>& s,
00091                       T& v,
00092                       hstate_t from,
00093                       hstate_t to,
00094                       AutoType(input_letter_t) i,
00095                       AutoType(output_semiring_elt_t) w)
00096   {
00097     AutoType(input_monoid_elt_t) input_w(s.series().monoid(), i);
00098     AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid());
00099     AutoType(output_series_set_elt_t) os(s.series().semiring());
00100     os.assoc(output_w, w);
00101     AutoType(series_set_elt_t) is(s.series());
00102     is.assoc(input_w, os);
00103     return op_add_series_transition(s, v, from, to, is);
00104   }
00105 
00106   template <class S, class T>
00107   htransition_t
00108   op_add_o_transition(const TransducerBase<S>& s,
00109                       T& v,
00110                       hstate_t from,
00111                       hstate_t to,
00112                       AutoType(input_letter_t) o,
00113                       AutoType(output_semiring_elt_t) w)
00114   {
00115     AutoType(input_monoid_elt_t) input_w(s.series().monoid());
00116     AutoType(output_monoid_elt_t) output_w(s.series().semiring().monoid(), o);
00117     AutoType(output_series_set_elt_t) os(s.series().semiring());
00118     os.assoc(output_w, w);
00119     AutoType(series_set_elt_t) is(s.series());
00120     is.assoc(input_w, os);
00121     return op_add_series_transition(s, v, from, to, is);
00122   }
00123 
00124   template <class S, class T>
00125   AutoType(series_set_elt_t)
00126   make_series(const TransducerBase<S>& s,
00127               AutoType(output_monoid_elt_value_t) o)
00128   {
00129     AutoType(input_monoid_elt_t) empty =
00130       algebra::identity_as<AutoType(input_monoid_elt_value_t)>::
00131       of(s.series().monoid());
00132     AutoType(output_semiring_elt_t) semi_id =
00133       algebra::identity_as<AutoType(output_semiring_elt_value_t)>::
00134       of(s.series().semiring().semiring());
00135 
00136     AutoType(input_monoid_elt_t) input_w(s.series().monoid());
00137     AutoType(output_series_set_elt_t) os (s.series().semiring());
00138 
00139     Element<AutoType(output_monoid_t), AutoType(output_monoid_elt_value_t)>
00140       o_elt (s.series().semiring().monoid(), o);
00141     os.assoc(o_elt, semi_id);
00142     AutoType(series_set_elt_t) is (s.series());
00143     is.assoc(empty, os);
00144     return is;
00145   }
00146 
00147   template <class S, class T>
00148   void
00149   op_set_o_final(const TransducerBase<S>& s,
00150                  T& v,
00151                  hstate_t final,
00152                  AutoType(output_monoid_elt_value_t) o)
00153   {
00154     AutoType(series_set_elt_t) is = make_series<S, T>(s, o);
00155     op_set_final(s, v, final, is);
00156   }
00157 
00158   template <class S, class T>
00159   void
00160   op_set_o_initial(const TransducerBase<S>& s,
00161                    T& v,
00162                    hstate_t initial,
00163                    AutoType(output_monoid_elt_value_t) o)
00164   {
00165     AutoType(series_set_elt_t) is = make_series<S, T>(s, o);
00166     op_set_initial(s, v, initial, is);
00167   }
00168 
00169 } // vcsn
00170 
00171 #undef AutoType
00172 
00173 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSDUCER_OPS_HXX

Generated on Sun Jul 29 19:35:31 2007 for Vaucanson by  doxygen 1.5.2