Vaucanson 1.4
generalized.hxx
00001 // generalized.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, 2007 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_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX
00019 
00020 # include <vaucanson/misc/selectors.hh>
00021 # include <vaucanson/algebra/concept/series_base.hh>
00022 # include <vaucanson/algebra/implementation/series/polynoms.hh>
00023 # include <vaucanson/algebra/implementation/series/krat.hh>
00024 
00025 namespace vcsn {
00026 
00027   namespace algebra {
00028 
00029     /*----------------------.
00030     | Generalized converter |
00031     `----------------------*/
00032     template<typename W, typename M, typename Tm, typename Tw>
00033     rat::exp<Tm, Tw> op_convert(const algebra::Series<W, M>& s1,
00034                                 SELECTOR2(rat::exp<Tm, Tw>),
00035                                 const algebra::Series<W, M>& s2,
00036                                 const algebra::polynom<Tm, Tw>& p_value)
00037     {
00038       precondition(& s1 == & s2);
00039 
00040       typedef rat::exp<Tm, Tw> kexp_t;
00041       kexp_t    exp;
00042 
00043       if (p_value == identity_value(SELECT2(algebra::Series<W, M>),
00044                                     SELECT2(algebra::polynom<Tm, Tw>)))
00045         return kexp_t::one();
00046 
00047       if (p_value == zero_value(SELECT2(algebra::Series<W, M>),
00048                                 SELECT2(algebra::polynom<Tm, Tw>)))
00049         return kexp_t::zero();
00050 
00051       for (typename algebra::polynom<Tm, Tw>::const_iterator p = p_value.begin();
00052            p != p_value.end();
00053            ++p)
00054         if (exp == kexp_t::zero())
00055           exp = (*p).second *  kexp_t::constant((*p).first);
00056         else
00057           exp += (*p).second *  kexp_t::constant((*p).first);
00058       return exp;
00059     }
00060 
00061   } // algebra
00062 
00063 } // vcsn
00064 
00065 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX