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-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_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
32  state_t src, state_t dst,
34  -> transition_t
35  {
36  throw std::runtime_error("No epsilon transition");
37  }
38 
39  template<typename Aut>
40  static inline
41  auto
43  state_t src, state_t dst,
45  -> transition_t
46  {
47  throw std::runtime_error("No epsilon transition");
48  }
49 
50  template<typename Aut>
51  static inline
52  auto
54  state_t src, state_t dst,
57  {
58  throw std::runtime_error("No epsilon transition");
59  }
60 
61  template<typename Labelset>
62  static inline
63  typename Labelset::value_t
65  throw std::runtime_error("No epsilon in labelset");
66  }
67 
68  template<typename Labelset>
69  static inline
70  bool
71  is_epsilon(const typename Labelset::value_t& l) {
72  return false;
73  }
74 
75  template<typename Aut>
76  static inline
77  void
79  state_t src, state_t dst)
80  {
81  throw std::runtime_error("No epsilon transition");
82  }
83  };
84 
85 
86  //If epsilon transitions are allowed
87 
88 
89  template<>
90  struct if_has_one<true> {
91 
92  template<typename Aut>
93  static inline
94  auto
96  state_t src, state_t dst,
98  -> transition_t
99  {
100  return a->new_transition(src, dst, a->context().labelset()->one(),w);
101  }
102 
103  template<typename Aut>
104  static inline
105  auto
107  state_t src, state_t dst,
109  -> transition_t
110  {
111  return a->set_transition(src, dst, a->context().labelset()->one(),w);
112  }
113 
114  template<typename Aut>
115  static inline
116  auto
118  state_t src, state_t dst,
121  {
122  return a->add_transition(src, dst, a->context().labelset()->one(),w);
123  }
124 
125  template<typename Aut>
126  static inline
127  void
129  state_t src, state_t dst)
130  {
131  a->del_transition(src, dst, a->context().labelset()->one());
132  }
133 
134  template<typename Labelset>
135  static inline
136  typename Labelset::value_t
138  return Labelset::one();
139  }
140 
141  template<typename Labelset>
142  static inline
143  bool
144  is_epsilon(const typename Labelset::value_t& l) {
145  return Labelset::is_one(l);
146  }
147 
148  };
149  }
150 
164  template <typename Aut>
165  inline
169  }
170 
184  template <typename Aut>
185  inline
189  }
190 
205  template <typename Aut>
206  inline
207  weight_t_of<Aut>
210  }
211 
223  template <typename Aut>
224  inline
225  void
226  del_epsilon_trans(Aut a, state_t src, state_t dst) {
228  }
229 
230  //Without weight
231 
245  template <typename Aut>
247  new_epsilon_trans(const Aut a, state_t src, state_t dst) {
248  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::new_epsilon_trans(a, src, dst, a->context().weightset()->one());
249  }
250 
264  template <typename Aut>
265  inline
266  weight_t_of<Aut>
267  add_epsilon_trans(const Aut a, state_t src, state_t dst) {
268  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::add_epsilon_trans(a, src, dst, a->context().weightset()->one());
269 
270  }
271 
284  template <typename Aut>
285  inline
287  set_epsilon_trans(const Aut a, state_t src, state_t dst) {
288  return internal::if_has_one<labelset_t_of<Aut>::has_one()>::set_epsilon_trans(a, src, dst, a->context().weightset()->one());
289  }
290  /*
291  template <typename Aut>
292  inline
293  label_t_of<Aut>
294  get_epsilon(const Aut a) {
295  return if_has_one<labelset_t_of<Aut>::has_one()>::template get_epsilon<labelset_t_of<Aut>>();
296  }
297  */
298 
305  template <typename Labelset>
306  inline
307  typename Labelset::value_t
309  return internal::if_has_one<Labelset::has_one()>::template get_epsilon<Labelset>();
310  }
311 
319  template <typename Labelset>
320  inline
321  bool
322  is_epsilon(const typename Labelset::value_t& l) {
323  return internal::if_has_one<Labelset::has_one()>::template is_epsilon<Labelset>(l);
324  }
325 
326  }
327 }//end of ns awali::stc
328 
329 #endif
constant< type_t::one, Label, Weight > one
Definition: fwd.hh:116
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
bool is_epsilon(const typename Labelset::value_t &l)
Helper to test if a label is epsilon.
Definition: add_epsilon_trans.hh:322
Labelset::value_t get_epsilon()
Helper to get the value of epsilon.
Definition: add_epsilon_trans.hh:308
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:187
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:167
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:208
void del_epsilon_trans(Aut a, state_t src, state_t dst)
Helper to delete an epsilon transition.
Definition: add_epsilon_trans.hh:226
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:106
static bool is_epsilon(const typename Labelset::value_t &l)
Definition: add_epsilon_trans.hh:144
static void del_epsilon_trans(Aut a, state_t src, state_t dst)
Definition: add_epsilon_trans.hh:128
static Labelset::value_t get_epsilon()
Definition: add_epsilon_trans.hh:137
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:117
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:95
Definition: add_epsilon_trans.hh:26
static Labelset::value_t get_epsilon()
Definition: add_epsilon_trans.hh:64
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:31
static bool is_epsilon(const typename Labelset::value_t &l)
Definition: add_epsilon_trans.hh:71
static void del_epsilon_trans(Aut a, state_t src, state_t dst)
Definition: add_epsilon_trans.hh:78
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:42
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:53