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

Generated on Fri Jul 28 12:18:55 2006 for Vaucanson by  doxygen 1.4.6