3 #include <vcsn/algos/fwd.hh>
21 template <
typename Aut>
22 class transpose_automaton_impl
23 :
public automaton_decorator<Aut>
35 template <
typename Ctx = context_t>
46 using kind_t =
typename automaton_t::element_type::kind_t;
48 using super_t::super_t;
53 static symbol res(
"transpose_automaton<"
60 o <<
"transpose_automaton<";
61 aut_->print_set(o, fmt);
74 -> decltype(transpose(vcsn::strip(this->naked_automaton())))
76 return transpose(vcsn::strip(this->naked_automaton()));
80 /*-------------------------------.
81 | const methods that transpose. |
82 `-------------------------------*/
83 #define DEFINE(Signature, Value) \
86 -> decltype(aut_->Value) \
91 DEFINE(all_in(state_t s), all_out(s));
92 template <typename Pred>
93 DEFINE(all_in(state_t s, Pred pred), all_out(s, pred));
94 DEFINE(all_out(state_t s), all_in(s));
95 template <typename Pred>
96 DEFINE(all_out(state_t s, Pred pred), all_in(s, pred));
98 DEFINE(dst_of(transition_t t), src_of(t));
99 DEFINE(final_transitions(), initial_transitions());
100 DEFINE(in(state_t s), out(s));
101 DEFINE(initial_transitions(), final_transitions());
102 DEFINE(is_final(state_t s), is_initial(s));
103 DEFINE(num_finals(), num_initials());
104 DEFINE(num_initials(), num_finals());
105 DEFINE(out(state_t s), in(s));
106 DEFINE(outin(state_t s, state_t d), outin(d, s));
107 DEFINE(src_of(transition_t t), dst_of(t));
108 DEFINE(is_initial(state_t s), is_final(s));
110 DEFINE(in(state_t s, label_t l),
111 out(s, aut_->labelset()->transpose(l)));
112 DEFINE(out(state_t s, label_t l),
113 in(s, aut_->labelset()->transpose(l)));
114 DEFINE(get_transition(state_t s, state_t d, label_t l),
115 get_transition(d, s, aut_->labelset()->transpose(l)));
116 DEFINE(has_transition(state_t s, state_t d, label_t l),
117 has_transition(d, s, aut_->labelset()->transpose(l)));
118 DEFINE(label_of(transition_t t),
119 labelset()->transpose(aut_->label_of(t)));
122 DEFINE(get_initial_weight(state_t s),
123 weightset()->transpose(aut_->get_final_weight(s)));
126 DEFINE(get_final_weight(state_t s),
127 weightset()->transpose(aut_->get_initial_weight(s)));
130 DEFINE(weight_of(transition_t t),
131 weightset()->transpose(aut_->weight_of(t)));
136 /*-----------------------------------.
137 | non-const methods that transpose. |
138 `-----------------------------------*/
140 #define DEFINE(Signature, Value) \
143 -> decltype(aut_->Value) \
145 return aut_->Value; \
148 DEFINE(set_initial(state_t s), set_final(s));
149 DEFINE(set_final(state_t s), set_initial(s));
150 DEFINE(unset_initial(state_t s), unset_final(s));
151 DEFINE(unset_final(state_t s), unset_initial(s));
153 DEFINE(set_weight(transition_t t, weight_t k),
154 set_weight(t, aut_->weightset()->transpose(k)));
155 DEFINE(add_weight(transition_t t, weight_t k),
156 add_weight(t, aut_->weightset()->transpose(k)));
157 DEFINE(lmul_weight(transition_t t, weight_t k),
158 lmul_weight(t, aut_->weightset()->transpose(k)));
159 DEFINE(rmul_weight(transition_t t, weight_t k),
160 rmul_weight(t, aut_->weightset()->transpose(k)));
162 DEFINE(del_transition(transition_t t), del_transition(t));
163 DEFINE(del_transition(state_t s, state_t d, label_t l),
164 del_transition(d, s, aut_->labelset()->transpose(l)));
166 DEFINE(add_transition(state_t s, state_t d, label_t l, weight_t k),
168 aut_->labelset()->transpose(l),
169 aut_->weightset()->transpose(k)));
170 DEFINE(add_transition(state_t s, state_t d, label_t l),
171 add_transition(d, s, aut_->labelset()->transpose(l)));
173 DEFINE(new_transition(state_t s, state_t d, label_t l, weight_t k),
175 aut_->labelset()->transpose(l),
176 aut_->weightset()->transpose(k)));
177 DEFINE(new_transition(state_t s, state_t d, label_t l),
179 aut_->labelset()->transpose(l)));
181 DEFINE(set_transition(state_t s, state_t d, label_t l, weight_t k),
183 aut_->labelset()->transpose(l),
184 aut_->weightset()->transpose(k)));
185 DEFINE(set_initial(state_t s, weight_t k),
186 set_final(s, aut_->weightset()->transpose(k)));
187 DEFINE(set_final(state_t s, weight_t k),
188 set_initial(s, aut_->weightset()->transpose(k)));
189 DEFINE(add_initial(state_t s, weight_t k),
190 add_final(s, aut_->weightset()->transpose(k)));
191 DEFINE(add_final(state_t s, weight_t k),
192 add_initial(s, aut_->weightset()->transpose(k)));
194 template <typename A>
195 DEFINE(add_transition_copy(state_t src, state_t dst,
197 typename A::element_type::transition_t t,
198 bool transpose = false),
199 add_transition_copy(dst, src, aut, t, !transpose));
201 template <typename A>
202 DEFINE(new_transition_copy(state_t src, state_t dst,
204 typename A::element_type::transition_t t,
205 bool transpose = false),
206 new_transition_copy(dst, src, aut, t, !transpose));
212 /*-----------------------------------.
213 | constexpr methods that transpose. |
214 `-----------------------------------*/
216 #define DEFINE(Signature, Value) \
220 -> decltype(automaton_t::element_type::Value) \
222 return automaton_t::element_type::Value; \
225 DEFINE(post(), pre());
226 DEFINE(pre(), post());
232 template <typename Aut>
235 transpose(const transpose_automaton<Aut>& aut)
237 return aut->naked_automaton();
240 template <typename Aut>
242 transpose_automaton<Aut>
245 return make_shared_ptr<transpose_automaton<Aut>>(aut);
253 template <typename Aut>
255 transpose(automaton& aut)
257 auto& a = aut->as<Aut>();
258 return make_automaton(vcsn::transpose(a));
264 /*------------------------------.
265 | dyn::transpose(expression). |
266 `------------------------------*/
272 template <typename ExpSet>
274 transpose_expression(const expression& exp)
276 const auto& e = exp->as<ExpSet>();
278 return make_expression(e.expressionset(),
279 ::vcsn::transpose(e.expressionset(),
285 /*----------------------------------.
286 | dyn::transposition(expression). |
287 `----------------------------------*/
293 template <typename ExpSet>
295 transposition_expression(const expression& exp)
297 const auto& e = exp->as<ExpSet>();
299 return make_expression(e.expressionset(),
300 e.expressionset().transposition(e.expression()));
typename automaton_t::element_type::kind_t kind_t
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
transition_t_of< automaton_t > transition_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Aggregate an automaton, and forward calls to it.
std::ostream & print_set(std::ostream &o, format fmt={}) const
weightset_t_of< automaton_t > weightset_t
std::shared_ptr< detail::transpose_automaton_impl< Aut >> transpose_automaton
An automaton wrapper that presents the transposed automaton.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
context_t_of< automaton_t > context_t
state_t_of< automaton_t > state_t
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
weight_t_of< automaton_t > weight_t
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aut automaton_t
The type of automaton to wrap.
transpose_automaton< fresh_automaton_t_of< automaton_t, Ctx >> fresh_automaton_t
The type to use to build an automaton of the same type: remove the inner const-volatile qualifiers...
labelset_t_of< automaton_t > labelset_t
label_t_of< automaton_t > label_t
automaton_t aut_
The wrapped automaton, possibly const.
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of