concatenate.hxx

00001 // concatenate.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
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 } // vcsn
00075 
00076 #endif // ! VCSN_ALGORITHMS_CONCATENATE_HXX

Generated on Sun Jul 29 19:35:18 2007 for Vaucanson by  doxygen 1.5.2