Vcsn  2.3
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)::rbegin() const
77  {
78  return sub_.begin();
79  }
80 
81  DEFINE(variadic)::rend() const
83  {
84  return sub_.end();
85  }
86 
87  DEFINE(variadic)::size() const
88  -> size_t
89  {
90  return sub_.size();
91  }
92 
93  DEFINE(variadic)::operator[](size_t n) const
94  -> const value_t
95  {
96  return sub_[n];
97  }
98 
99  DEFINE(variadic)::head() const
100  -> const value_t
101  {
102  return *begin();
103  }
104 
105  DEFINE(variadic)::back() const
106  -> const value_t
107  {
108  return sub_.back();
109  }
110 
111  DEFINE(variadic)::tail() const
112  -> decltype(boost::make_iterator_range(*this, 1, 0))
113  {
114  return boost::make_iterator_range(*this, 1, 0);
115  }
116 
117  DEFINE(variadic)::subs() const
118  -> values_t
119  {
120  return sub_;
121  }
122 
123  DEFINE(variadic)::accept(typename super_t::const_visitor& v) const
124  -> void
125  {
126  v.visit(*this);
127  }
128 
129  /*--------.
130  | unary. |
131  `--------*/
132 
134  : sub_(sub)
135  {}
136 
137  DEFINE(unary)::sub() const
138  -> const value_t
139  {
140  return sub_;
141  }
142 
143  DEFINE(unary)::accept(typename super_t::const_visitor& v) const
144  -> void
145  {
146  v.visit(*this);
147  }
148 
149  /*---------.
150  | weight. |
151  `---------*/
152 
154  : sub_(std::move(sub))
155  , weight_(weight)
156  {}
157 
158  DEFINE(weight_node)::sub() const
159  -> const value_t
160  {
161  return sub_;
162  }
163 
164  DEFINE(weight_node)::weight() const
165  -> const weight_t&
166  {
167  return weight_;
168  }
169 
170  DEFINE(weight_node)::set_weight(weight_t w)
171  -> void
172  {
173  weight_ = w;
174  }
175 
176  DEFINE(weight_node)::accept(typename super_t::const_visitor& v) const
177  -> void
178  {
179  v.visit(*this);
180  }
181 
182 
183  /*-----------.
184  | constant. |
185  `-----------*/
186 
187  DEFINE(constant)::accept(typename super_t::const_visitor& v) const
188  -> void
189  {
190  v.visit(*this);
191  }
192 
193 #undef DEFINE_CTOR
194 #undef DEFINE
195 
196  } // namespace rat
197 } // namespace vcsn
return v
Definition: multiply.hh:361
value_impl< detail::weight_tag > weight
Definition: fwd.hh:28
The abstract parameterized, root for all rational expression types.
Definition: expression.hh:80
label_t_of< Context > label_t
Definition: expression.hh:332
typename values_t::const_iterator const_iterator
Definition: expression.hh:128
std::shared_ptr< const node_t > value_t
An expression usable with value semantics.
Definition: expression.hh:88
#define DEFINE(Node)
Definition: expression.hxx:48
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
An inner node implementing a weight.
Definition: expression.hh:264
#define DEFINE_CTOR(Node)
Definition: expression.hxx:44
weight_t_of< Context > weight_t
Definition: expression.hh:273
typename values_t::const_reverse_iterator const_reverse_iterator
Definition: expression.hh:133
std::vector< value_t > values_t
Definition: expression.hh:89
Definition: a-star.hh:8
An inner node with multiple children.
Definition: expression.hh:118
Container::value_type back(const Container &container)
The last member of this Container.
Definition: algorithm.hh:37