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, 2006 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     std::list<hstate_t> to_be_removed;
00040     for (typename auto_t::state_iterator i = a.states().begin();
00041          i != a.states().end(); ++i)
00042     {
00043       if (std::find(selected.begin(), selected.end(), *i)
00044           == selected.end())
00045         to_be_removed.push_back(*i);
00046     }
00047 
00048     for_all_const_(std::list<hstate_t>, i, to_be_removed)
00049       if (!check_states
00050           || a.has_state(*i))
00051         a.del_state(*i);
00052   }
00053 
00054 
00055   // wrapper:
00056   template<typename A, typename T, typename StatesSet>
00057   Element<A, T>
00058   sub_automaton(const Element<A, T>& a, const StatesSet& s, bool check_states)
00059   {
00060     Element<A, T> ret(a);
00061     do_sub_automaton_here(ret.structure(), ret, s, check_states);
00062     return ret;
00063   }
00064 
00065   template<typename A, typename T, typename StatesSet>
00066   void sub_automaton_here(Element<A, T>& a, const StatesSet& s, bool check_states)
00067   {
00068     do_sub_automaton_here(a.structure(), a, s, check_states);
00069   }
00070 
00071 } // vcsn
00072 
00073 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX

Generated on Sat Jul 29 17:13:11 2006 for Vaucanson by  doxygen 1.4.6