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 <class Self, class Auto>
00030 void
00031 do_auto_in_concat(const AutomataBase<Self>& ,
00032 Auto& lhs,
00033 const Auto& rhs)
00034 {
00035 AUTOMATON_TYPES(Auto);
00036 std::map<hstate_t, hstate_t> trans;
00037
00038 for_all_states(s, rhs)
00039 {
00040 hstate_t ns = lhs.add_state();
00041 trans[*s] = ns;
00042 if (rhs.is_initial(*s))
00043 for_all_final_states(f, lhs)
00044 lhs.add_series_transition(*f, ns,
00045 lhs.get_final(*f) * rhs.get_initial(*s));
00046 }
00047 for_all_transitions(e, rhs)
00048 lhs.add_transition(trans[rhs.src_of(*e)],
00049 trans[rhs.dst_of(*e)],
00050 rhs.label_of(*e));
00051 lhs.clear_final();
00052 for_all_final_states(f, rhs)
00053 lhs.set_final(trans[*f], rhs.get_final(*f));
00054 }
00055
00056
00057 template <class A, class T>
00058 Element<A, T>
00059 concatenate(const Element<A, T>& lhs, const Element<A, T>& rhs)
00060 {
00061 Element<A, T> ret(lhs);
00062 do_auto_in_concat(ret.structure(), ret, rhs);
00063 return ret;
00064 }
00065
00066 template <class A, class T>
00067 void
00068 concatenate_here(Element<A, T>& lhs, const Element<A, T>& rhs)
00069 {
00070 do_auto_in_concat(lhs.structure(), lhs, rhs);
00071 }
00072
00073 }
00074
00075 #endif // ! VCSN_ALGORITHMS_CONCATENATE_HXX