Vaucanson  1.4.1
generalized.hxx
1 // generalized.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, 2007 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_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX
19 
21 # include <vaucanson/algebra/concept/series_base.hh>
22 # include <vaucanson/algebra/implementation/series/polynoms.hh>
23 # include <vaucanson/algebra/implementation/series/krat.hh>
24 
25 namespace vcsn {
26 
27  namespace algebra {
28 
29  /*----------------------.
30  | Generalized converter |
31  `----------------------*/
32  template<typename W, typename M, typename Tm, typename Tw>
33  rat::exp<Tm, Tw> op_convert(const algebra::Series<W, M>& s1,
34  SELECTOR2(rat::exp<Tm, Tw>),
35  const algebra::Series<W, M>& s2,
36  const algebra::polynom<Tm, Tw>& p_value)
37  {
38  precondition(& s1 == & s2);
39 
40  typedef rat::exp<Tm, Tw> kexp_t;
41  kexp_t exp;
42 
43  if (p_value == identity_value(SELECT2(algebra::Series<W, M>),
44  SELECT2(algebra::polynom<Tm, Tw>)))
45  return kexp_t::one();
46 
47  if (p_value == zero_value(SELECT2(algebra::Series<W, M>),
48  SELECT2(algebra::polynom<Tm, Tw>)))
49  return kexp_t::zero();
50 
51  for (typename algebra::polynom<Tm, Tw>::const_iterator p = p_value.begin();
52  p != p_value.end();
53  ++p)
54  if (exp == kexp_t::zero())
55  exp = (*p).second * kexp_t::constant((*p).first);
56  else
57  exp += (*p).second * kexp_t::constant((*p).first);
58  return exp;
59  }
60 
61  } // algebra
62 
63 } // vcsn
64 
65 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_GENERALIZED_HXX