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