00001 // complement.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, 2005, 2006, 2008 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_ALGORITHMS_COMPLEMENT_HXX 00018 # define VCSN_ALGORITHMS_COMPLEMENT_HXX 00019 00020 # include <vaucanson/algorithms/complement.hh> 00021 00022 # ifndef VCSN_NDEBUG 00023 # include <vaucanson/algorithms/complete.hh> 00024 # include <vaucanson/algorithms/is_deterministic.hh> 00025 # endif // ! VCSN_NDEBUG 00026 00027 # include <vaucanson/misc/usual_macros.hh> 00028 # include <vaucanson/misc/contract.hh> 00029 00030 namespace vcsn { 00031 00032 /*------------------. 00033 | complement_here. | 00034 `------------------*/ 00035 00036 template <typename A, typename AI> 00037 void 00038 complement_here(Element<A, AI>& a) 00039 { 00040 TIMER_SCOPED("complement"); 00041 typedef Element<A, AI> automaton_t; 00042 AUTOMATON_TYPES(automaton_t); 00043 00044 precondition(is_complete(a)); 00045 precondition(is_deterministic(a)); 00046 for_all_const_states(i, a) 00047 if (a.is_final(*i)) 00048 a.unset_final(*i); 00049 else 00050 a.set_final(*i); 00051 } 00052 00053 /*-------------. 00054 | complement. | 00055 `-------------*/ 00056 00057 template <typename A, typename AI> 00058 Element<A, AI> 00059 complement(const Element<A, AI>& a) 00060 { 00061 Element<A, AI> res(a); 00062 complement_here(res); 00063 return res; 00064 } 00065 00066 } // vcsn 00067 00068 #endif // ! VCSN_ALGORITHMS_COMPLEMENT_HXX