finite_support_conversion.hxx

00001 // finite_support_conversion.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_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> // For zero_as.
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 finite_support_convert(Element<S, T>& dst, const Element<Ss, Ts>& org)
00031   {
00032     TIMER_SCOPED("finite_support_convert");
00033     precondition(org.is_finite_app());
00034 
00035     typedef typename Element<S, T>::monoid_elt_t me_t;
00036     typedef typename Element<S, T>::semiring_elt_t se_t;
00037     typedef typename Element<Ss, Ts>::monoid_elt_t sme_t;
00038     typedef typename Element<Ss, Ts>::semiring_elt_t sse_t;
00039 
00040     typedef typename Element<Ss, Ts>::support_t support_t;
00041 
00042     dst = algebra::zero_as<T>::of(dst.structure());
00043 
00044     const support_t& org_supp = org.supp();
00045     for (typename support_t::const_iterator i = org_supp.begin();
00046          i != org_supp.end();
00047          ++i)
00048       {
00049         const sme_t &sm = sme_t(org.structure().monoid(), *i);
00050 
00051         const me_t &m = me_t(dst.structure().monoid(), sm);
00052         const se_t &w = se_t(dst.structure().semiring(), org.get(sm));
00053 
00054         dst += w * Element<S, T>(dst.structure(), m);
00055       }
00056 
00057     postcondition(dst.is_finite_app());
00058   }
00059 
00060 }
00061 
00062 #endif // ! VCSN_ALGORITHMS_FINITE_SUPPORT_CONVERSION_HXX

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