Vaucanson  1.4.1
complement.hxx
1 // complement.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, 2008 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_ALGORITHMS_COMPLEMENT_HXX
18 # define VCSN_ALGORITHMS_COMPLEMENT_HXX
19 
21 
22 # ifndef VCSN_NDEBUG
25 # endif // ! VCSN_NDEBUG
26 
27 # include <vaucanson/misc/usual_macros.hh>
29 
30 namespace vcsn {
31 
32  /*------------------.
33  | complement_here. |
34  `------------------*/
35 
36  template <typename A, typename AI>
37  void
39  {
40  BENCH_TASK_SCOPED("complement");
41  typedef Element<A, AI> automaton_t;
42  AUTOMATON_TYPES(automaton_t);
43 
44  precondition(is_complete(a));
45  precondition(is_deterministic(a));
46  for_all_const_states(i, a)
47  if (a.is_final(*i))
48  a.unset_final(*i);
49  else
50  a.set_final(*i);
51  }
52 
53  /*-------------.
54  | complement. |
55  `-------------*/
56 
57  template <typename A, typename AI>
58  Element<A, AI>
60  {
61  Element<A, AI> res(a);
62  complement_here(res);
63  return res;
64  }
65 
66 } // vcsn
67 
68 #endif // ! VCSN_ALGORITHMS_COMPLEMENT_HXX