00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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<typename rhs_t::hstate_t, typename lhs_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 typename lhs_t::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[from.src_of(*i)], stmap[from.dst_of(*i)],
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 }
00062
00063 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX