translate.hxx

00001 // translate.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_AUTOMATA_CONCEPT_TRANSLATE_HXX
00018 # define VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX
00019 
00020 # include <vaucanson/automata/concept/translate.hh>
00021 # include <vaucanson/automata/concept/handlers.hh>
00022 # include <map>
00023 
00024 namespace vcsn {
00025 
00026   template<typename lhs_t, typename rhs_t, typename F>
00027   void auto_translate_transitions(lhs_t& dst_,
00028                                   const rhs_t& from,
00029                                   const F& translate_fun)
00030   {
00031     lhs_t dst;
00032     std::map<hstate_t, hstate_t> stmap;
00033 
00034     dst.create();
00035     dst.series() = from.series();
00036     for (typename rhs_t::state_iterator i = from.states().begin();
00037          i != from.states().end();
00038          ++i)
00039     {
00040       hstate_t s = dst.add_state();
00041       dst.set_final(s, from.get_final(*i));
00042       dst.set_initial(s, from.get_initial(*i));
00043       stmap[*i] = s;
00044     }
00045     for (typename rhs_t::transition_iterator i = from.transitions().begin();
00046          i != from.transitions().end();
00047          ++i)
00048       dst.add_series_transition(stmap[i.origin()], stmap[i.aim()],
00049                                 translate_fun(from.series_of(*i)));
00050     dst_.swap(dst);
00051   }
00052 
00053   template<typename auto_t, typename F>
00054   auto_t auto_translate_transitions(const auto_t& from, const F& translate_fun)
00055   {
00056     auto_t dst;
00057     auto_translate_transitions(dst, from, translate_fun);
00058     return dst;
00059   }
00060 
00061 } // vcsn
00062 
00063 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX

Generated on Fri Jul 28 12:18:55 2006 for Vaucanson by  doxygen 1.4.6