4 #include <vcsn/algos/fwd.hh>
22 template <Automaton Aut>
23 class transpose_automaton_impl
24 :
public automaton_decorator<Aut>
37 template <
typename Ctx = context_t>
48 using kind_t =
typename automaton_t::element_type::kind_t;
50 using super_t::super_t;
55 static auto res =
symbol{
"transpose_automaton<"
62 o <<
"transpose_automaton<";
63 aut_->print_set(o, fmt);
78 -> decltype(transpose(vcsn::strip(this->naked_automaton())))
80 return transpose(vcsn::strip(this->naked_automaton()));
85 auto automaton() const
87 return copy<const transpose_automaton_impl*, automaton_t>(this);
90 /*-------------------------------.
91 | const methods that transpose. |
92 `-------------------------------*/
93 #define DEFINE(Signature, Value) \
96 -> decltype(aut_->Value) \
101 DEFINE(all_in(state_t s), all_out(s));
102 DEFINE(all_out(state_t s), all_in(s));
103 DEFINE(dst_of(transition_t t), src_of(t));
104 DEFINE(is_final(state_t s), is_initial(s));
105 DEFINE(num_finals(), num_initials());
106 DEFINE(num_initials(), num_finals());
107 DEFINE(src_of(transition_t t), dst_of(t));
108 DEFINE(is_initial(state_t s), is_final(s));
110 DEFINE(is_lazy(state_t s), is_lazy_in(s));
111 DEFINE(is_lazy_in(state_t s), is_lazy(s));
113 DEFINE(get_transition(state_t s, state_t d, label_t l),
114 get_transition(d, s, aut_->labelset()->transpose(l)));
115 DEFINE(has_transition(transition_t t),
117 DEFINE(has_transition(state_t s, state_t d, label_t l),
118 has_transition(d, s, aut_->labelset()->transpose(l)));
119 DEFINE(label_of(transition_t t),
120 labelset()->transpose(aut_->label_of(t)));
123 DEFINE(get_initial_weight(state_t s),
124 weightset()->transpose(aut_->get_final_weight(s)));
127 DEFINE(get_final_weight(state_t s),
128 weightset()->transpose(aut_->get_initial_weight(s)));
131 DEFINE(weight_of(transition_t t),
132 weightset()->transpose(aut_->weight_of(t)));
137 /*-----------------------------------.
138 | non-const methods that transpose. |
139 `-----------------------------------*/
141 #define DEFINE(Signature, Value) \
144 -> decltype(aut_->Value) \
146 return aut_->Value; \
149 DEFINE(set_lazy(state_t s, bool l = true), set_lazy_in(s, l));
150 DEFINE(set_lazy_in(state_t s, bool l = true), set_lazy(s, l));
152 DEFINE(set_initial(state_t s), set_final(s));
153 DEFINE(set_final(state_t s), set_initial(s));
154 DEFINE(unset_initial(state_t s), unset_final(s));
155 DEFINE(unset_final(state_t s), unset_initial(s));
157 DEFINE(set_weight(transition_t t, weight_t k),
158 set_weight(t, aut_->weightset()->transpose(k)));
159 DEFINE(add_weight(transition_t t, weight_t k),
160 add_weight(t, aut_->weightset()->transpose(k)));
161 DEFINE(lweight(transition_t t, weight_t k),
162 lweight(t, aut_->weightset()->transpose(k)));
163 DEFINE(rweight(transition_t t, weight_t k),
164 rweight(t, aut_->weightset()->transpose(k)));
166 DEFINE(del_transition(transition_t t), del_transition(t));
167 DEFINE(del_transition(state_t s, state_t d, label_t l),
168 del_transition(d, s, aut_->labelset()->transpose(l)));
170 DEFINE(add_transition(state_t s, state_t d, label_t l, weight_t k),
172 aut_->labelset()->transpose(l),
173 aut_->weightset()->transpose(k)));
174 DEFINE(add_transition(state_t s, state_t d, label_t l),
175 add_transition(d, s, aut_->labelset()->transpose(l)));
177 DEFINE(new_transition(state_t s, state_t d, label_t l, weight_t k),
179 aut_->labelset()->transpose(l),
180 aut_->weightset()->transpose(k)));
181 DEFINE(new_transition(state_t s, state_t d, label_t l),
183 aut_->labelset()->transpose(l)));
185 DEFINE(set_transition(state_t s, state_t d, label_t l, weight_t k),
187 aut_->labelset()->transpose(l),
188 aut_->weightset()->transpose(k)));
189 DEFINE(set_initial(state_t s, weight_t k),
190 set_final(s, aut_->weightset()->transpose(k)));
191 DEFINE(set_final(state_t s, weight_t k),
192 set_initial(s, aut_->weightset()->transpose(k)));
193 DEFINE(add_initial(state_t s, weight_t k),
194 add_final(s, aut_->weightset()->transpose(k)));
195 DEFINE(add_final(state_t s, weight_t k),
196 add_initial(s, aut_->weightset()->transpose(k)));
198 template <Automaton A>
199 DEFINE(add_transition_copy(state_t src, state_t dst,
201 transition_t_of<A> t,
202 bool transpose = false),
203 add_transition_copy(dst, src, aut, t, !transpose));
205 template <Automaton A>
206 DEFINE(new_transition_copy(state_t src, state_t dst,
208 transition_t_of<A> t,
209 bool transpose = false),
210 new_transition_copy(dst, src, aut, t, !transpose));
216 /*-----------------------------------.
217 | constexpr methods that transpose. |
218 `-----------------------------------*/
220 #define DEFINE(Signature, Value) \
224 -> decltype(automaton_t::element_type::Value) \
226 return automaton_t::element_type::Value; \
229 DEFINE(post(), pre());
230 DEFINE(pre(), post());
236 template <Automaton Aut>
238 transpose(const transpose_automaton<Aut>& aut)
240 return aut->naked_automaton();
243 template <Automaton Aut>
244 transpose_automaton<Aut>
247 return make_shared_ptr<transpose_automaton<Aut>>(aut);
255 template <Automaton Aut>
257 transpose(automaton& aut)
259 auto& a = aut->as<Aut>();
260 return vcsn::transpose(a);
266 /*------------------------------.
267 | dyn::transpose(expression). |
268 `------------------------------*/
274 template <typename ExpSet>
276 transpose_expression(const expression& exp)
278 const auto& e = exp->as<ExpSet>();
279 return {e.valueset(), ::vcsn::transpose(e.valueset(), e.value())};
284 /*----------------------------------.
285 | dyn::transposition(expression). |
286 `----------------------------------*/
292 template <typename ExpSet>
294 transposition_expression(const expression& exp)
296 const auto& e = exp->as<ExpSet>();
297 return {e.valueset(), e.valueset().transposition(e.value())};
weight_t_of< automaton_t > weight_t
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of
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...
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Aggregate an automaton, and forward calls to it.
labelset_t_of< automaton_t > labelset_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Aut automaton_t
The type of automaton to wrap.
transition_t_of< automaton_t > transition_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
label_t_of< automaton_t > label_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
std::shared_ptr< detail::transpose_automaton_impl< Aut >> transpose_automaton
An automaton wrapper that presents the transposed automaton.
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
transpose_automaton< automaton_t > self_t
An input/output format for valuesets.
typename automaton_t::element_type::kind_t kind_t
weightset_t_of< automaton_t > weightset_t
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
automaton_t aut_
The wrapped automaton, possibly const.
context_t_of< automaton_t > context_t
state_t_of< automaton_t > state_t