00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_ALGORITHMS_AUT_PROJECTION_HXX
00019 # define VCSN_ALGORITHMS_AUT_PROJECTION_HXX
00020
00021 # include <vaucanson/algorithms/aut_projection.hh>
00022
00023 namespace vcsn
00024 {
00025 template <typename S, typename T>
00026 void
00027 do_first_projection(const Element<S, T>& src,
00028 typename projection_traits<S, T>::
00029 first_projection_t& dst)
00030 {
00031 BENCH_TASK_SCOPED("first_projection");
00032
00033
00034 typedef Element<S, T> automaton_t;
00035 typedef projection_traits<S, T> projection_traits_t;
00036 typedef typename projection_traits_t::first_projection_t res_t;
00037 AUTOMATON_TYPES(automaton_t);
00038 AUTOMATON_TYPES_(res_t, res_);
00039
00040
00041 std::map<hstate_t, res_hstate_t> m;
00042
00043
00044 for_all_const_states(p, src)
00045 m[*p] = dst.add_state();
00046
00047
00048 for_all_const_initial_states(i, src)
00049 {
00050 dst.set_initial(m[*i],
00051 projection_traits_t::
00052 series_first_projection(dst.series(),
00053 src.get_initial(*i)));
00054 }
00055
00056
00057 for_all_const_transitions(e, src)
00058 {
00059 dst.add_series_transition(m[src.src_of(*e)],
00060 m[src.dst_of(*e)],
00061 projection_traits_t::
00062 series_first_projection(dst.series(),
00063 src.series_of(*e)));
00064 }
00065
00066
00067 for_all_const_final_states(f, src)
00068 {
00069 dst.set_final(m[*f],
00070 projection_traits_t::
00071 series_first_projection(dst.series(),
00072 src.get_final(*f)));
00073 }
00074 }
00075
00076 template <typename S, typename T>
00077 void
00078 do_second_projection(const Element<S, T>& src,
00079 typename projection_traits<S, T>::
00080 second_projection_t& dst)
00081 {
00082 BENCH_TASK_SCOPED("second_projection");
00083
00084
00085 typedef Element<S, T> automaton_t;
00086 typedef projection_traits<S, T> projection_traits_t;
00087 typedef typename projection_traits_t::second_projection_t res_t;
00088 AUTOMATON_TYPES(automaton_t);
00089 AUTOMATON_TYPES_(res_t, res_);
00090
00091
00092 std::map<hstate_t, res_hstate_t> m;
00093
00094
00095 for_all_const_states(p, src)
00096 m[*p] = dst.add_state();
00097
00098
00099 for_all_const_initial_states(i, src)
00100 {
00101 dst.set_initial(m[*i],
00102 projection_traits_t::
00103 series_second_projection(dst.series(),
00104 src.get_initial(*i)));
00105 }
00106
00107
00108 for_all_const_transitions(e, src)
00109 {
00110 dst.add_series_transition(m[src.src_of(*e)],
00111 m[src.dst_of(*e)],
00112 projection_traits_t::
00113 series_second_projection(dst.series(),
00114 src.series_of(*e)));
00115 }
00116
00117
00118 for_all_const_final_states(f, src)
00119 {
00120 dst.set_final(m[*f],
00121 projection_traits_t::
00122 series_second_projection(dst.series(),
00123 src.get_final(*f)));
00124 }
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 template <typename S, typename T>
00136 void
00137 first_projection(const Element<S, T>& src,
00138 typename projection_traits<S, T>::first_projection_t& dst)
00139 {
00140 do_first_projection(src, dst);
00141 }
00142
00143 template <typename S, typename T>
00144 typename projection_traits<S, T>::first_projection_t
00145 first_projection(const Element<S, T>& src)
00146 {
00147 typename projection_traits<S, T>::first_projection_t
00148 dst = projection_traits<S, T>::first_projection(src);
00149
00150 do_first_projection(src, dst);
00151
00152 return dst;
00153 }
00154
00155
00156
00157
00158
00159 template <typename S, typename T>
00160 void
00161 second_projection(const Element<S, T>& src,
00162 typename projection_traits<S, T>::
00163 second_projection_t& dst)
00164 {
00165 do_second_projection(src, dst);
00166 }
00167
00168 template <typename S, typename T>
00169 typename projection_traits<S, T>::second_projection_t
00170 second_projection(const Element<S, T>& src)
00171 {
00172 typename projection_traits<S, T>::second_projection_t
00173 dst = projection_traits<S, T>::second_projection(src);
00174
00175 do_second_projection(src, dst);
00176
00177 return dst;
00178 }
00179
00180 }
00181
00182 #endif // ! VCSN_ALGORITHMS_AUT_PROJECTION_HXX