3 #include <vcsn/algos/fwd.hh>
24 template <
typename A,
typename I>
27 template <
Automaton Aut, std::size_t... I>
36 template <std::
size_t Tape, Automaton Aut>
39 project_context<Tape, context_t_of<Aut>>>
46 "focus: requires labels_are_tuples");
48 "focus: invalid tape number");
68 using label_t =
typename labelset_t::value_t;
73 using weight_t =
typename weightset_t::value_t;
92 template <
typename =
void>
102 std::tuple_size<full_label_t>::value - Tape - 1>>;
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();
244 has_transition(state_t src, state_t dst, label_t l) const
246 return get_transition(src, dst, l) != aut_->null_transition();
249 using super_t::del_transition;
252 del_transition(state_t src, state_t dst, label_t l)
254 auto t = get_transition(src, dst, l);
255 if (t != aut_->null_transition())
256 aut_->del_transition(t);
260 template <typename A>
262 new_transition_copy(state_t src, state_t dst,
264 typename A::element_type::transition_t t,
265 bool transpose = false)
267 return aut_->new_transition_copy(src, dst,
268 aut->strip(), t, transpose);
272 template <typename A>
274 add_transition_copy(state_t src, state_t dst,
276 typename A::element_type::transition_t t,
277 bool transpose = false)
279 return aut_->add_transition_copy(src, dst,
280 aut->strip(), t, transpose);
283 #define DEFINE(Name, Sig) \
286 raise("focus: cannot provide " #Name); \
289 DEFINE(add_transition,
290 (state_t, state_t, label_t, weight_t) -> transition_t);
291 DEFINE(add_transition,
292 (state_t, state_t, label_t) -> transition_t);
293 DEFINE(new_transition,
294 (state_t, state_t, label_t, weight_t) -> transition_t);
295 DEFINE(new_transition,
296 (state_t, state_t, label_t) -> transition_t);
297 DEFINE(set_transition,
298 (state_t, state_t, label_t, weight_t) -> transition_t);
306 context_t context_ = project<Tape>(full_context());
312 = std::make_shared<labelset_t>(aut_->labelset()->template set<Tape>());
316 template <unsigned Tape, Automaton Aut>
318 focus_automaton<Tape, Aut>
321 return std::make_shared<detail::focus_automaton_impl<Tape, Aut>>(aut);
330 template <Automaton Aut, typename Tape>
332 focus(const automaton& aut, integral_constant)
334 auto& a = aut->as<Aut>();
335 return make_automaton(vcsn::focus<Tape::value>(a));
std::shared_ptr< detail::focus_automaton_impl< Tape, Aut >> focus_automaton
A focus automaton as a shared pointer.
typename labelset_t::value_t label_t
labelset_t_of< Aut > ls_t
focus_automaton_impl(const automaton_t &aut)
Aut automaton_t
The type of the wrapped automaton.
automaton_t aut_
The wrapped automaton, possibly const.
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
SharedPtr make_shared_ptr(Args &&...args)
Same as std::make_shared, but parameterized by the shared_ptr type, not the (pointed to) element_type...
An input/output format for valuesets.
Provide a variadic mul on top of a binary mul(), and one().
state_t_of< automaton_t > state_t
This automaton's state and transition types are those of the wrapped automaton.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
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.
typename res_labelset_t::value_t res_label_t
transition_t_of< automaton_t > transition_t
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
Aggregate an automaton, and forward calls to it.
Read-write on an automaton, that hides all tapes but one.
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_t weightset_t
Exposed weightset.
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
focus_automaton_impl(const full_context_t &ctx)
typename hidden_label_type< Aut, hidden_indices_t >::type res_labelset_t
typename make_index_range< S, L >::type make_index_range_t
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
typename full_labelset_t::value_t full_label_t
Underlying automaton label.
static dyn::context ctx(const driver &d)
Get the context of the driver.
typename full_context_t::labelset_t full_labelset_t
Underlying automaton labelset.
std::string to_string(identities i)
Wrapper around operator<<.
std::ostream & print_set(std::ostream &o, format fmt={}) const
std::shared_ptr< const weightset_t > weightset_ptr
concat_sequence< make_index_range_t< 0, Tape >, make_index_range_t< Tape+1, std::tuple_size< full_label_t >::value-Tape-1 >> hidden_indices_t
Indices of the remaining tapes.
typename concat_index_sequence< S1, S2 >::type concat_sequence
typename weightset_t::value_t weight_t
typename context_t::labelset_t labelset_t
Exposed labelset.
typename context_t::weightset_ptr weightset_ptr
std::shared_ptr< const labelset_t > labelset_ptr
context_t_of< automaton_t > full_context_t
Underlying automaton context.
typename context_t::labelset_ptr labelset_ptr