Vaucanson  1.4.1
finite_support_conversion.hxx
1 // finite_support_conversion.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, 2008 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_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX
18 # define VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX
19 
20 # include <vaucanson/misc/usual_macros.hh>
22 # include <vaucanson/algebra/concept/monoid_base.hh> // For zero_as.
23 
25 
26 namespace vcsn
27 {
28 
29  template<typename S, typename T, typename Ss, typename Ts>
30  void
32  {
33  BENCH_TASK_SCOPED("finite_support_convert");
34  precondition(org.is_finite_app());
35 
36  typedef typename Element<S, T>::monoid_elt_t me_t;
37  typedef typename Element<S, T>::semiring_elt_t se_t;
38  typedef typename Element<Ss, Ts>::monoid_elt_t sme_t;
39  typedef typename Element<Ss, Ts>::semiring_elt_t sse_t;
40 
41  typedef typename Element<Ss, Ts>::support_t support_t;
42 
43  dst = algebra::zero_as<T>::of(dst.structure());
44 
45  const support_t& org_supp = org.supp();
46  for (typename support_t::const_iterator i = org_supp.begin();
47  i != org_supp.end();
48  ++i)
49  {
50  const sme_t &sm = sme_t(org.structure().monoid(), *i);
51 
52  const me_t &m = me_t(dst.structure().monoid(), sm);
53  const se_t &w = se_t(dst.structure().semiring(), org.get(sm));
54 
55  dst += w * Element<S, T>(dst.structure(), m);
56  }
57 
58  postcondition(dst.is_finite_app());
59  }
60 
61 }
62 
63 #endif // ! VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX