sub_automaton.hxx

00001 // sub_automaton.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, 2007 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_SUB_AUTOMATON_HXX
00018 # define VCSN_ALGORITHMS_SUB_AUTOMATON_HXX
00019 
00020 # include <vaucanson/algorithms/sub_automaton.hh>
00021 
00022 # include <vaucanson/automata/concept/automata_base.hh>
00023 # include <vaucanson/misc/usual_macros.hh>
00024 
00025 # include <list>
00026 
00027 namespace vcsn {
00028 
00029   /*----------------------------------------.
00030   | SubAutomaton defined by a set of states |
00031   `----------------------------------------*/
00032 
00033   template<typename A, typename auto_t, typename list_t>
00034   void do_sub_automaton_here(const AutomataBase<A>&,
00035                              auto_t& a,
00036                              const list_t& selected,
00037                              bool check_states)
00038   {
00039     TIMER_SCOPED("sub_automaton");
00040     std::list<hstate_t> to_be_removed;
00041     for (typename auto_t::state_iterator i = a.states().begin();
00042          i != a.states().end(); ++i)
00043       if (std::find(selected.begin(), selected.end(), *i) == selected.end())
00044         to_be_removed.push_back(*i);
00045 
00046     for_all_const_(std::list<hstate_t>, i, to_be_removed)
00047       if (!check_states
00048           || a.has_state(*i))
00049         a.del_state(*i);
00050   }
00051 
00052 
00053   // wrapper:
00054   template<typename A, typename T, typename StatesSet>
00055   Element<A, T>
00056   sub_automaton(const Element<A, T>& a, const StatesSet& s, bool check_states)
00057   {
00058     Element<A, T> ret(a);
00059     do_sub_automaton_here(ret.structure(), ret, s, check_states);
00060     return ret;
00061   }
00062 
00063   template<typename A, typename T, typename StatesSet>
00064   void sub_automaton_here(Element<A, T>& a, const StatesSet& s, bool check_states)
00065   {
00066     do_sub_automaton_here(a.structure(), a, s, check_states);
00067   }
00068 
00069 } // vcsn
00070 
00071 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX

Generated on Sun Jul 29 19:35:29 2007 for Vaucanson by  doxygen 1.5.2