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