Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
size.hh
Go to the documentation of this file.
1 #ifndef VCSN_CORE_RAT_SIZE_HH
2 # define VCSN_CORE_RAT_SIZE_HH
3 
4 # include <vcsn/core/rat/visitor.hh>
5 # include <vcsn/misc/attributes.hh>
6 # include <vcsn/misc/cast.hh>
7 
8 namespace vcsn
9 {
10  namespace rat
11  {
12  template <typename RatExpSet>
13  class size
14  : public RatExpSet::const_visitor
15  {
16  public:
17  using ratexpset_t = RatExpSet;
19  using weight_t = typename context_t::weightset_t::value_t;
20  using super_t = typename ratexpset_t::const_visitor;
21  using node_t = typename super_t::node_t;
22  using inner_t = typename super_t::inner_t;
23  template <type_t Type>
24  using unary_t = typename super_t::template unary_t<Type>;
25  template <type_t Type>
26  using variadic_t = typename super_t::template variadic_t<Type>;
27  using leaf_t = typename super_t::leaf_t;
28 
30  size_t
31  operator()(const node_t& v)
32  {
33  size_ = 0;
34  v.accept(*this);
35  return size_;
36  }
37 
39  size_t
40  operator()(const std::shared_ptr<const node_t>& v)
41  {
42  return operator()(*v);
43  }
44 
45  private:
46 
47 # define DEFINE(Type) \
48  using Type ## _t = typename super_t::Type ## _t; \
49  virtual void visit(const Type ## _t& v)
50 
64 
65 # undef DEFINE
66 
68  template <rat::exp::type_t Type>
69  void visit_unary(const unary_t<Type>& n);
70 
72  template <rat::exp::type_t Type>
73  void visit_variadic(const variadic_t<Type>& n);
74 
75  size_t size_;
76  };
77  } // namespace rat
78 } // namespace vcsn
79 
80 # include <vcsn/core/rat/size.hxx>
81 
82 #endif // !VCSN_CORE_RAT_SIZE_HH
An inner node with multiple children.
Definition: fwd.hh:123
typename super_t::template variadic_t< Type > variadic_t
Definition: size.hh:26
void visit_unary(const unary_t< Type > &n)
Traverse unary node.
Definition: size.hxx:54
typename context_t::weightset_t::value_t weight_t
Definition: size.hh:19
void visit_variadic(const variadic_t< Type > &n)
Traverse variadic node.
Definition: size.hxx:64
typename super_t::inner_t inner_t
Definition: size.hh:22
typename super_t::template unary_t< Type > unary_t
Definition: size.hh:24
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:32
#define DEFINE(Type)
Definition: size.hh:47
RatExpSet ratexpset_t
Definition: size.hh:17
typename super_t::node_t node_t
Definition: size.hh:21
size_t operator()(const std::shared_ptr< const node_t > &v)
Entry point: return the size of v.
Definition: size.hh:40
typename ratexpset_t::const_visitor super_t
Definition: size.hh:20
typename super_t::leaf_t leaf_t
Definition: size.hh:27
size_t size_
Definition: size.hh:75
An inner node implementing a weight.
Definition: fwd.hh:145
size_t operator()(const node_t &v)
Entry point: return the size of v.
Definition: size.hh:31
context_t_of< ratexpset_t > context_t
Definition: size.hh:18