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 
25 
26 
27 namespace awali {
28  namespace sttc {
29 
32  template<typename L>
33  struct labelset_trait {
34  using nullable_t = L;
35  using not_nullable_t = L;
36  using letterset_t = L;
37  using wordset_t = L;
38  using ratlabelset_t = L;
39 
40  static const letterset_t& get_letterset(const L& ls) {
41  return ls;
42  }
43 
44  static const wordset_t& get_wordset(const L& ls) {
45  return ls;
46  }
47 
48  static const nullable_t& get_nullableset(const L& ls) {
49  return ls;
50  }
51 
52  static const not_nullable_t& get_not_nullableset(const L& ls) {
53  return ls;
54  }
55 
56  static const ratlabelset_t& get_ratlabelset(const L& ls) {
57  return ls;
58  }
59  };
60 
62  template<typename T>
69 
70  static const letterset_t& get_letterset(const letterset<T>& ls) {
71  return ls;
72  }
73 
74  static wordset_t get_wordset(const letterset<T>& ls) {
75  return {ls.genset()};
76  }
77 
79  return nullable_t(ls);
80  }
81 
82  static const not_nullable_t& get_not_nullableset(const letterset<T>& ls) {
83  return ls;
84  }
85 
86  static const ratlabelset_t& get_ratlabelset(const letterset<T>& ls) {
87  return ls;
88  }
89 
90  };
91 
93  template<typename T>
94  struct labelset_trait<wordset<T>> {
100 
102  return {ls.genset()};
103  }
104 
105  static const wordset_t& get_wordset(const wordset<T>& ls) {
106  return ls;
107  }
108 
109  static const nullable_t& get_nullableset(const wordset<T>& ls) {
110  return ls;
111  }
112 
113  static const not_nullable_t& get_not_nullableset(const wordset<T>& ls) {
114  return ls;
115  }
116 
117  static const ratlabelset_t& get_ratlabelset(const wordset<T>& ls) {
118  return ls;
119  }
120 
121  };
122 
124  template<typename T>
131 
133  auto ls_=*ls.labelset();
134  return labelset_trait<decltype(ls_)>::get_letterset(ls_);
135  }
136 
138  auto ls_=*ls.labelset();
139  return labelset_trait<decltype(ls_)>::get_wordset(ls_);
140  }
141 
143  auto ls_=*ls.labelset();
144  return labelset_trait<decltype(ls_)>::get_nullableset(ls_);
145  }
146 
148  auto ls_=*ls.labelset();
149  return labelset_trait<decltype(ls_)>::get_not_nullableset(ls_);
150  }
151 
153  auto ls_=*ls.labelset();
154  return labelset_trait<decltype(ls_)>::get_ratlabelset(ls_);
155  }
156 
157  };
158 
160  template<>
164  /*
165  static ratlabelset_t get_ratlabelset(const oneset& os) {
166  return os;
167  }
168  */
169  };
170 
171 
172  template<typename L>
173  auto
174  get_letterset(const L& labelset) -> typename labelset_trait<L>::letterset_t
175  {
176  return labelset_trait<L>::get_letterset(labelset);
177  }
178 
179  template<typename L>
180  auto
181  get_wordset(const L& labelset) -> typename labelset_trait<L>::wordset_t
182  {
183  return labelset_trait<L>::get_wordset(labelset);
184  }
185 
186  template<typename L>
187  auto
188  get_ratlabelset(const L& labelset) -> typename labelset_trait<L>::ratlabelset_t
189  {
190  return labelset_trait<L>::get_ratlabelset(labelset);
191  }
192 
193  template<typename L>
194  auto
195  get_nullableset(const L& labelset) -> typename labelset_trait<L>::nullable_t
196  {
197  return labelset_trait<L>::get_nullableset(labelset);
198  }
199 
200  template<typename L>
201  auto
203  {
205  }
206 
207  template<typename LS, typename WS>
208  auto
210  {
211  return {get_letterset(*ctx.labelset()), *ctx.weightset()};
212  }
213 
214  template<typename LS, typename WS>
215  auto
217  {
218  return {get_wordset(*ctx.labelset()), *ctx.weightset()};
219  }
220 
221  template<typename Context>
224  typename Context::weightset_t>>;
225 
226  template<typename Context>
227  using nullable_of =
229  typename Context::weightset_t>;
230 
231  template<typename Context>
234  typename Context::weightset_t>;
235 
236  template<typename Context>
237  auto
238  get_rat_context(const Context& ctx) ->
240  typename Context::weightset_t>
241  {
242  return {get_ratlabelset(*ctx.labelset()), *ctx.weightset()};
243  }
244 
245  template<typename Context>
246  auto
248  {
249  return {get_nullableset(*ctx.labelset()), *ctx.weightset()};
250  }
251 
252  template<typename Context>
253  auto
255  {
256  return {get_not_nullableset(*ctx.labelset()), *ctx.weightset()};
257  }
258 
259  }
260 }//end of ns awali::stc
261 
262 #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
Implementation of labels are words.
Definition: wordset.hh:35
const genset_t & genset() const
Definition: wordset.hh:56
labelset_description oneset()
auto get_wordset_context(const context< LS, WS > &ctx) -> context< typename labelset_trait< LS >::wordset_t, WS >
Definition: traits.hh:216
auto get_rat_context(const Context &ctx) -> context< typename labelset_trait< typename Context::labelset_t >::ratlabelset_t, typename Context::weightset_t >
Definition: traits.hh:238
auto get_not_nullable_context(const Context &ctx) -> not_nullable_of< Context >
Definition: traits.hh:254
auto get_nullableset(const L &labelset) -> typename labelset_trait< L >::nullable_t
Definition: traits.hh:195
auto get_letterset(const L &labelset) -> typename labelset_trait< L >::letterset_t
Definition: traits.hh:174
auto get_wordset(const L &labelset) -> typename labelset_trait< L >::wordset_t
Definition: traits.hh:181
auto get_ratlabelset(const L &labelset) -> typename labelset_trait< L >::ratlabelset_t
Definition: traits.hh:188
auto get_not_nullableset(const L &labelset) -> typename labelset_trait< L >::not_nullable_t
Definition: traits.hh:202
auto get_nullable_context(const Context &ctx) -> nullable_of< Context >
Definition: traits.hh:247
auto get_letterset_context(const context< LS, WS > &ctx) -> context< typename labelset_trait< LS >::letterset_t, WS >
Definition: traits.hh:209
Main namespace of Awali.
Definition: ato.hh:22
static nullable_t get_nullableset(const letterset< T > &ls)
Definition: traits.hh:78
static wordset_t get_wordset(const letterset< T > &ls)
Definition: traits.hh:74
static const letterset_t & get_letterset(const letterset< T > &ls)
Definition: traits.hh:70
static const not_nullable_t & get_not_nullableset(const letterset< T > &ls)
Definition: traits.hh:82
static const ratlabelset_t & get_ratlabelset(const letterset< T > &ls)
Definition: traits.hh:86
static ratlabelset_t get_ratlabelset(const nullableset< T > &ls)
Definition: traits.hh:152
typename labelset_trait< T >::nullable_t nullable_t
Definition: traits.hh:126
static nullable_t get_nullableset(const nullableset< T > &ls)
Definition: traits.hh:142
typename labelset_trait< T >::not_nullable_t not_nullable_t
Definition: traits.hh:127
static wordset_t get_wordset(const nullableset< T > &ls)
Definition: traits.hh:137
typename labelset_trait< T >::ratlabelset_t ratlabelset_t
Definition: traits.hh:130
static letterset_t get_letterset(const nullableset< T > &ls)
Definition: traits.hh:132
typename labelset_trait< T >::letterset_t letterset_t
Definition: traits.hh:128
typename labelset_trait< T >::wordset_t wordset_t
Definition: traits.hh:129
static not_nullable_t get_not_nullableset(const nullableset< T > &ls)
Definition: traits.hh:147
static letterset_t get_letterset(const wordset< T > &ls)
Definition: traits.hh:101
static const nullable_t & get_nullableset(const wordset< T > &ls)
Definition: traits.hh:109
static const ratlabelset_t & get_ratlabelset(const wordset< T > &ls)
Definition: traits.hh:117
static const wordset_t & get_wordset(const wordset< T > &ls)
Definition: traits.hh:105
static const not_nullable_t & get_not_nullableset(const wordset< T > &ls)
Definition: traits.hh:113
trait that computes the related types of a labelset
Definition: traits.hh:33
L ratlabelset_t
Definition: traits.hh:38
static const wordset_t & get_wordset(const L &ls)
Definition: traits.hh:44
L not_nullable_t
Definition: traits.hh:35
static const nullable_t & get_nullableset(const L &ls)
Definition: traits.hh:48
static const not_nullable_t & get_not_nullableset(const L &ls)
Definition: traits.hh:52
L nullable_t
Definition: traits.hh:34
static const letterset_t & get_letterset(const L &ls)
Definition: traits.hh:40
L wordset_t
Definition: traits.hh:37
L letterset_t
Definition: traits.hh:36
static const ratlabelset_t & get_ratlabelset(const L &ls)
Definition: traits.hh:56
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38