Vaucanson  1.4.1
copy.hxx
1 // copy.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_COPY_HXX
18 # define VCSN_AUTOMATA_CONCEPT_COPY_HXX
19 
20 # include <map>
21 # include <vaucanson/automata/concept/handlers.hh>
22 
23 
24 namespace vcsn
25 {
26 
27  template<typename lhs_t, typename rhs_t>
28  void auto_copy(lhs_t& dst_,
29  const rhs_t& from)
30  {
31  lhs_t dst(dst_.structure());
32  typedef typename lhs_t::series_set_elt_t dst_series_set_elt_t;
33 
34  std::map<typename rhs_t::hstate_t, typename lhs_t::hstate_t> stmap;
35 
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_series_set_elt_t s_(from.get_final(*i));
42  dst.set_final(s, s_);
43  dst_series_set_elt_t s__(from.get_initial(*i));
44  dst.set_initial(s, s__);
45  stmap[*i] = s;
46  }
47 
48  for (typename rhs_t::transition_iterator i = from.transitions().begin();
49  i != from.transitions().end();
50  ++i)
51  {
52  dst_series_set_elt_t s(from.series_of(*i));
53  dst.add_series_transition(stmap[from.src_of(*i)], stmap[from.dst_of(*i)], s);
54  }
55  dst_.swap(dst);
56  }
57 
58  template<typename auto_t>
59  auto_t auto_copy(const auto_t& from)
60  {
61  auto_t dst;
62  auto_copy(dst, from);
63  return dst;
64  }
65 
66 }
67 
68 
69 #endif // ! VCSN_AUTOMATA_CONCEPT_COPY_HXX