3 #include <unordered_map>
5 #include <vcsn/algos/fwd.hh>
26 template <Automaton Aut>
31 template <Automaton Aut>
36 template <Automaton Aut>
40 -> decltype(aut->context())
42 return aut->context();
46 template <std::
size_t Tape, Automaton Aut>
50 -> decltype(aut->full_context())
52 return aut->full_context();
60 template <Automaton Aut>
70 template <Automaton Aut>
88 Automaton AutOut = fresh_automaton_t_of<AutIn>>
112 template <Automaton AutIn, Automaton AutOut = AutIn>
148 , out_state_{{in_->pre(), out_->pre()},
149 {in_->post(), out_->post()}}
159 template <
typename KeepState,
typename KeepTrans>
165 for (
auto s: in_->states())
167 out_state_[s] = out_->new_state();
172 auto src = out_state_.find(in_->src_of(t));
173 auto dst = out_state_.find(in_->dst_of(t));
174 if (src != out_state_.end() && dst != out_state_.end())
177 out_->new_transition_copy(src->second, dst->second,
180 out_->add_transition_copy(src->second, dst->second,
189 template <
typename Transitions>
191 -> decltype(ts[0] == in_->null_transition(),
void())
202 auto src =
state(in_->src_of(t));
203 auto dst =
state(in_->dst_of(t));
205 out_->new_transition_copy(src, dst, in_, t);
207 out_->add_transition_copy(src, dst, in_, t);
235 auto i = out_state_.find(s);
236 if (i == std::end(out_state_))
237 res = out_state_.emplace(s, out_->new_state()).first->second;
247 template <Automaton AutIn, Automaton AutOut>
248 detail::copier<AutIn, AutOut>
251 return {
in,
out, safe};
258 typename KeepState,
typename KeepTrans>
261 KeepState keep_state, KeepTrans keep_trans)
264 copy(keep_state, keep_trans);
269 template <Automaton AutIn, Automaton AutOut,
typename KeepState>
280 template <Automaton AutIn, Automaton AutOut>
292 template <Automaton AutIn, Automaton AutOut>
305 Automaton AutOut = fresh_automaton_t_of<AutIn>,
306 typename KeepState,
typename KeepTrans>
308 copy(
const AutIn& input, KeepState keep_state, KeepTrans keep_trans)
309 -> decltype(keep_state(input->null_state()),
310 keep_trans(input->null_transition()),
311 make_fresh_automaton<AutIn, AutOut>(input))
313 auto res = make_fresh_automaton<AutIn, AutOut>(input);
321 Automaton AutOut = fresh_automaton_t_of<AutIn>,
324 copy(
const AutIn& input, KeepState keep_state)
325 -> decltype(keep_state(input->null_state()),
326 make_fresh_automaton<AutIn, AutOut>(input))
328 return ::vcsn::copy<AutIn, AutOut>(
338 Automaton AutOut = fresh_automaton_t_of<AutIn>>
342 return ::vcsn::copy<AutIn, AutOut>(
353 Automaton AutOut = fresh_automaton_t_of<AutIn>,
356 copy(
const AutIn& input,
const States& ss)
357 -> decltype(*ss.begin() == input->null_state(),
358 make_fresh_automaton<AutIn, AutOut>(input))
360 return ::vcsn::copy<AutIn, AutOut>
370 Automaton AutOut = fresh_automaton_t_of<AutIn>,
371 typename States,
typename Trans>
373 copy(
const AutIn& input,
const States& ss,
const Trans& ts)
374 -> decltype(*ss.begin() == input->null_state(),
375 *ts.begin() == input->null_transition(),
376 make_fresh_automaton<AutIn, AutOut>(input))
378 return ::vcsn::copy<AutIn, AutOut>
388 Automaton AutOut = fresh_automaton_t_of<AutIn>,
389 typename Transitions>
391 copy(
const AutIn& input,
const Transitions& ts)
392 -> decltype(*ts.begin() == input->null_transition(),
393 make_fresh_automaton<AutIn, AutOut>(input))
395 auto res = make_fresh_automaton<AutIn, AutOut>(input);
407 template <Automaton Aut,
typename Ctx>
411 const auto& a = aut->as<Aut>();
412 const auto& c = ctx->as<Ctx>();
419 template <Automaton Aut>
423 const auto& a = aut->as<Aut>();
438 template <
typename ExpSet,
typename Context,
typename Identities>
443 const auto&
r = exp->as<ExpSet>();
444 const auto& c = ctx->as<Context>();
std::shared_ptr< detail::focus_automaton_impl< Tape, Aut >> focus_automaton
A focus automaton as a shared pointer.
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...
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
copier(const in_automaton_t &in, out_automaton_t &out, bool safe=true)
Prepare for an automaton full/partial duplication.
void operator()()
Copy all the states, and all the transitions.
void operator()(KeepState keep_state, KeepTrans keep_trans)
Copy some states, and some transitions.
An expressionset can implement several different sets of identities on expressions.
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
state_t_of< out_automaton_t > out_state_t
static auto context(const focus_automaton< Tape, Aut > &aut) -> decltype(aut->full_context())
state_map_t & state_map()
A map from original state to result state.
out_state_t state(const in_state_t &s)
The out state corresponding to the in-state s.
Provide a variadic mul on top of a binary mul(), and one().
in_automaton_t in_
Input automaton.
auto operator()(const Transitions &ts) -> decltype(ts[0]==in_->null_transition(), void())
Copy some transitions, and their corresponding states.
out_automaton_t out_
Output automaton.
static auto context(const Aut &aut) -> decltype(aut->context())
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
void copy_into(const AutIn &in, AutOut &out, bool safe)
Copy an automaton.
expression copy_expression(const expression &exp, const context &ctx, rat::identities ids)
Bridge (copy).
std::shared_ptr< const detail::context_base > context
A dyn::context.
void operator()(const transition_t_of< in_automaton_t > &t)
Copy one transition, and its corresponding states.
Aggregate an automaton, and forward calls to it.
std::shared_ptr< detail::automaton_base > automaton
typename detail::transition_t_of_impl< base_t< ValueSet >>::type transition_t_of
bool safe_
whether the input automaton is in normal form and never has two transitions with same (src...
std::unordered_map< in_state_t, out_state_t > state_map_t
input state -> output state.
expressionset< Context > make_expressionset(const Context &ctx, rat::identities identities={})
Shorthand to expressionset constructor.
static dyn::context ctx(const driver &d)
Get the context of the driver.
const state_map_t & state_map() const
A map from original state to result state.
state_map_t out_state_
input state -> output state.
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
automaton copy(const automaton &aut)
Bridge.
AutOut make_fresh_automaton(const AutIn &model)
Create an empty, mutable, automaton, based on another one.
mutable_automaton< Context > make_mutable_automaton(const Context &ctx)
OutExpSet::value_t copy(const InExpSet &in_rs, const OutExpSet &out_rs, const typename InExpSet::value_t &v)
Copy/convert a rational expression.
static auto context(const automaton_decorator< Aut > &aut) -> decltype(real_context(aut->strip()))
detail::copier< AutIn, AutOut > make_copier(const AutIn &in, AutOut &out, bool safe=true)
Build an automaton copier.
std::shared_ptr< detail::expression_base > expression
static identities ids(const driver &d)
Get the identities of the driver.
auto all_transitions(const Aut &aut)
All the transition indexes between all states (including pre and post).
auto in(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions arriving to state s.
expression make_expression(const ExpSet &rs, const typename ExpSet::value_t &r)
When we copy a focus automaton, create another focus automaton.
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 ...
automaton copy_convert(const automaton &aut, const context &ctx)
Bridge (copy).
state_t_of< in_automaton_t > in_state_t