00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX
00018 # define VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX
00019
00020 # include <vaucanson/misc/usual_macros.hh>
00021 # include <vaucanson/algorithms/finite_support_conversion.hh>
00022 # include <vaucanson/algebra/concept/monoid_base.hh>
00023
00024 # include <vaucanson/misc/contract.hh>
00025
00026 namespace vcsn
00027 {
00028
00029 template<typename S, typename T, typename Ss, typename Ts>
00030 void
00031 finite_support_convert(Element<S, T>& dst, const Element<Ss, Ts>& org)
00032 {
00033 BENCH_TASK_SCOPED("finite_support_convert");
00034 precondition(org.is_finite_app());
00035
00036 typedef typename Element<S, T>::monoid_elt_t me_t;
00037 typedef typename Element<S, T>::semiring_elt_t se_t;
00038 typedef typename Element<Ss, Ts>::monoid_elt_t sme_t;
00039 typedef typename Element<Ss, Ts>::semiring_elt_t sse_t;
00040
00041 typedef typename Element<Ss, Ts>::support_t support_t;
00042
00043 dst = algebra::zero_as<T>::of(dst.structure());
00044
00045 const support_t& org_supp = org.supp();
00046 for (typename support_t::const_iterator i = org_supp.begin();
00047 i != org_supp.end();
00048 ++i)
00049 {
00050 const sme_t &sm = sme_t(org.structure().monoid(), *i);
00051
00052 const me_t &m = me_t(dst.structure().monoid(), sm);
00053 const se_t &w = se_t(dst.structure().semiring(), org.get(sm));
00054
00055 dst += w * Element<S, T>(dst.structure(), m);
00056 }
00057
00058 postcondition(dst.is_finite_app());
00059 }
00060
00061 }
00062
00063 #endif // ! VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX