Vcsn  2.4
Be Rational
expression.hxx
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace vcsn
7 {
8  namespace rat
9  {
10 
11 #define DEFINE_CTOR(Node) \
12  template <typename Context> \
13  Node<Context>::Node
14 
15 #define DEFINE(Node) \
16  template <typename Context> \
17  auto \
18  Node<Context>
19 
20  /*-------.
21  | atom. |
22  `-------*/
23 
24  DEFINE_CTOR(atom)(const label_t& value)
25  : value_(value)
26  {}
27 
28  DEFINE(atom)::accept(typename super_t::const_visitor& v) const
29  -> void
30  {
31  v.visit(*this);
32  }
33 
34  DEFINE(atom)::value() const
35  -> const label_t&
36  {
37  return value_;
38  }
39 
40 #undef DEFINE_CTOR
41 #undef DEFINE
42 
43 
44 #define DEFINE_CTOR(Node) \
45  template <type_t Type, typename Context> \
46  Node<Type, Context>::Node
47 
48 #define DEFINE(Node) \
49  template <type_t Type, typename Context> \
50  auto \
51  Node<Type, Context>
52 
53 
54  /*-----------.
55  | variadic. |
56  `-----------*/
57 
59  : sub_(std::move(ns))
60  {}
61 
62 
63  DEFINE(variadic)::begin() const
65  {
66  return sub_.begin();
67  }
68 
69  DEFINE(variadic)::end() const
71  {
72  return sub_.end();
73  }
74 
75  DEFINE(variadic)::size() const
76  -> size_t
77  {
78  return sub_.size();
79  }
80 
81  DEFINE(variadic)::operator[](size_t n) const
82  -> const value_t
83  {
84  return sub_[n];
85  }
86 
87  DEFINE(variadic)::head() const
88  -> const value_t
89  {
90  return *begin();
91  }
92 
93  DEFINE(variadic)::back() const
94  -> const value_t
95  {
96  return sub_.back();
97  }
98 
99  DEFINE(variadic)::tail() const
100  -> decltype(boost::make_iterator_range(*this, 1, 0))
101  {
102  return boost::make_iterator_range(*this, 1, 0);
103  }
104 
105  DEFINE(variadic)::subs() const
106  -> values_t
107  {
108  return sub_;
109  }
110 
111  DEFINE(variadic)::accept(typename super_t::const_visitor& v) const
112  -> void
113  {
114  v.visit(*this);
115  }
116 
117  /*--------.
118  | unary. |
119  `--------*/
120 
122  : sub_(sub)
123  {}
124 
125  DEFINE(unary)::sub() const
126  -> const value_t
127  {
128  return sub_;
129  }
130 
131  DEFINE(unary)::accept(typename super_t::const_visitor& v) const
132  -> void
133  {
134  v.visit(*this);
135  }
136 
137  /*---------.
138  | weight. |
139  `---------*/
140 
142  : sub_(std::move(sub))
143  , weight_(weight)
144  {}
145 
146  DEFINE(weight_node)::sub() const
147  -> const value_t
148  {
149  return sub_;
150  }
151 
152  DEFINE(weight_node)::weight() const
153  -> const weight_t&
154  {
155  return weight_;
156  }
157 
158  DEFINE(weight_node)::set_weight(weight_t w)
159  -> void
160  {
161  weight_ = w;
162  }
163 
164  DEFINE(weight_node)::accept(typename super_t::const_visitor& v) const
165  -> void
166  {
167  v.visit(*this);
168  }
169 
170 
171  /*-----------.
172  | constant. |
173  `-----------*/
174 
175  DEFINE(constant)::accept(typename super_t::const_visitor& v) const
176  -> void
177  {
178  v.visit(*this);
179  }
180 
181 #undef DEFINE_CTOR
182 #undef DEFINE
183 
184  } // namespace rat
185 } // namespace vcsn
#define DEFINE_CTOR(Node)
Definition: expression.hxx:44
std::shared_ptr< const node_t > value_t
An expression usable with value semantics.
Definition: expression.hh:88
std::vector< value_t > values_t
Definition: expression.hh:89
label_t_of< Context > label_t
Definition: expression.hh:319
value_impl< detail::weight_tag > weight
Definition: fwd.hh:28
An inner node implementing a weight.
Definition: expression.hh:255
Definition: filter.hh:56
Definition: a-star.hh:8
#define DEFINE(Node)
Definition: expression.hxx:48
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
An inner node with multiple children.
Definition: expression.hh:118
return v
Definition: multiply.hh:361
Container::value_type back(const Container &container)
The last member of this Container.
Definition: algorithm.hh:37
typename values_t::const_iterator const_iterator
Definition: expression.hh:128
weight_t_of< Context > weight_t
Definition: expression.hh:264
The abstract parameterized, root for all rational expression types.
Definition: expression.hh:80