Vaucanson  1.4.1
reverse_visitor.hxx
1 // reverse_visitor.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005 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_RAT_REVERSE_VISITOR_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_REVERSE_VISITOR_HXX
19 
20 # include <vaucanson/algebra/implementation/series/rat/reverse_visitor.hh>
21 
22 namespace vcsn
23 {
24 
25  namespace rat
26  {
27 
28  template <class Semiring, class Word, class Weight>
29  ReverseVisitor<Semiring, Word, Weight>::
30  ReverseVisitor(const algebra::SemiringBase<Semiring>& s) : s_ (s)
31  {}
32 
33  template <class Semiring, class Word, class Weight>
34  void
35  ReverseVisitor<Semiring, Word, Weight>::
36  product(rat::Node<Word, Weight>* lhs, rat::Node<Word, Weight>* rhs)
37  {
38  lhs->accept(*this);
39  rhs->accept(*this);
40  swap(lhs, rhs);
41  }
42 
43  template <class Semiring, class Word, class Weight>
44  void
45  ReverseVisitor<Semiring, Word, Weight>::left_weight(Weight& w)
46  {
47  w = transpose(w);
48  }
49 
50  template <class Semiring, class Word, class Weight>
51  void
52  ReverseVisitor<Semiring, Word, Weight>::right_weight(Weight& w)
53  {
54  w = transpose(s_, w);
55  }
56 
57  template <class Semiring, class Word, class Weight>
58  void
59  ReverseVisitor<Semiring, Word, Weight>::constant(Word& w)
60  {
61  w = mirror(w);
62  }
63 
64  template <class Semiring, class Word, class Weight>
65  template <class S>
66  Weight
68  transpose(const algebra::SeriesBase<S>& s, const Weight& w)
69  {
70  Element<S, Weight> e (s, w);
71  e.transpose();
72  return e.value();
73  }
74 
75  template <class Semiring, class Word, class Weight>
76  template <class S>
77  Weight
79  transpose(const algebra::SemiringBase<S>&, const Weight& w)
80  {
81  return w;
82  }
83 
84  } // End of namespace rat.
85 
86  namespace algebra
87  {
88 
89  template <typename S, typename Word, typename Weight>
90  rat::exp<Word, Weight>&
91  DefaultTransposeFun< S, rat::exp<Word, Weight> >::
92  operator () (const S& s, const rat::exp<Word, Weight>& exp)
93  {
94  rat::exp<Word, Weight>* rexp = new rat::exp<Word, Weight> (exp);
95  rat::ReverseVisitor<typename S::semiring_t, Word, Weight>
96  rv (s.semiring());
97 
98  rexp.accept(rv);
99  return *rexp;
100  }
101 
102  } // End of namespace algebra.
103 
104 } // End of namespace vcsn.
105 
106 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_REVERSE_VISITOR_HXX