Awali
Another Weighted Automata library
traits.hh
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_LABELSET_TRAITS_HH
18 #define AWALI_LABELSET_TRAITS_HH
19 
26 
27 
28 namespace awali {
29  namespace sttc {
30 
33  template<typename L>
34  struct labelset_trait {
35  using nullable_t = L;
36  using not_nullable_t = L;
37  using letterset_t = L;
38  using wordset_t = L;
39  using ratlabelset_t = L;
40 
41  static const letterset_t& get_letterset(const L& ls) {
42  return ls;
43  }
44 
45  static const wordset_t& get_wordset(const L& ls) {
46  return ls;
47  }
48 
49  static const nullable_t& get_nullableset(const L& ls) {
50  return ls;
51  }
52 
53  static const not_nullable_t& get_not_nullableset(const L& ls) {
54  return ls;
55  }
56 
57  static const ratlabelset_t& get_ratlabelset(const L& ls) {
58  return ls;
59  }
60  };
61 
63  template<typename T>
70 
71  static const letterset_t& get_letterset(const letterset<T>& ls) {
72  return ls;
73  }
74 
75  static wordset_t get_wordset(const letterset<T>& ls) {
76  return {ls.genset()};
77  }
78 
80  return nullable_t(ls);
81  }
82 
83  static const not_nullable_t& get_not_nullableset(const letterset<T>& ls) {
84  return ls;
85  }
86 
87  static const ratlabelset_t& get_ratlabelset(const letterset<T>& ls) {
88  return ls;
89  }
90 
91  };
92 
94  template<typename T>
95  struct labelset_trait<wordset<T>> {
101 
103  return {ls.genset()};
104  }
105 
106  static const wordset_t& get_wordset(const wordset<T>& ls) {
107  return ls;
108  }
109 
110  static const nullable_t& get_nullableset(const wordset<T>& ls) {
111  return ls;
112  }
113 
114  static const not_nullable_t& get_not_nullableset(const wordset<T>& ls) {
115  return ls;
116  }
117 
118  static const ratlabelset_t& get_ratlabelset(const wordset<T>& ls) {
119  return ls;
120  }
121 
122  };
123 
125  template<typename T>
132 
134  auto ls_=*ls.labelset();
135  return labelset_trait<decltype(ls_)>::get_letterset(ls_);
136  }
137 
139  auto ls_=*ls.labelset();
140  return labelset_trait<decltype(ls_)>::get_wordset(ls_);
141  }
142 
144  auto ls_=*ls.labelset();
145  return labelset_trait<decltype(ls_)>::get_nullableset(ls_);
146  }
147 
149  auto ls_=*ls.labelset();
150  return labelset_trait<decltype(ls_)>::get_not_nullableset(ls_);
151  }
152 
154  auto ls_=*ls.labelset();
155  return labelset_trait<decltype(ls_)>::get_ratlabelset(ls_);
156  }
157 
158  };
159 
161  template<typename... Ts>
162  struct labelset_trait<tupleset<Ts...>> {
163  using self_t = tupleset<Ts...>;
165  using nullable_t
167  using wordset_t
170 
171  static nullable_t get_nullableset(const self_t& ls) {
172  return get_nullableset(ls, ls.indices);
173  }
174 
175  template<std::size_t... I>
178  {
179  return nullable_t{(labelset_trait<typename std::tuple_element<I, std::tuple<Ts...>>::type>::get_nullableset(ls.template set<I>()))...};
180  }
181 
182  static wordset_t get_wordset(const self_t& ls) {
183  return get_wordset(ls, ls.indices);
184  }
185 
186  template<std::size_t... I>
187  static wordset_t get_wordset(const self_t& ls,
189  {
190  return nullable_t{(labelset_trait<typename std::tuple_element<I, std::tuple<Ts...>>::type>::get_wordset(ls.template set<I>()))...};
191  }
192 
193  static const ratlabelset_t& get_ratlabelset(const self_t& ls) {
194  return ls;
195  }
196 
197  static not_nullable_t const& get_not_nullableset(const self_t& ls)
198  {
199  return ls;
200  }
201 
202 
203  };
204 
206  template<>
208  using self_t = oneset;
212 
214  return os;
215  }
216  static not_nullable_t const& get_not_nullableset(const self_t& ls)
217  {
218  return ls;
219  }
220 
221  };
222 
223  template<typename L>
224  auto
225  get_letterset(const L& labelset) -> typename labelset_trait<L>::letterset_t
226  {
227  return labelset_trait<L>::get_letterset(labelset);
228  }
229 
230  template<typename L>
231  auto
232  get_wordset(const L& labelset) -> typename labelset_trait<L>::wordset_t
233  {
234  return labelset_trait<L>::get_wordset(labelset);
235  }
236 
237  template<typename L>
238  auto
239  get_ratlabelset(const L& labelset) -> typename labelset_trait<L>::ratlabelset_t
240  {
241  return labelset_trait<L>::get_ratlabelset(labelset);
242  }
243 
244  template<typename L>
245  auto
246  get_nullableset(const L& labelset) -> typename labelset_trait<L>::nullable_t
247  {
248  return labelset_trait<L>::get_nullableset(labelset);
249  }
250 
251  template<typename L>
252  auto
254  {
256  }
257 
258  template<typename LS, typename WS>
259  auto
261  {
262  return {get_letterset(*ctx.labelset()), *ctx.weightset()};
263  }
264 
265  template<typename LS, typename WS>
266  auto
268  {
269  return {get_wordset(*ctx.labelset()), *ctx.weightset()};
270  }
271 
272 
273 
274  template<typename Context>
277  typename Context::weightset_t >;
278 
279 
280  template<typename Context>
282 
283  template<typename Context>
284  using nullable_of =
286  typename Context::weightset_t>;
287 
288  template<typename Context>
291  typename Context::weightset_t>;
292 
293  template<typename Context>
295  get_rat_context(const Context& ctx)
296  {
297  return {get_ratlabelset(*ctx.labelset()), *ctx.weightset()};
298  }
299 
300  template<typename Context>
301  auto
303  {
304  return {get_nullableset(*ctx.labelset()), *ctx.weightset()};
305  }
306 
307  template<typename Context>
308  auto
310  {
311  return {get_not_nullableset(*ctx.labelset()), *ctx.weightset()};
312  }
313 
314  }
315 }//end of ns awali::stc
316 
317 #endif
carries the algebraic settings of automata
Definition: context.hh:40
Implementation of labels are letters.
Definition: letterset.hh:43
const genset_t & genset() const
Definition: letterset.hh:72
Implementation of labels are nullables (letter or empty).
Definition: nullableset.hh:189
const labelset_ptr labelset() const
Definition: nullableset.hh:281
Implementation of labels are ones: there is a single instance of label.
Definition: oneset.hh:38
A ValueSet which is a Cartesian product of ValueSets.
Definition: tupleset.hh:80
static constexpr indices_t indices
Definition: tupleset.hh:84
Implementation of labels are words.
Definition: wordset.hh:35
const genset_t & genset() const
Definition: wordset.hh:56
labelset_description oneset()
Definition: tuple.hh:43
auto get_wordset_context(const context< LS, WS > &ctx) -> context< typename labelset_trait< LS >::wordset_t, WS >
Definition: traits.hh:267
auto get_not_nullable_context(const Context &ctx) -> not_nullable_of< Context >
Definition: traits.hh:309
auto get_nullableset(const L &labelset) -> typename labelset_trait< L >::nullable_t
Definition: traits.hh:246
auto get_letterset(const L &labelset) -> typename labelset_trait< L >::letterset_t
Definition: traits.hh:225
auto get_wordset(const L &labelset) -> typename labelset_trait< L >::wordset_t
Definition: traits.hh:232
auto get_ratlabelset(const L &labelset) -> typename labelset_trait< L >::ratlabelset_t
Definition: traits.hh:239
auto get_not_nullableset(const L &labelset) -> typename labelset_trait< L >::not_nullable_t
Definition: traits.hh:253
auto get_nullable_context(const Context &ctx) -> nullable_of< Context >
Definition: traits.hh:302
ratexp_context_of< Context > get_rat_context(const Context &ctx)
Definition: traits.hh:295
auto get_letterset_context(const context< LS, WS > &ctx) -> context< typename labelset_trait< LS >::letterset_t, WS >
Definition: traits.hh:260
Main namespace of Awali.
Definition: ato.hh:22
static nullable_t get_nullableset(const letterset< T > &ls)
Definition: traits.hh:79
static wordset_t get_wordset(const letterset< T > &ls)
Definition: traits.hh:75
static const letterset_t & get_letterset(const letterset< T > &ls)
Definition: traits.hh:71
static const not_nullable_t & get_not_nullableset(const letterset< T > &ls)
Definition: traits.hh:83
static const ratlabelset_t & get_ratlabelset(const letterset< T > &ls)
Definition: traits.hh:87
static ratlabelset_t get_ratlabelset(const nullableset< T > &ls)
Definition: traits.hh:153
typename labelset_trait< T >::nullable_t nullable_t
Definition: traits.hh:127
static nullable_t get_nullableset(const nullableset< T > &ls)
Definition: traits.hh:143
typename labelset_trait< T >::not_nullable_t not_nullable_t
Definition: traits.hh:128
static wordset_t get_wordset(const nullableset< T > &ls)
Definition: traits.hh:138
typename labelset_trait< T >::ratlabelset_t ratlabelset_t
Definition: traits.hh:131
static letterset_t get_letterset(const nullableset< T > &ls)
Definition: traits.hh:133
typename labelset_trait< T >::letterset_t letterset_t
Definition: traits.hh:129
typename labelset_trait< T >::wordset_t wordset_t
Definition: traits.hh:130
static not_nullable_t get_not_nullableset(const nullableset< T > &ls)
Definition: traits.hh:148
static not_nullable_t const & get_not_nullableset(const self_t &ls)
Definition: traits.hh:216
static ratlabelset_t get_ratlabelset(const oneset &os)
Definition: traits.hh:213
static nullable_t get_nullableset(const self_t &ls)
Definition: traits.hh:171
static wordset_t get_wordset(const self_t &ls, awali::internal::index_sequence< I... >)
Definition: traits.hh:187
static wordset_t get_wordset(const self_t &ls)
Definition: traits.hh:182
static const ratlabelset_t & get_ratlabelset(const self_t &ls)
Definition: traits.hh:193
static nullable_t get_nullableset(const self_t &ls, awali::internal::index_sequence< I... >)
Definition: traits.hh:176
static not_nullable_t const & get_not_nullableset(const self_t &ls)
Definition: traits.hh:197
static letterset_t get_letterset(const wordset< T > &ls)
Definition: traits.hh:102
static const nullable_t & get_nullableset(const wordset< T > &ls)
Definition: traits.hh:110
static const ratlabelset_t & get_ratlabelset(const wordset< T > &ls)
Definition: traits.hh:118
static const wordset_t & get_wordset(const wordset< T > &ls)
Definition: traits.hh:106
static const not_nullable_t & get_not_nullableset(const wordset< T > &ls)
Definition: traits.hh:114
trait that computes the related types of a labelset
Definition: traits.hh:34
L ratlabelset_t
Definition: traits.hh:39
static const wordset_t & get_wordset(const L &ls)
Definition: traits.hh:45
L not_nullable_t
Definition: traits.hh:36
static const nullable_t & get_nullableset(const L &ls)
Definition: traits.hh:49
static const not_nullable_t & get_not_nullableset(const L &ls)
Definition: traits.hh:53
L nullable_t
Definition: traits.hh:35
static const letterset_t & get_letterset(const L &ls)
Definition: traits.hh:41
L wordset_t
Definition: traits.hh:38
L letterset_t
Definition: traits.hh:37
static const ratlabelset_t & get_ratlabelset(const L &ls)
Definition: traits.hh:57
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38