Vaucanson  1.4.1
krat_exp_flatten.hxx
1 // krat_exp_flatten.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, 2011 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_ALGORITHMS_KRAT_EXP_FLATTEN_HXX
18 # define VCSN_ALGORITHMS_KRAT_EXP_FLATTEN_HXX
19 
21 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
22 
23 namespace vcsn
24 {
27  template <class Series, class T, class Dispatch>
28  struct KRatExpFlatten : algebra::KRatExpMatcher<
29  KRatExpFlatten<Series, T, Dispatch>,
30  T,
31  std::list<typename Series::monoid_t::alphabet_t::letter_t>,
32  Dispatch
33  >
34  {
36  typedef typename Element<Series, T>::semiring_elt_t semiring_elt_t;
37  typedef typename semiring_elt_t::value_t semiring_elt_value_t;
38  typedef typename Element<Series, T>::monoid_elt_t monoid_elt_t;
39  typedef typename monoid_elt_t::value_t monoid_elt_value_t;
40  typedef typename monoid_elt_t::set_t monoid_t;
41  typedef typename monoid_t::alphabet_t alphabet_t;
42  typedef typename alphabet_t::letter_t letter_t;
43  typedef std::list<typename Series::monoid_t::alphabet_t::letter_t>
44  return_type;
45  INHERIT_CONSTRUCTORS(self_t, T, return_type, Dispatch);
46 
47  KRatExpFlatten(const Element<Series, T>& exp) : exp_(exp), res_ ()
48  {
49  }
50 
51  return_type
52  flatten()
53  {
54  return this->match(exp_.value());
55  }
56 
57  MATCH__(Product, lhs, rhs)
58  {
59  this->match(lhs);
60  this->match(rhs);
61  return res_;
62  }
63  END
64 
65  MATCH__(Sum, lhs, rhs)
66  {
67  this->match(lhs);
68  this->match(rhs);
69  return res_;
70  }
71  END
72 
73  MATCH_(Star, e)
74  {
75  this->match(e);
76  return res_;
77  }
78  END
79 
80  MATCH__(LeftWeight, w, e)
81  {
82  (void)w;
83  this->match(e);
84  return res_;
85  }
86  END
87 
88  MATCH__(RightWeight, e, w)
89  {
90  (void)w;
91  this->match(e);
92  return res_;
93  }
94  END
95 
96  MATCH_(Constant, m)
97  {
98  for (size_t i = 0; i < m.length(); ++i)
99  res_.push_back(m[i]);
100  return res_;
101  }
102  END
103 
104  MATCH(Zero)
105  {
106  return res_;
107  }
108  END
109 
110  MATCH(One)
111  {
112  return res_;
113  }
114  END
115 
116  private:
117  Element<Series, T> exp_;
118  return_type res_;
119  };
120 
121  template <class Series, class T>
122  std::list<typename Series::monoid_t::alphabet_t::letter_t>
124  {
126  return matcher.flatten();
127  }
128 
131 } // end of namepsace vcsn
132 
133 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_FLATTEN_HXX