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 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
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 }
00072
00073 #endif // ! VCSN_ALGORITHMS_SUB_AUTOMATON_HXX