Vcsn  2.8
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  /*--------.
41  | name. |
42  `--------*/
43 
45  : sub_{std::move(sub)}
46  , name_{name}
47  {}
48 
49  DEFINE(name)::sub() const
50  -> const value_t
51  {
52  return sub_;
53  }
54 
55  DEFINE(name)::name_get() const
56  -> symbol
57  {
58  return name_;
59  }
60 
61  DEFINE(name)::accept(typename super_t::const_visitor& v) const
62  -> void
63  {
64  v.visit(*this);
65  }
66 
67 #undef DEFINE_CTOR
68 #undef DEFINE
69 
70 
71 #define DEFINE_CTOR(Node) \
72  template <type_t Type, typename Context> \
73  Node<Type, Context>::Node
74 
75 #define DEFINE(Node) \
76  template <type_t Type, typename Context> \
77  auto \
78  Node<Type, Context>
79 
80 
81  /*-----------.
82  | variadic. |
83  `-----------*/
84 
86  : sub_(std::move(ns))
87  {}
88 
89 
90  DEFINE(variadic)::begin() const
92  {
93  return sub_.begin();
94  }
95 
96  DEFINE(variadic)::end() const
98  {
99  return sub_.end();
100  }
101 
102  DEFINE(variadic)::size() const
103  -> size_t
104  {
105  return sub_.size();
106  }
107 
108  DEFINE(variadic)::operator[](size_t n) const
109  -> const value_t
110  {
111  return sub_[n];
112  }
113 
114  DEFINE(variadic)::head() const
115  -> const value_t
116  {
117  return *begin();
118  }
119 
120  DEFINE(variadic)::back() const
121  -> const value_t
122  {
123  return sub_.back();
124  }
125 
126  DEFINE(variadic)::tail() const
127  -> decltype(boost::make_iterator_range(*this, 1, 0))
128  {
129  return boost::make_iterator_range(*this, 1, 0);
130  }
131 
132  DEFINE(variadic)::subs() const
133  -> values_t
134  {
135  return sub_;
136  }
137 
138  DEFINE(variadic)::accept(typename super_t::const_visitor& v) const
139  -> void
140  {
141  v.visit(*this);
142  }
143 
144  /*--------.
145  | unary. |
146  `--------*/
147 
149  : sub_(sub)
150  {}
151 
152  DEFINE(unary)::sub() const
153  -> const value_t
154  {
155  return sub_;
156  }
157 
158  DEFINE(unary)::accept(typename super_t::const_visitor& v) const
159  -> void
160  {
161  v.visit(*this);
162  }
163 
164  /*---------.
165  | weight. |
166  `---------*/
167 
169  : sub_(std::move(sub))
170  , weight_(weight)
171  {}
172 
173  DEFINE(weight_node)::sub() const
174  -> const value_t
175  {
176  return sub_;
177  }
178 
179  DEFINE(weight_node)::weight() const
180  -> const weight_t&
181  {
182  return weight_;
183  }
184 
185  DEFINE(weight_node)::set_weight(weight_t w)
186  -> void
187  {
188  weight_ = w;
189  }
190 
191  DEFINE(weight_node)::accept(typename super_t::const_visitor& v) const
192  -> void
193  {
194  v.visit(*this);
195  }
196 
197 
198  /*-----------.
199  | constant. |
200  `-----------*/
201 
202  DEFINE(constant)::accept(typename super_t::const_visitor& v) const
203  -> void
204  {
205  v.visit(*this);
206  }
207 
208 #undef DEFINE_CTOR
209 #undef DEFINE
210 
211  } // namespace rat
212 } // namespace vcsn
size_t size(const ExpSet &rs, const typename ExpSet::value_t &r)
std::vector< value_t > values_t
Definition: expression.hh:90
An inner node with multiple children.
Definition: expression.hh:119
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Definition: symbol.hh:21
#define DEFINE_CTOR(Node)
Definition: expression.hxx:71
#define DEFINE(Node)
Definition: expression.hxx:75
An inner node to name the subexpression.
Definition: expression.hh:290
Container::value_type back(const Container &container)
The last member of this Container.
Definition: algorithm.hh:37
label_t_of< Context > label_t
Definition: expression.hh:347
Definition: a-star.hh:8
std::shared_ptr< const node_t > value_t
An expression usable with value semantics.
Definition: expression.hh:89
The abstract parameterized, root for all rational expression types.
Definition: expression.hh:81
An inner node implementing a weight.
Definition: expression.hh:256
weight_t_of< Context > weight_t
Definition: expression.hh:265
return v
Definition: multiply.hh:362
Definition: filter.hh:56
typename values_t::const_iterator const_iterator
Definition: expression.hh:129
value_impl< detail::weight_tag > weight
Definition: fwd.hh:34