Awali
Another Weighted Automata library
traits.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2021 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>
176  static nullable_t const& get_nullableset(const self_t& ls,
178  {
179  return nullable_t{ls.template set<I>()...};
180  }
181 
182  static nullable_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 const& get_wordset(const self_t& ls,
189  {
190  return wordset_t{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<>
210 
212  return os;
213  }
214 
215  };
216 
217  template<typename L>
218  auto
219  get_letterset(const L& labelset) -> typename labelset_trait<L>::letterset_t
220  {
221  return labelset_trait<L>::get_letterset(labelset);
222  }
223 
224  template<typename L>
225  auto
226  get_wordset(const L& labelset) -> typename labelset_trait<L>::wordset_t
227  {
228  return labelset_trait<L>::get_wordset(labelset);
229  }
230 
231  template<typename L>
232  auto
233  get_ratlabelset(const L& labelset) -> typename labelset_trait<L>::ratlabelset_t
234  {
235  return labelset_trait<L>::get_ratlabelset(labelset);
236  }
237 
238  template<typename L>
239  auto
240  get_nullableset(const L& labelset) -> typename labelset_trait<L>::nullable_t
241  {
242  return labelset_trait<L>::get_nullableset(labelset);
243  }
244 
245  template<typename L>
246  auto
248  {
250  }
251 
252  template<typename LS, typename WS>
253  auto
255  {
256  return {get_letterset(*ctx.labelset()), *ctx.weightset()};
257  }
258 
259  template<typename LS, typename WS>
260  auto
262  {
263  return {get_wordset(*ctx.labelset()), *ctx.weightset()};
264  }
265 
266  template<typename Context>
269  typename Context::weightset_t>>;
270 
271  template<typename Context>
272  using nullable_of =
274  typename Context::weightset_t>;
275 
276  template<typename Context>
279  typename Context::weightset_t>;
280 
281  template<typename Context>
282  auto
283  get_rat_context(const Context& ctx) ->
285  typename Context::weightset_t>
286  {
287  return {get_ratlabelset(*ctx.labelset()), *ctx.weightset()};
288  }
289 
290  template<typename Context>
291  auto
293  {
294  return {get_nullableset(*ctx.labelset()), *ctx.weightset()};
295  }
296 
297  template<typename Context>
298  auto
300  {
301  return {get_not_nullableset(*ctx.labelset()), *ctx.weightset()};
302  }
303 
304  }
305 }//end of ns awali::stc
306 
307 #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:261
auto get_rat_context(const Context &ctx) -> context< typename labelset_trait< typename Context::labelset_t >::ratlabelset_t, typename Context::weightset_t >
Definition: traits.hh:283
auto get_not_nullable_context(const Context &ctx) -> not_nullable_of< Context >
Definition: traits.hh:299
auto get_nullableset(const L &labelset) -> typename labelset_trait< L >::nullable_t
Definition: traits.hh:240
auto get_letterset(const L &labelset) -> typename labelset_trait< L >::letterset_t
Definition: traits.hh:219
auto get_wordset(const L &labelset) -> typename labelset_trait< L >::wordset_t
Definition: traits.hh:226
auto get_ratlabelset(const L &labelset) -> typename labelset_trait< L >::ratlabelset_t
Definition: traits.hh:233
auto get_not_nullableset(const L &labelset) -> typename labelset_trait< L >::not_nullable_t
Definition: traits.hh:247
auto get_nullable_context(const Context &ctx) -> nullable_of< Context >
Definition: traits.hh:292
auto get_letterset_context(const context< LS, WS > &ctx) -> context< typename labelset_trait< LS >::letterset_t, WS >
Definition: traits.hh:254
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 ratlabelset_t get_ratlabelset(const oneset &os)
Definition: traits.hh:211
static wordset_t const & get_wordset(const self_t &ls, awali::internal::index_sequence< I... >)
Definition: traits.hh:187
static nullable_t get_nullableset(const self_t &ls)
Definition: traits.hh:171
static nullable_t const & get_nullableset(const self_t &ls, awali::internal::index_sequence< I... >)
Definition: traits.hh:176
static nullable_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 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