3 #include <unordered_map>
5 #include <vcsn/algos/fwd.hh>
27 template <Automaton Aut>
32 template <Automaton Aut>
37 template <Automaton Aut>
41 -> decltype(aut->context())
43 return aut->context();
47 template <std::
size_t Tape, Automaton Aut>
51 -> decltype(aut->full_context())
53 return aut->full_context();
61 template <Automaton Aut>
71 template <Automaton Aut>
89 Automaton AutOut = fresh_automaton_t_of<AutIn>>
113 template <Automaton AutIn, Automaton AutOut = AutIn>
149 , out_state_{{in_->pre(), out_->pre()},
150 {in_->post(), out_->post()}}
160 template <
typename KeepState,
typename KeepTrans>
166 for (
auto s: in_->states())
168 out_state_[s] = out_->new_state();
173 auto src = out_state_.find(in_->src_of(t));
174 auto dst = out_state_.find(in_->dst_of(t));
175 if (src != out_state_.end() && dst != out_state_.end())
178 out_->new_transition_copy(src->second, dst->second,
181 out_->add_transition_copy(src->second, dst->second,
190 template <
typename Transitions>
192 -> decltype(ts[0] == in_->null_transition(),
void())
203 auto src =
state(in_->src_of(t));
204 auto dst =
state(in_->dst_of(t));
206 out_->new_transition_copy(src, dst, in_, t);
208 out_->add_transition_copy(src, dst, in_, t);
236 auto i = out_state_.find(s);
237 if (i == std::end(out_state_))
238 res = out_state_.emplace(s, out_->new_state()).first->second;
254 template <Automaton AutIn, Automaton AutOut>
255 detail::copier<AutIn, AutOut>
258 return {
in,
out, safe};
265 typename KeepState,
typename KeepTrans>
268 KeepState keep_state, KeepTrans keep_trans)
271 copy(keep_state, keep_trans);
276 template <Automaton AutIn, Automaton AutOut,
typename KeepState>
287 template <Automaton AutIn, Automaton AutOut>
306 template <Automaton AutIn, Automaton AutOut>
319 Automaton AutOut = fresh_automaton_t_of<AutIn>,
320 typename KeepState,
typename KeepTrans>
322 copy(
const AutIn& input, KeepState keep_state, KeepTrans keep_trans)
323 -> decltype(keep_state(input->null_state()),
324 keep_trans(input->null_transition()),
325 make_fresh_automaton<AutIn, AutOut>(input))
327 auto res = make_fresh_automaton<AutIn, AutOut>(input);
335 Automaton AutOut = fresh_automaton_t_of<AutIn>,
338 copy(
const AutIn& input, KeepState keep_state)
339 -> decltype(keep_state(input->null_state()),
340 make_fresh_automaton<AutIn, AutOut>(input))
342 return ::vcsn::copy<AutIn, AutOut>(
352 Automaton AutOut = fresh_automaton_t_of<AutIn>>
356 return ::vcsn::copy<AutIn, AutOut>(
367 Automaton AutOut = fresh_automaton_t_of<AutIn>,
370 copy(
const AutIn& input,
const States& ss)
371 -> decltype(*ss.begin() == input->null_state(),
372 make_fresh_automaton<AutIn, AutOut>(input))
374 return ::vcsn::copy<AutIn, AutOut>
384 Automaton AutOut = fresh_automaton_t_of<AutIn>,
385 typename States,
typename Trans>
387 copy(
const AutIn& input,
const States& ss,
const Trans& ts)
388 -> decltype(*ss.begin() == input->null_state(),
389 *ts.begin() == input->null_transition(),
390 make_fresh_automaton<AutIn, AutOut>(input))
392 return ::vcsn::copy<AutIn, AutOut>
402 Automaton AutOut = fresh_automaton_t_of<AutIn>,
403 typename Transitions>
405 copy(
const AutIn& input,
const Transitions& ts)
406 -> decltype(*ts.begin() == input->null_transition(),
407 make_fresh_automaton<AutIn, AutOut>(input))
409 auto res = make_fresh_automaton<AutIn, AutOut>(input);
421 template <Automaton Aut,
typename Ctx>
425 const auto& a = aut->
as<Aut>();
426 const auto& c = ctx->
as<Ctx>();
433 template <Automaton Aut>
437 const auto& a = aut->
as<Aut>();
452 template <
typename ExpSet,
typename Context,
typename Identities>
457 const auto&
r = exp->as<ExpSet>();
458 const auto& c = ctx->
as<Context>();
void operator()()
Copy all the states, and all the transitions.
automaton copy(const automaton &aut)
Bridge.
bool safe_
whether the input automaton is in normal form and never has two transitions with same (src...
void operator()(KeepState keep_state, KeepTrans keep_trans)
Copy some states, and some transitions.
static auto context(const automaton_decorator< Aut > &aut) -> decltype(real_context(aut->strip()))
std::unordered_map< in_state_t, out_state_t > state_map_t
input state -> output state.
expression copy_expression(const expression &exp, const context &ctx, identities ids)
Bridge (copy).
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
void copy_into(const AutIn &in, AutOut &out, bool safe)
Copy an automaton.
state_map_t & state_map()
A map from original state to result state.
Aggregate an automaton, and forward calls to it.
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
state_map_t out_state_
input state -> output state.
auto operator()(const Transitions &ts) -> decltype(ts[0]==in_->null_transition(), void())
Copy some transitions, and their corresponding states.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
state_t_of< out_automaton_t > out_state_t
automaton copy_convert(const automaton &aut, const context &ctx)
Bridge (copy).
static auto context(const focus_automaton< Tape, Aut > &aut) -> decltype(aut->full_context())
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
auto & as()
Downcast to the exact type.
When we copy a focus automaton, we create another focus automaton.
in_automaton_t in_
Input automaton.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
Template-less root for contexts.
auto copy(const AutIn &input, KeepState keep_state, KeepTrans keep_trans) -> decltype(keep_state(input->null_state()), keep_trans(input->null_transition()), make_fresh_automaton< AutIn, AutOut >(input))
A copy of input keeping only its states that are accepted by keep_state, and transitions accepted by ...
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
static auto context(const Aut &aut) -> decltype(aut->context())
copier(const in_automaton_t &in, out_automaton_t &out, bool safe=true)
Prepare for an automaton full/partial duplication.
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
auto real_context(const Aut &aut) -> decltype(real_context_impl< Aut >::context(aut))
For a focus automaton, its genuine context (not the visible one), and for all the other automata...
std::shared_ptr< detail::focus_automaton_impl< Tape, Aut >> focus_automaton
A focus automaton as a shared pointer.
detail::copier< AutIn, AutOut > make_copier(const AutIn &in, AutOut &out, bool safe=true)
Build an automaton copier.
auto make_expressionset(const context< LabelSet, WeightSet > &ctx, rat::identities ids={}) -> expressionset< context< LabelSet, WeightSet >>
Shorthand to expressionset constructor.
out_state_t state(const in_state_t &s)
The out state corresponding to the in-state s.
const state_map_t & state_map() const
A map from original state to result state.
auto & as()
Extract wrapped typed automaton.
static identities ids(const driver &d)
Get the identities of the driver.
Provide a variadic mul on top of a binary mul(), and one().
state_t_of< in_automaton_t > in_state_t
value_impl< detail::expression_tag > expression
out_automaton_t out_
Output automaton.
OutExpSet::value_t copy(const InExpSet &in_rs, const OutExpSet &out_rs, const typename InExpSet::value_t &v)
Copy/convert a rational expression.
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
void operator()(const transition_t_of< in_automaton_t > &t)
Copy one transition, and its corresponding states.