00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_CONCATENATE_HXX
00018 # define VCSN_ALGORITHMS_CONCATENATE_HXX
00019
00020 # include <vaucanson/algorithms/concatenate.hh>
00021
00022 # include <vaucanson/automata/concept/automata_base.hh>
00023 # include <vaucanson/misc/usual_macros.hh>
00024
00025 # include <map>
00026
00027 namespace vcsn {
00028
00029 template <typename A, typename AI>
00030 void
00031 do_auto_in_concat(const AutomataBase<A>& ,
00032 Element<A, AI>& lhs,
00033 const Element<A, AI>& rhs)
00034 {
00035 TIMER_SCOPED("concatentate");
00036 typedef Element<A, AI> automaton_t;
00037 AUTOMATON_TYPES(automaton_t);
00038 std::map<hstate_t, hstate_t> trans;
00039
00040 for_all_const_states(s, rhs)
00041 {
00042 hstate_t ns = lhs.add_state();
00043 trans[*s] = ns;
00044 if (rhs.is_initial(*s))
00045 for_all_const_final_states(f, lhs)
00046 lhs.add_series_transition(*f, ns,
00047 lhs.get_final(*f) * rhs.get_initial(*s));
00048 }
00049 for_all_const_transitions(e, rhs)
00050 lhs.add_transition(trans[rhs.src_of(*e)],
00051 trans[rhs.dst_of(*e)],
00052 rhs.label_of(*e));
00053 lhs.clear_final();
00054 for_all_const_final_states(f, rhs)
00055 lhs.set_final(trans[*f], rhs.get_final(*f));
00056 }
00057
00058
00059 template <typename A, typename AI>
00060 Element<A, AI>
00061 concatenate(const Element<A, AI>& lhs, const Element<A, AI>& rhs)
00062 {
00063 Element<A, AI> ret(lhs);
00064 do_auto_in_concat(ret.structure(), ret, rhs);
00065 return ret;
00066 }
00067
00068 template <typename A, typename AI>
00069 void
00070 concatenate_here(Element<A, AI>& lhs, const Element<A, AI>& rhs)
00071 {
00072 do_auto_in_concat(lhs.structure(), lhs, rhs);
00073 }
00074
00075 }
00076
00077 #endif // ! VCSN_ALGORITHMS_CONCATENATE_HXX