00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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 }
00070
00071 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX