krat_conversion.hxx

00001 // krat_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 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_KRAT_CONVERSION_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_KRAT_CONVERSION_HXX
00019 
00020 # include <vaucanson/algebra/implementation/series/krat_conversion.hh>
00021 
00022 namespace vcsn {
00023 
00024   namespace algebra {
00025 
00026     /*------------------.
00027     | ExpConvertVisitor |
00028     `------------------*/
00029 
00030     template<typename Tm, typename Tw, typename oTm, typename oTw,
00031              typename Series_>
00032     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::ExpConvertVisitor(const Series_& s)
00033       : exp_(), series_(s)
00034     {}
00035 
00036 
00037     template<typename Tm, typename Tw, typename oTm, typename oTw,
00038              typename Series_>
00039     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::~ExpConvertVisitor()
00040     {}
00041 
00042     template<typename Tm, typename Tw, typename oTm, typename oTw,
00043              typename Series_>
00044      void
00045     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::product(const node_t* left_,
00046                                                  const node_t* right_)
00047     {
00048       right_->accept(*this);
00049       exp_t tmp = exp_;
00050       left_->accept(*this);
00051       op_in_mul(series_, exp_, tmp);
00052     }
00053 
00054     template<typename Tm, typename Tw, typename oTm, typename oTw,
00055              typename Series_>
00056      void
00057     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::sum(const node_t* left_,
00058                                              const node_t* right_)
00059     {
00060       right_->accept(*this);
00061       exp_t tmp = exp_;
00062       left_->accept(*this);
00063       op_in_add(series_, exp_, tmp);
00064     }
00065 
00066     template<typename Tm, typename Tw, typename oTm, typename oTw,
00067              typename Series_>
00068      void
00069     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::star(const node_t* node_)
00070     {
00071       node_->accept(*this);
00072       op_in_star(series_, exp_);
00073     }
00074 
00075     template<typename Tm, typename Tw, typename oTm, typename oTw,
00076              typename Series_>
00077      void
00078     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::left_weight(const oTw& w,
00079                                                               const node_t* node_)
00080     {
00081       node_->accept(*this);
00082       exp_ = op_mul(series_.semiring(), series_,
00083                     op_convert(SELECT(typename Series_::semiring_t),
00084                                SELECT(Tw),
00085                                w),
00086                     exp_);
00087     }
00088 
00089     template<typename Tm, typename Tw, typename oTm, typename oTw,
00090              typename Series_>
00091      void
00092     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::right_weight(const oTw& w,
00093                                                                const node_t*
00094                                                                  node_)
00095     {
00096       node_->accept(*this);
00097       op_in_mul(series_, series_.semiring(), exp_,
00098                 op_convert(SELECT(typename Series_::semiring_t),
00099                            SELECT(Tw),
00100                            w));
00101     }
00102 
00103     template<typename Tm, typename Tw, typename oTm, typename oTw,
00104              typename Series_>
00105      void
00106     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::constant(const oTm& m_)
00107     {
00108       Tm m = op_convert(SELECT(typename Series_::monoid_t),
00109                         SELECT(Tm),
00110                         m_);
00111       if (m == identity_value(SELECT(typename Series_::monoid_t),
00112                               SELECT(Tm)))
00113         exp_ = exp_t::one();
00114       else
00115         exp_ = exp_t::constant(m);
00116     }
00117 
00118     template<typename Tm, typename Tw, typename oTm, typename oTw,
00119              typename Series_>
00120      void
00121     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::one()
00122     {
00123       exp_ = exp_t::one();
00124     }
00125 
00126     template<typename Tm, typename Tw, typename oTm, typename oTw,
00127              typename Series_>
00128      void
00129     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::zero()
00130     {
00131       exp_ = exp_t::zero();
00132     }
00133 
00134     template<typename Tm, typename Tw, typename oTm, typename oTw,
00135              typename Series_>
00136     const typename ExpConvertVisitor<Tm,Tw,oTm,oTw,Series_>::exp_t&
00137     ExpConvertVisitor<Tm, Tw, oTm, oTw, Series_>::get() const
00138     {
00139       return exp_;
00140     }
00141 
00142     template<typename Tm, typename Tw, typename W, typename M,
00143              typename oTm, typename oTw>
00144     rat::exp<Tm, Tw>
00145     convert_exp(SELECTOR2(rat::exp<Tm, Tw>),
00146                 const Series<W, M>& s,
00147                 const rat::exp<oTm, oTw>& arg)
00148     {
00149       ExpConvertVisitor<Tm, Tw, oTm, oTw, Series<W, M> > v(s);
00150       arg.accept(v);
00151       return v.get();
00152     }
00153 
00154     template<typename W, typename M, typename Tm, typename Tw,
00155              typename oTm, typename oTw>
00156     Element<Series<W, M>, rat::exp<Tm, Tw> >
00157     convert_exp(SELECTOR4(Element<Series<W, M>, rat::exp<Tm, Tw> >),
00158                 const Element<Series<W, M>, rat::exp<oTm, oTw> >& arg)
00159     {
00160       return Element<Series<W, M>, rat::exp<Tm, Tw> >
00161         (arg.structure(),
00162          convert_exp(SELECT2(rat::exp<Tm, Tw>),
00163                      arg.structure(),
00164                      arg.value()));
00165     }
00166 
00167   } // algebra
00168 
00169 } // vcsn
00170 
00171 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_KRAT_CONVERSION_HXX

Generated on Sat Jul 29 17:13:01 2006 for Vaucanson by  doxygen 1.4.6