krat_exp_flatten.hxx

00001 // krat_exp_flatten.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2004, 2005 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_ALGORITHMS_KRAT_EXP_FLATTEN_HXX
00018 # define VCSN_ALGORITHMS_KRAT_EXP_FLATTEN_HXX
00019 
00020 # include <vaucanson/algorithms/krat_exp_flatten.hh>
00021 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
00022 
00023 namespace vcsn
00024 { 
00027   template <class Series, class T, class Dispatch>
00028   struct KRatExpFlatten : algebra::KRatExpMatcher<
00029     KRatExpFlatten<Series, T, Dispatch>,
00030     T,
00031     std::list<typename Series::monoid_t::alphabet_t::letter_t>,
00032     Dispatch
00033     >
00034   {
00035     typedef KRatExpFlatten<Series, T, Dispatch>         self_t;
00036     typedef typename Element<Series, T>::semiring_elt_t semiring_elt_t;
00037     typedef typename semiring_elt_t::value_t            semiring_elt_value_t;
00038     typedef typename Element<Series, T>::monoid_elt_t   monoid_elt_t;
00039     typedef typename monoid_elt_t::value_t              monoid_elt_value_t;
00040     typedef typename monoid_elt_t::set_t                monoid_t;
00041     typedef typename monoid_t::alphabet_t               alphabet_t;
00042     typedef typename alphabet_t::letter_t               letter_t;
00043     typedef std::list<typename Series::monoid_t::alphabet_t::letter_t>
00044                                                         return_type;
00045     INHERIT_CONSTRUCTORS(self_t, T, return_type, Dispatch);
00046 
00047     KRatExpFlatten(const Element<Series, T>& exp) : exp_(exp), res_ ()
00048     {
00049     }
00050 
00051     return_type
00052     flatten()
00053     {
00054       return match(exp_.value());
00055     }
00056 
00057     MATCH__(Product, lhs, rhs)
00058     {
00059       match(lhs);
00060       match(rhs);
00061       return res_;
00062     }
00063     END
00064 
00065     MATCH__(Sum, lhs, rhs)
00066     {
00067       match(lhs);
00068       match(rhs);
00069       return res_;
00070     }
00071     END
00072 
00073     MATCH_(Star, e)
00074     {
00075       match(e);
00076       return res_;
00077     }
00078     END
00079 
00080     MATCH__(LeftWeight, w, e)
00081     {
00082       w = w; // Dirty trick to avoid warinings.
00083       match(e);
00084       return res_;
00085     }
00086     END
00087 
00088     MATCH__(RightWeight, e, w)
00089     {
00090       w = w; // Dirty trick to avoid warinings.
00091       match(e);
00092       return res_;
00093     }
00094     END
00095 
00096     MATCH_(Constant, m)
00097     {
00098       for (size_t i = 0; i < m.length(); ++i)
00099         res_.push_back(m[i]);
00100       return res_;
00101     }
00102     END
00103 
00104     MATCH(Zero)
00105     {
00106       return res_;
00107     }
00108     END
00109 
00110     MATCH(One)
00111     {
00112       return res_;
00113     }
00114     END
00115 
00116   private:
00117     Element<Series, T>  exp_;
00118     return_type         res_;
00119   };
00120 
00121   template <class Series, class T>
00122   std::list<typename Series::monoid_t::alphabet_t::letter_t>
00123   flatten(const Element<Series, T>& exp)
00124   {
00125     KRatExpFlatten< Series, T, algebra::DispatchFunction<T> > matcher(exp);
00126     return matcher.flatten();
00127   }
00128 
00131 } // end of namepsace vcsn
00132 
00133 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_FLATTEN_HXX

Generated on Wed Jun 13 17:00:24 2007 for Vaucanson by  doxygen 1.5.1