reverse_visitor.hxx

00001 // reverse_visitor.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004 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_RAT_REVERSE_VISITOR_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_REVERSE_VISITOR_HXX
00019 
00020 # include <vaucanson/algebra/implementation/series/rat/reverse_visitor.hh>
00021 
00022 namespace vcsn
00023 {
00024 
00025   namespace rat
00026   {
00027 
00028     template <class Semiring, class Word, class Weight>
00029     ReverseVisitor<Semiring, Word, Weight>::
00030     ReverseVisitor(const algebra::SemiringBase<Semiring>& s) : s_ (s)
00031     {}
00032 
00033     template <class Semiring, class Word, class Weight>
00034     void
00035     ReverseVisitor<Semiring, Word, Weight>::
00036     product(rat::Node<Word, Weight>* lhs, rat::Node<Word, Weight>* rhs)
00037     {
00038       lhs->accept(*this);
00039       rhs->accept(*this);
00040       swap(lhs, rhs);
00041     }
00042 
00043     template <class Semiring, class Word, class Weight>
00044     void
00045     ReverseVisitor<Semiring, Word, Weight>::left_weight(Weight& w)
00046     {
00047       w = transpose(w);
00048     }
00049 
00050     template <class Semiring, class Word, class Weight>
00051     void
00052     ReverseVisitor<Semiring, Word, Weight>::right_weight(Weight& w)
00053     {
00054       w = transpose(s_, w);
00055     }
00056 
00057     template <class Semiring, class Word, class Weight>
00058     void
00059     ReverseVisitor<Semiring, Word, Weight>::constant(Word& w)
00060     {
00061       w = mirror(w);
00062     }
00063 
00064     template <class Semiring, class Word, class Weight>
00065     template <class S>
00066     Weight
00067     ReverseVisitor<Semiring, Word, Weight>::
00068     transpose(const algebra::SeriesBase<S>& s, const Weight& w)
00069     {
00070       Element<S, Weight> e (s, w);
00071       e.transpose();
00072       return e.value();
00073     }
00074 
00075     template <class Semiring, class Word, class Weight>
00076     template <class S>
00077     Weight
00078     ReverseVisitor<Semiring, Word, Weight>::
00079     transpose(const algebra::SemiringBase<S>&, const Weight& w)
00080     {
00081       return w;
00082     }
00083 
00084   } // End of namespace rat.
00085 
00086   namespace algebra
00087   {
00088 
00089     template <typename S, typename Word, typename Weight>
00090     rat::exp<Word, Weight>&
00091     DefaultTransposeFun< S, rat::exp<Word, Weight> >::
00092     operator () (const S& s, const rat::exp<Word, Weight>& exp)
00093     {
00094       rat::exp<Word, Weight>* rexp = new rat::exp<Word, Weight> (exp);
00095       rat::ReverseVisitor<typename S::semiring_t, Word, Weight>
00096         rv (s.semiring());
00097 
00098       rexp.accept(rv);
00099       return *rexp;
00100     }
00101 
00102   } // End of namespace algebra.
00103 
00104 } // End of namespace vcsn.
00105 
00106 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_REVERSE_VISITOR_HXX

Generated on Fri Jul 28 12:18:51 2006 for Vaucanson by  doxygen 1.4.6