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