Vaucanson  1.4.1
translate.hxx
1 // translate.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX
18 # define VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX
19 
20 # include <vaucanson/automata/concept/translate.hh>
21 # include <vaucanson/automata/concept/handlers.hh>
22 # include <map>
23 
24 namespace vcsn {
25 
26  template<typename lhs_t, typename rhs_t, typename F>
27  void auto_translate_transitions(lhs_t& dst_,
28  const rhs_t& from,
29  const F& translate_fun)
30  {
31  lhs_t dst;
32  std::map<typename rhs_t::hstate_t, typename lhs_t::hstate_t> stmap;
33 
34  dst.create();
35  dst.series() = from.series();
36  for (typename rhs_t::state_iterator i = from.states().begin();
37  i != from.states().end();
38  ++i)
39  {
40  typename lhs_t::hstate_t s = dst.add_state();
41  dst.set_final(s, from.get_final(*i));
42  dst.set_initial(s, from.get_initial(*i));
43  stmap[*i] = s;
44  }
45  for (typename rhs_t::transition_iterator i = from.transitions().begin();
46  i != from.transitions().end();
47  ++i)
48  dst.add_series_transition(stmap[from.src_of(*i)], stmap[from.dst_of(*i)],
49  translate_fun(from.series_of(*i)));
50  dst_.swap(dst);
51  }
52 
53  template<typename auto_t, typename F>
54  auto_t auto_translate_transitions(const auto_t& from, const F& translate_fun)
55  {
56  auto_t dst;
57  auto_translate_transitions(dst, from, translate_fun);
58  return dst;
59  }
60 
61 } // vcsn
62 
63 #endif // ! VCSN_AUTOMATA_CONCEPT_TRANSLATE_HXX