Vaucanson  1.4.1
star_height_visitor.hxx
1 // star_height_visitor.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2005 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_ALGEBRA_IMPLEMENTATION_SERIES_RAT_STAR_HEIGHT_VISITOR_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_STAR_HEIGHT_VISITOR_HXX
19 
20 # include <algorithm>
21 
22 # include <vaucanson/algebra/implementation/series/rat/star_height_visitor.hh>
23 
24 namespace vcsn {
25 
26  namespace rat {
27 
28  template<typename M_, typename W_>
29  void
30  StarHeightVisitor<M_,W_>::sum_or_product(const Node<M_, W_>* left_,
31  const Node<M_, W_>* right_)
32  {
33  size_t post = h_;
34  left_->accept(*this);
35  size_t left_height = h_;
36  h_ = post;
37  right_->accept(*this);
38  h_ = std::max(h_, left_height);
39  }
40 
41  template<typename M_, typename W_>
42  void
43  StarHeightVisitor<M_, W_>::weight_or_star(const Node<M_, W_>* node)
44  {
45  node->accept(*this);
46  }
47 
48  template<typename M_, typename W_>
49  void
50  StarHeightVisitor<M_, W_>::product(const Node<M_, W_>* left_,
51  const Node<M_, W_>* right_)
52  {
53  sum_or_product(left_, right_);
54  }
55 
56  template<typename M_, typename W_>
57  void
58  StarHeightVisitor<M_, W_>::sum(const Node<M_, W_>* left_,
59  const Node<M_, W_>* right_)
60  {
61  sum_or_product(left_, right_);
62  }
63 
64  template<typename M_, typename W_>
65  void
66  StarHeightVisitor<M_, W_>::star(const Node<M_, W_>* node)
67  {
68  h_++;
69  node->accept(*this);
70  }
71 
72  template<typename M_, typename W_>
73  void
74  StarHeightVisitor<M_, W_>::left_weight(const W_&, const Node<M_, W_>* node)
75  {
76  weight_or_star(node);
77  }
78 
79  template<typename M_, typename W_>
80  void
81  StarHeightVisitor<M_, W_>::right_weight(const W_&, const Node<M_, W_>* node)
82  {
83  weight_or_star(node);
84  }
85 
86  template<typename M_, typename W_>
87  void
88  StarHeightVisitor<M_, W_>::constant(const M_&)
89  {
90  }
91 
92  template<typename M_, typename W_>
93  void StarHeightVisitor<M_, W_>::zero()
94  {
95  }
96 
97  template<typename M_, typename W_>
98  void StarHeightVisitor<M_, W_>::one()
99  {
100  }
101 
102  template<typename M_, typename W_>
103  size_t StarHeightVisitor<M_, W_>::get() const
104  {
105  return h_;
106  }
107 
108  } // End of namespace rat.
109 
110 } // End of namespace vcsn.
111 
112 
113 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_STAR_HEIGHT_VISITOR_HXX