3 #include <vcsn/algos/fwd.hh>
25 template <Automaton A,
typename I>
28 template <
Automaton Aut, std::size_t... I>
37 template <std::
size_t Tape, Automaton Aut>
40 project_context<Tape, context_t_of<Aut>>>
47 "focus: requires labels_are_tuples");
49 "focus: invalid tape number");
69 using label_t =
typename labelset_t::value_t;
74 using weight_t =
typename weightset_t::value_t;
93 template <
typename =
void>
123 static auto res =
symbol{
"focus_automaton<"
131 o <<
"focus_automaton<" << Tape <<
", ";
132 aut_->print_set(o, fmt);
136 full_context_t full_context() const
138 return aut_->context();
141 context_t context() const
147 hidden_label_of(transition_t t) const
149 return hidden_label_of_(t, hidden_indices);
155 return hidden_one_<full_labelset_t>(hidden_indices);
161 return res_labelset_(hidden_indices);
174 hidden_indices_t hidden_indices{};
176 static label_t hide_(full_label_t l)
178 return std::get<Tape>(l);
181 template <std::size_t... I>
182 res_label_t hidden_label_of_(transition_t t, index_sequence<I...>) const
184 full_label_t l = aut_->label_of(t);
185 return std::make_tuple(std::get<I>(l)...);
188 template <typename L, std::size_t... I>
189 std::enable_if_t<L::has_one(), res_label_t>
190 hidden_one_(index_sequence<I...>) const
192 full_label_t l = aut_->labelset()->one();
193 return std::make_tuple(std::get<I>(l)...);
196 template <typename L, std::size_t... I>
197 std::enable_if_t<!L::has_one(), res_label_t>
198 hidden_one_(index_sequence<I...>) const
200 raise("Should not get here");
203 template <std::size_t... I>
204 res_labelset_t res_labelset_(index_sequence<I...>) const
206 return res_labelset_t{std::get<I>(aut_->labelset()->sets())...};
211 /*----------------------------.
212 | const methods that change. |
213 `----------------------------*/
216 auto label_of(transition_t t) const
219 return hide_(aut_->label_of(t));
222 // FIXME: http://llvm.org/bugs/show_bug.cgi?id=20175.
223 // using super_t::out;
226 -> decltype(out(aut_, s))
231 // FIXME: Having support for predicates in
232 // mutable_automaton::get_transition would help.
234 get_transition(state_t src, state_t dst, label_t l) const
236 for (auto t: out(src, l))
237 if (aut_->dst_of(t) == dst)
239 return aut_->null_transition();
246 has_transition(transition_t t) const
248 return aut_->has_transition(t);
253 has_transition(state_t src, state_t dst, label_t l) const
255 return get_transition(src, dst, l) != aut_->null_transition();
258 using super_t::del_transition;
261 del_transition(state_t src, state_t dst, label_t l)
263 auto t = get_transition(src, dst, l);
264 if (t != aut_->null_transition())
265 aut_->del_transition(t);
269 template <Automaton A>
271 new_transition_copy(state_t src, state_t dst,
273 transition_t_of<A> t,
274 bool transpose = false)
276 return aut_->new_transition_copy(src, dst,
277 aut->strip(), t, transpose);
281 template <Automaton A>
283 add_transition_copy(state_t src, state_t dst,
285 transition_t_of<A> t,
286 bool transpose = false)
288 return aut_->add_transition_copy(src, dst,
289 aut->strip(), t, transpose);
292 #define DEFINE(Name, Sig) \
295 raise("focus: cannot provide " #Name); \
298 DEFINE(add_transition,
299 (state_t, state_t, label_t, weight_t) -> transition_t);
300 DEFINE(add_transition,
301 (state_t, state_t, label_t) -> transition_t);
302 DEFINE(new_transition,
303 (state_t, state_t, label_t, weight_t) -> transition_t);
304 DEFINE(new_transition,
305 (state_t, state_t, label_t) -> transition_t);
306 DEFINE(set_transition,
307 (state_t, state_t, label_t, weight_t) -> transition_t);
315 context_t context_ = project<Tape>(full_context());
321 = std::make_shared<labelset_t>(aut_->labelset()->template set<Tape>());
325 template <unsigned Tape, Automaton Aut>
326 focus_automaton<Tape, Aut>
329 return std::make_shared<detail::focus_automaton_impl<Tape, Aut>>(aut);
338 template <Automaton Aut, typename Tape>
340 focus(const automaton& aut, integral_constant)
342 auto& a = aut->as<Aut>();
343 return vcsn::focus<Tape::value>(a);
typename labelset_t::value_t label_t
typename context_t::weightset_t weightset_t
Exposed weightset.
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
transition_t_of< automaton_t > transition_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
typename concat_index_sequence< S1, S2 >::type concat_sequence
labelset_t_of< Aut > ls_t
std::shared_ptr< const labelset_t > labelset_ptr
Aggregate an automaton, and forward calls to it.
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
typename hidden_label_type< Aut, hidden_indices_t >::type res_labelset_t
typename Aut::element_type::template fresh_automaton_t< Context > fresh_automaton_t_of
Given an automaton type, the type of its copies.
typename context_t::weightset_ptr weightset_ptr
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
concat_sequence< make_index_range_t< 0, Tape >, make_index_range_t< Tape+1, std::tuple_size< full_label_t >::value >> hidden_indices_t
Indices of the remaining tapes.
typename weightset_t::value_t weight_t
typename full_labelset_t::value_t full_label_t
Underlying automaton label.
focus_automaton< Tape, fresh_automaton_t_of< automaton_t, full_context_t >> fresh_automaton_t
The type of automata to produce this kind of automata.
context_t_of< automaton_t > full_context_t
Underlying automaton context.
Aut automaton_t
The type of the wrapped automaton.
std::shared_ptr< detail::focus_automaton_impl< Tape, Aut >> focus_automaton
A focus automaton as a shared pointer.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Read-write on an automaton, that hides all tapes but one.
focus_automaton_impl(const automaton_t &aut)
typename full_context_t::labelset_t full_labelset_t
Underlying automaton labelset.
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
typename res_labelset_t::value_t res_label_t
typename make_index_range< S, E >::type make_index_range_t
state_t_of< automaton_t > state_t
This automaton's state and transition types are those of the wrapped automaton.
focus_automaton_impl(const full_context_t &ctx)
automaton_t aut_
The wrapped automaton, possibly const.
typename context_t::labelset_t labelset_t
Exposed labelset.
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename context_t::labelset_ptr labelset_ptr
std::string to_string(identities i)
Wrapper around operator<<.
std::shared_ptr< const weightset_t > weightset_ptr