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 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     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 } // vcsn
00074 
00075 #endif // ! VCSN_ALGORITHMS_CONCATENATE_HXX

Generated on Sat Jul 29 17:12:58 2006 for Vaucanson by  doxygen 1.4.6