00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 this->match(exp_.value());
00055 }
00056
00057 MATCH__(Product, lhs, rhs)
00058 {
00059 this->match(lhs);
00060 this->match(rhs);
00061 return res_;
00062 }
00063 END
00064
00065 MATCH__(Sum, lhs, rhs)
00066 {
00067 this->match(lhs);
00068 this->match(rhs);
00069 return res_;
00070 }
00071 END
00072
00073 MATCH_(Star, e)
00074 {
00075 this->match(e);
00076 return res_;
00077 }
00078 END
00079
00080 MATCH__(LeftWeight, w, e)
00081 {
00082 (void)w;
00083 this->match(e);
00084 return res_;
00085 }
00086 END
00087
00088 MATCH__(RightWeight, e, w)
00089 {
00090 (void)w;
00091 this->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 }
00132
00133 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_FLATTEN_HXX