Awali
Another Weighted Automata library
ratexp.hxx
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_CORE_RAT_RATEXP_HXX_
18 # define AWALI_CORE_RAT_RATEXP_HXX_
19 
22 
23 namespace awali { namespace sttc
24 {
25  namespace rat
26  {
27 
28 #define DEFINE_CTOR(Node) \
29  template <typename Label, typename Weight> \
30  inline \
31  Node<Label, Weight>::Node
32 
33 #define DEFINE(Node) \
34  template <typename Label, typename Weight> \
35  inline \
36  auto \
37  Node<Label, Weight>
38 
39  /*-------.
40  | atom. |
41  `-------*/
42 
44  : value_(value)
45  {}
46 
47  DEFINE(atom)::accept(typename node_t::const_visitor& v) const
48  -> void
49  {
50  v.visit(*this);
51  }
52 
53  DEFINE(atom)::value() const
54  -> const label_t&
55  {
56  return value_;
57  }
58 
59 # undef DEFINE_CTOR
60 # undef DEFINE
61 
62 
63 #define DEFINE_CTOR(Node) \
64  template <type_t Type, typename Label, typename Weight> \
65  inline \
66  Node<Type, Label, Weight>::Node
67 
68 #define DEFINE(Node) \
69  template <type_t Type, typename Label, typename Weight> \
70  inline \
71  auto \
72  Node<Type, Label, Weight>
73 
74 
75  /*-----------.
76  | variadic. |
77  `-----------*/
78 
80  : sub_(ns)
81  {}
82 
83 
84  DEFINE(variadic)::begin() const
86  {
87  return sub_.begin();
88  }
89 
90  DEFINE(variadic)::end() const
92  {
93  return sub_.end();
94  }
95 
96  DEFINE(variadic)::rbegin() const
98  {
99  return sub_.rbegin();
100  }
101 
102  DEFINE(variadic)::rend() const
104  {
105  return sub_.rend();
106  }
107 
108  DEFINE(variadic)::size() const
109  -> size_t
110  {
111  return sub_.size();
112  }
113 
114  DEFINE(variadic)::operator[](size_t n) const
115  -> const value_t
116  {
117  return sub_[n];
118  }
119 
120  DEFINE(variadic)::head() const
121  -> const value_t
122  {
123  return *begin();
124  }
125 
126  DEFINE(variadic)::back() const
127  -> const value_t
128  {
129  return sub_.back();
130  }
131 
132  DEFINE(variadic)::tail() const
133  -> internal::it_cont<const_iterator>
134  {
135  auto it=begin();
136  return internal::it_cont<const_iterator>(++it,end());
137  }
138 
139  DEFINE(variadic)::subs() const
140  -> ratexps_t
141  {
142  return sub_;
143  }
144 
145  DEFINE(variadic)::accept(typename node_t::const_visitor& v) const
146  -> void
147  {
148  v.visit(*this);
149  }
150 
151  /*---------.
152  | weight. |
153  `---------*/
154 
156  : sub_(sub)
157  , weight_(weight)
158  {}
159 
160  DEFINE(weight_node)::sub() const
161  -> const value_t
162  {
163  return sub_;
164  }
165 
166  DEFINE(weight_node)::weight() const
167  -> const weight_t&
168  {
169  return weight_;
170  }
171 
172  DEFINE(weight_node)::set_weight(const weight_t& w)
173  -> void
174  {
175  weight_ = w;
176  }
177 
178  DEFINE(weight_node)::accept(typename node_t::const_visitor& v) const
179  -> void
180  {
181  v.visit(*this);
182  }
183 
184  /*--------.
185  | unary. |
186  `--------*/
187 
189  : sub_(sub)
190  {}
191 
192  DEFINE(unary)::sub() const
193  -> const value_t
194  {
195  return sub_;
196  }
197 
198  DEFINE(unary)::accept(typename node_t::const_visitor& v) const
199  -> void
200  {
201  v.visit(*this);
202  }
203 
204  /*-----------.
205  | constant. |
206  `-----------*/
207 
208  DEFINE(constant)::accept(typename node_t::const_visitor& v) const
209  -> void
210  {
211  v.visit(*this);
212  }
213 
214 # undef DEFINE_CTOR
215 # undef DEFINE
216 
217  } // namespace exp
218 }}//end of ns awali::stc
219 
220 #endif // !AWALI_CORE_RAT_RATEXP_HXX_
The semiring of Natural numbers.
Definition: n.hh:34
Definition: ratexp.hh:280
Definition: visitor.hh:30
Definition: ratexp.hh:262
The abstract parameterized, root for all rational expression types.
Definition: ratexp.hh:74
Weight weight_t
Definition: ratexp.hh:77
std::shared_ptr< const node_t > value_t
Definition: ratexp.hh:79
std::vector< value_t > ratexps_t
Definition: ratexp.hh:82
Label label_t
Definition: ratexp.hh:76
Definition: size.hh:31
Definition: ratexp.hh:176
An inner node with multiple children.
Definition: ratexp.hh:115
typename ratexps_t::const_iterator const_iterator
Definition: ratexp.hh:126
typename ratexps_t::const_reverse_iterator const_reverse_iterator
Definition: ratexp.hh:131
An inner node implementing a weight.
Definition: ratexp.hh:208
static constexpr TOP< void > value
Definition: priority.hh:93
Main namespace of Awali.
Definition: ato.hh:22
#define DEFINE(Node)
Definition: ratexp.hxx:68
#define DEFINE_CTOR(Node)
Definition: ratexp.hxx:63
Definition: cont_filter.hh:179