Awali
Another Weighted Automata library
size.hxx
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_CORE_RAT_SIZE_HXX
18 # define AWALI_CORE_RAT_SIZE_HXX
19 
20 namespace awali { namespace sttc
21 {
22  namespace rat
23  {
24 
25 # define DEFINE \
26  template <typename RatExpSet> \
27  inline \
28  auto \
29  size<RatExpSet>
30 
31 # define VISIT(Type) \
32  DEFINE::visit(const Type ## _t& v) \
33  -> void
34 
35  VISIT(zero)
36  {
37  (void) v;
38  ++ size_;
39  }
40 
41  VISIT(one)
42  {
43  (void) v;
44  ++ size_;
45  }
46 
47  VISIT(atom)
48  {
49  (void) v;
50  // FIXME: use the label size instead of 1. Labels don't have a size yet.
51  ++ size_;
52  }
53 
54  VISIT(lweight)
55  {
56  ++ size_;
57  v.sub()->accept(*this);
58  }
59 
60  VISIT(rweight)
61  {
62  ++ size_;
63  v.sub()->accept(*this);
64  }
65 
66  template <typename RatExpSet>
67  template <type_t Type>
68  inline
69  void
70  size<RatExpSet>::visit_unary(const unary_t<Type>& v)
71  {
72  ++ size_;
73  v.sub()->accept(*this);
74  }
75 
76  template <typename RatExpSet>
77  template <type_t Type>
78  inline
79  void
80  size<RatExpSet>::visit_variadic(const variadic_t<Type>& n)
81  {
82  /* An n-ary node contributes n-1 unit (plus the sum of its
83  children sizes) to the ratexp size. */
84  -- size_;
85  for (auto child : n)
86  {
87  ++ size_;
88  child->accept(*this);
89  }
90  }
91 
92 
93 # undef VISIT
94 # undef DEFINE
95 
96  } // namespace rat
97 }}//end of ns awali::stc
98 
99 #endif // !AWALI_CORE_RAT_SIZE_HXX
weight_node< type_t::lweight, Label, Weight > lweight
Definition: fwd.hh:164
constant< type_t::zero, Label, Weight > zero
Definition: fwd.hh:113
weight_node< type_t::rweight, Label, Weight > rweight
Definition: fwd.hh:167
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
Main namespace of Awali.
Definition: ato.hh:22
#define VISIT(Type)
Definition: size.hxx:31