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, 2008 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 <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 } // vcsn
00076 
00077 #endif // ! VCSN_ALGORITHMS_CONCATENATE_HXX

Generated on Thu Oct 9 20:22:34 2008 for Vaucanson by  doxygen 1.5.1