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/tools/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(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_each_const_(std::list<hstate_t>, i, to_be_removed)
00049 if ((!check_states) || (a.has_state(*i)))
00050 a.del_state(*i);
00051 }
00052
00053
00054
00055 template<typename A, typename T, typename StatesSet>
00056 Element<A, T>
00057 sub_automaton(const Element<A, T>& a, const StatesSet& s, bool check_states)
00058 {
00059 Element<A, T> ret(a);
00060 do_sub_automaton(ret.structure(), ret, s, check_states);
00061 return ret;
00062 }
00063
00064 template<typename A, typename T, typename StatesSet>
00065 void sub_automaton_here(Element<A, T>& a, const StatesSet& s, bool check_states)
00066 {
00067 do_sub_automaton(a.structure(), a, s, check_states);
00068 }
00069
00070 }
00071
00072 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX