Awali
Another Weighted Automata library
add_epsilon_trans.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_MISC_ADD_EPSILON_TRANS_HH
18 #define AWALI_MISC_ADD_EPSILON_TRANS_HH
19 
20 namespace awali {
21  namespace sttc {
22  namespace internal {
23  //If epsilon transitions are not allowed
24 
25  template<bool HAS_ONE>
26  struct if_has_one {
27 
28  template<typename Aut>
29  static inline
30  auto
34  -> transition_t
35  {
36  throw std::runtime_error("No epsilon transition");
37  }
38 
39  template<typename Aut>
40  static inline
41  auto
44  -> transition_t
45  {
46  throw std::runtime_error("No epsilon transition");
47  }
48 
49  template<typename Aut>
50  static inline
51  auto
56  {
57  throw std::runtime_error("No epsilon transition");
58  }
59 
60  template<typename Labelset>
61  static inline
62  typename Labelset::value_t
64  throw std::runtime_error("No epsilon in labelset");
65  }
66 
67  template<typename Labelset>
68  static inline
69  bool
70  is_epsilon(const typename Labelset::value_t&) {
71  return false;
72  }
73 
74  template<typename Aut>
75  static inline
76  void
78  {
79  throw std::runtime_error("No epsilon transition");
80  }
81  };
82 
83 
84  //If epsilon transitions are allowed
85 
86 
87  template<>
88  struct if_has_one<true> {
89 
90  template<typename Aut>
91  static inline
92  auto
94  state_t src, state_t dst,
96  -> transition_t
97  {
98  return a->new_transition(src, dst, a->context().labelset()->one(),w);
99  }
100 
101  template<typename Aut>
102  static inline
103  auto
105  state_t src, state_t dst,
107  -> transition_t
108  {
109  return a->set_transition(src, dst, a->context().labelset()->one(),w);
110  }
111 
112  template<typename Aut>
113  static inline
114  auto
116  state_t src, state_t dst,
119  {
120  return a->add_transition(src, dst, a->context().labelset()->one(),w);
121  }
122 
123  template<typename Aut>
124  static inline
125  void
127  state_t src, state_t dst)
128  {
129  a->del_transition(src, dst, a->context().labelset()->one());
130  }
131 
132  template<typename Labelset>
133  static inline
134  typename Labelset::value_t
136  return Labelset::one();
137  }
138 
139  template<typename Labelset>
140  static inline
141  bool
142  is_epsilon(const typename Labelset::value_t& l) {
143  return Labelset::is_one(l);
144  }
145 
146  };
147  }
148 
162  template <typename Aut>
163  inline
167  }
168 
182  template <typename Aut>
183  inline
187  }
188 
203  template <typename Aut>
204  inline
205  weight_t_of<Aut>
208  }
209 
221  template <typename Aut>
222  inline
223  void
224  del_epsilon_trans(Aut a, state_t src, state_t dst) {
226  }
227 
228  //Without weight
229 
243  template <typename Aut>
245  new_epsilon_trans(const Aut a, state_t src, state_t dst) {
246  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::new_epsilon_trans(a, src, dst, a->context().weightset()->one());
247  }
248 
262  template <typename Aut>
263  inline
264  weight_t_of<Aut>
265  add_epsilon_trans(const Aut a, state_t src, state_t dst) {
266  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::add_epsilon_trans(a, src, dst, a->context().weightset()->one());
267 
268  }
269 
282  template <typename Aut>
283  inline
285  set_epsilon_trans(const Aut a, state_t src, state_t dst) {
286  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::set_epsilon_trans(a, src, dst, a->context().weightset()->one());
287  }
288  /*
289  template <typename Aut>
290  inline
291  label_t_of<Aut>
292  get_epsilon(const Aut a) {
293  return if_has_one<labelset_t_of<Aut>::has_one()>::template get_epsilon<labelset_t_of<Aut>>();
294  }
295  */
296 
303  template <typename Labelset>
304  inline
305  typename Labelset::value_t
306  get_epsilon() {
307  return internal::if_has_one<Labelset::has_one()>::template get_epsilon<Labelset>();
308  }
309 
317  template <typename Labelset>
318  inline
319  bool
320  is_epsilon(const typename Labelset::value_t& l) {
321  return internal::if_has_one<Labelset::has_one()>::template is_epsilon<Labelset>(l);
322  }
323 
324  }
325 }//end of ns awali::stc
326 
327 #endif
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
ctx::lan_char::value_t get_epsilon()
Helper to get the value of epsilon.
Definition: automaton.hh:74
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
transition_t set_epsilon_trans(Aut a, state_t src, state_t dst, weight_t_of< Aut > w)
Helper to set an epsilon transition.
Definition: add_epsilon_trans.hh:185
bool is_epsilon(ctx::lan_char::value_t v)
Definition: automaton.hh:78
transition_t new_epsilon_trans(Aut a, state_t src, state_t dst, weight_t_of< Aut > w)
Helper to create a new epsilon transition.
Definition: add_epsilon_trans.hh:165
weight_t_of< Aut > add_epsilon_trans(Aut a, state_t src, state_t dst, weight_t_of< Aut > w)
Helper to add an epsilon transition.
Definition: add_epsilon_trans.hh:206
void del_epsilon_trans(Aut a, state_t src, state_t dst)
Helper to delete an epsilon transition.
Definition: add_epsilon_trans.hh:224
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
unsigned transition_t
Definition: types.hh:22
static auto set_epsilon_trans(Aut a, state_t src, state_t dst, ::awali::sttc::weight_t_of< Aut > w) -> transition_t
Definition: add_epsilon_trans.hh:104
static bool is_epsilon(const typename Labelset::value_t &l)
Definition: add_epsilon_trans.hh:142
static void del_epsilon_trans(Aut a, state_t src, state_t dst)
Definition: add_epsilon_trans.hh:126
static Labelset::value_t get_epsilon()
Definition: add_epsilon_trans.hh:135
static auto add_epsilon_trans(Aut a, state_t src, state_t dst, ::awali::sttc::weight_t_of< Aut > w) -> ::awali::sttc::weight_t_of< Aut >
Definition: add_epsilon_trans.hh:115
static auto new_epsilon_trans(Aut a, state_t src, state_t dst, ::awali::sttc::weight_t_of< Aut > w) -> transition_t
Definition: add_epsilon_trans.hh:93
Definition: add_epsilon_trans.hh:26
static Labelset::value_t get_epsilon()
Definition: add_epsilon_trans.hh:63
static auto new_epsilon_trans(Aut, state_t, state_t, ::awali::sttc::weight_t_of< Aut >) -> transition_t
Definition: add_epsilon_trans.hh:31
static void del_epsilon_trans(Aut, state_t, state_t)
Definition: add_epsilon_trans.hh:77
static auto set_epsilon_trans(Aut, state_t, state_t, ::awali::sttc::weight_t_of< Aut >) -> transition_t
Definition: add_epsilon_trans.hh:42
static auto add_epsilon_trans(Aut, state_t, state_t, ::awali::sttc::weight_t_of< Aut >) -> ::awali::sttc::weight_t_of< Aut >
Definition: add_epsilon_trans.hh:52
static bool is_epsilon(const typename Labelset::value_t &)
Definition: add_epsilon_trans.hh:70