3 #include <vcsn/algos/fwd.hh>
21 template <Automaton 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 auto res =
symbol{
"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 DEFINE(all_out(state_t s), all_in(s));
93 DEFINE(dst_of(transition_t t), src_of(t));
94 DEFINE(is_final(state_t s), is_initial(s));
95 DEFINE(num_finals(), num_initials());
96 DEFINE(num_initials(), num_finals());
97 DEFINE(src_of(transition_t t), dst_of(t));
98 DEFINE(is_initial(state_t s), is_final(s));
100 DEFINE(is_lazy(state_t s), is_lazy_in(s));
101 DEFINE(is_lazy_in(state_t s), is_lazy(s));
103 DEFINE(get_transition(state_t s, state_t d, label_t l),
104 get_transition(d, s, aut_->labelset()->transpose(l)));
105 DEFINE(has_transition(state_t s, state_t d, label_t l),
106 has_transition(d, s, aut_->labelset()->transpose(l)));
107 DEFINE(label_of(transition_t t),
108 labelset()->transpose(aut_->label_of(t)));
111 DEFINE(get_initial_weight(state_t s),
112 weightset()->transpose(aut_->get_final_weight(s)));
115 DEFINE(get_final_weight(state_t s),
116 weightset()->transpose(aut_->get_initial_weight(s)));
119 DEFINE(weight_of(transition_t t),
120 weightset()->transpose(aut_->weight_of(t)));
125 /*-----------------------------------.
126 | non-const methods that transpose. |
127 `-----------------------------------*/
129 #define DEFINE(Signature, Value) \
132 -> decltype(aut_->Value) \
134 return aut_->Value; \
137 DEFINE(set_lazy(state_t s, bool l = true), set_lazy_in(s, l));
138 DEFINE(set_lazy_in(state_t s, bool l = true), set_lazy(s, l));
140 DEFINE(set_initial(state_t s), set_final(s));
141 DEFINE(set_final(state_t s), set_initial(s));
142 DEFINE(unset_initial(state_t s), unset_final(s));
143 DEFINE(unset_final(state_t s), unset_initial(s));
145 DEFINE(set_weight(transition_t t, weight_t k),
146 set_weight(t, aut_->weightset()->transpose(k)));
147 DEFINE(add_weight(transition_t t, weight_t k),
148 add_weight(t, aut_->weightset()->transpose(k)));
149 DEFINE(lmul_weight(transition_t t, weight_t k),
150 lmul_weight(t, aut_->weightset()->transpose(k)));
151 DEFINE(rmul_weight(transition_t t, weight_t k),
152 rmul_weight(t, aut_->weightset()->transpose(k)));
154 DEFINE(del_transition(transition_t t), del_transition(t));
155 DEFINE(del_transition(state_t s, state_t d, label_t l),
156 del_transition(d, s, aut_->labelset()->transpose(l)));
158 DEFINE(add_transition(state_t s, state_t d, label_t l, weight_t k),
160 aut_->labelset()->transpose(l),
161 aut_->weightset()->transpose(k)));
162 DEFINE(add_transition(state_t s, state_t d, label_t l),
163 add_transition(d, s, aut_->labelset()->transpose(l)));
165 DEFINE(new_transition(state_t s, state_t d, label_t l, weight_t k),
167 aut_->labelset()->transpose(l),
168 aut_->weightset()->transpose(k)));
169 DEFINE(new_transition(state_t s, state_t d, label_t l),
171 aut_->labelset()->transpose(l)));
173 DEFINE(set_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(set_initial(state_t s, weight_t k),
178 set_final(s, aut_->weightset()->transpose(k)));
179 DEFINE(set_final(state_t s, weight_t k),
180 set_initial(s, aut_->weightset()->transpose(k)));
181 DEFINE(add_initial(state_t s, weight_t k),
182 add_final(s, aut_->weightset()->transpose(k)));
183 DEFINE(add_final(state_t s, weight_t k),
184 add_initial(s, aut_->weightset()->transpose(k)));
186 template <Automaton A>
187 DEFINE(add_transition_copy(state_t src, state_t dst,
189 typename A::element_type::transition_t t,
190 bool transpose = false),
191 add_transition_copy(dst, src, aut, t, !transpose));
193 template <Automaton A>
194 DEFINE(new_transition_copy(state_t src, state_t dst,
196 typename A::element_type::transition_t t,
197 bool transpose = false),
198 new_transition_copy(dst, src, aut, t, !transpose));
204 /*-----------------------------------.
205 | constexpr methods that transpose. |
206 `-----------------------------------*/
208 #define DEFINE(Signature, Value) \
212 -> decltype(automaton_t::element_type::Value) \
214 return automaton_t::element_type::Value; \
217 DEFINE(post(), pre());
218 DEFINE(pre(), post());
224 template <Automaton Aut>
227 transpose(const transpose_automaton<Aut>& aut)
229 return aut->naked_automaton();
232 template <Automaton Aut>
234 transpose_automaton<Aut>
237 return make_shared_ptr<transpose_automaton<Aut>>(aut);
245 template <Automaton Aut>
247 transpose(automaton& aut)
249 auto& a = aut->as<Aut>();
250 return make_automaton(vcsn::transpose(a));
256 /*------------------------------.
257 | dyn::transpose(expression). |
258 `------------------------------*/
264 template <typename ExpSet>
266 transpose_expression(const expression& exp)
268 const auto& e = exp->as<ExpSet>();
270 return make_expression(e.expressionset(),
271 ::vcsn::transpose(e.expressionset(),
277 /*----------------------------------.
278 | dyn::transposition(expression). |
279 `----------------------------------*/
285 template <typename ExpSet>
287 transposition_expression(const expression& exp)
289 const auto& e = exp->as<ExpSet>();
291 return make_expression(e.expressionset(),
292 e.expressionset().transposition(e.expression()));
std::ostream & print_set(std::ostream &o, format fmt={}) const
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
std::shared_ptr< detail::transpose_automaton_impl< Aut >> transpose_automaton
An automaton wrapper that presents the transposed automaton.
automaton_t aut_
The wrapped automaton, possibly const.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
weight_t_of< automaton_t > weight_t
An input/output format for valuesets.
typename automaton_t::element_type::kind_t kind_t
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aggregate an automaton, and forward calls to it.
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...
context_t_of< automaton_t > context_t
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
weightset_t_of< automaton_t > weightset_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
state_t_of< automaton_t > state_t
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
labelset_t_of< automaton_t > labelset_t
Aut automaton_t
The type of automaton to wrap.
label_t_of< automaton_t > label_t
transition_t_of< automaton_t > transition_t