Awali
Another Weighted Automata library
size.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 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_HH
18 # define AWALI_CORE_RAT_SIZE_HH
19 
22 #include <awali/sttc/misc/cast.hh>
23 
24 namespace awali { namespace sttc
25 {
26  namespace rat
27  {
28  template <typename RatExpSet>
29  class size
30  : public RatExpSet::const_visitor
31  {
32  public:
33  using ratexpset_t = RatExpSet;
35  using weight_t = typename context_t::weightset_t::value_t;
36  using super_type = typename ratexpset_t::const_visitor;
37  using node_t = typename super_type::node_t;
38  using inner_t = typename super_type::inner_t;
39  template <type_t Type>
40  using unary_t = typename super_type::template unary_t<Type>;
41  template <type_t Type>
42  using variadic_t = typename super_type::template variadic_t<Type>;
43  using leaf_t = typename super_type::leaf_t;
44 
46  size_t
47  operator()(const node_t& v)
48  {
49  size_ = 0;
50  v.accept(*this);
51  return size_;
52  }
53 
55  size_t
56  operator()(const std::shared_ptr<const node_t>& v)
57  {
58  return operator()(*v);
59  }
60 
61  private:
62 
63 # define DEFINE(Type) \
64  using Type ## _t = typename super_type::Type ## _t; \
65  virtual void visit(const Type ## _t& v) override
66 
67  DEFINE(atom);
68  DEFINE(complement) { visit_unary(v); }
69  DEFINE(conjunction) { visit_variadic(v); }
70  DEFINE(ldiv) { visit_variadic(v); }
71  DEFINE(lweight);
72  DEFINE(one);
73  DEFINE(prod) { visit_variadic(v); };
74  DEFINE(rweight);
75  DEFINE(shuffle) { visit_variadic(v); };
76  DEFINE(star) { visit_unary(v); }
77  DEFINE(sum) { visit_variadic(v); };
78  DEFINE(transposition){ visit_unary(v); }
79  DEFINE(zero);
80 
81 # undef DEFINE
82 
84  template <rat::exp::type_t Type>
85  void visit_unary(const unary_t<Type>& n);
86 
88  template <rat::exp::type_t Type>
89  void visit_variadic(const variadic_t<Type>& n);
90 
91  size_t size_;
92  };
93  } // namespace rat
94 }}//end of ns awali::stc
95 
97 
98 #endif // !AWALI_CORE_RAT_SIZE_HH
Definition: size.hh:31
context_t_of< ratexpset_t > context_t
Definition: size.hh:34
RatExpSet ratexpset_t
Definition: size.hh:33
size_t operator()(const std::shared_ptr< const node_t > &v)
Entry point: return the size of v.
Definition: size.hh:56
typename context_t::weightset_t::value_t weight_t
Definition: size.hh:35
size_t operator()(const node_t &v)
Entry point: return the size of v.
Definition: size.hh:47
typename super_type::node_t node_t
Definition: size.hh:37
typename ratexpset_t::const_visitor super_type
Definition: size.hh:36
typename super_type::template unary_t< Type > unary_t
Definition: size.hh:40
typename super_type::template variadic_t< Type > variadic_t
Definition: size.hh:42
typename super_type::leaf_t leaf_t
Definition: size.hh:43
typename super_type::inner_t inner_t
Definition: size.hh:38
variadic< type_t::sum, Label, Weight > sum
Definition: fwd.hh:154
weight_node< type_t::lweight, Label, Weight > lweight
Definition: fwd.hh:164
unary< type_t::star, Label, Weight > star
Definition: fwd.hh:129
constant< type_t::zero, Label, Weight > zero
Definition: fwd.hh:113
variadic< type_t::ldiv, Label, Weight > ldiv
Definition: fwd.hh:148
variadic< type_t::conjunction, Label, Weight > conjunction
Definition: fwd.hh:145
variadic< type_t::shuffle, Label, Weight > shuffle
Definition: fwd.hh:151
weight_node< type_t::rweight, Label, Weight > rweight
Definition: fwd.hh:167
unary< type_t::transposition, Label, Weight > transposition
Definition: fwd.hh:132
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
unary< type_t::complement, Label, Weight > complement
Definition: fwd.hh:126
variadic< type_t::prod, Label, Weight > prod
Definition: fwd.hh:142
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
Main namespace of Awali.
Definition: ato.hh:22
#define DEFINE(Type)
Definition: size.hh:63