00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_CONSTANT_TERM_HXX
00018 # define VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_CONSTANT_TERM_HXX
00019
00020 # include <utility>
00021 # include <vaucanson/algorithms/internal/partial_rat_exp_constant_term.hh>
00022 # include <vaucanson/algorithms/krat_exp_constant_term.hh>
00023
00024 namespace vcsn {
00025
00026 template <class Series, class T>
00027 std::pair<typename Element<Series, T>::semiring_elt_t, bool>
00028 constant_term(const PartialExp<Series, T>& exp)
00029 {
00030 typedef typename PartialExp<Series, T>::const_iterator const_iterator;
00031 typedef typename PartialExp<Series, T>::semiring_elt_t semiring_elt_t;
00032 typedef typename PartialExp<Series, T>::series_set_elt_value_t
00033 series_set_elt_value_t;
00034 typedef std::pair<typename Element<Series, T>::semiring_elt_t, bool>
00035 result_t;
00036
00037 const_iterator i = exp.begin();
00038 semiring_elt_t res = i.semiring_elt();
00039 bool defined = true;
00040
00041 for (i++; i != exp.end() && defined; ++i)
00042 {
00043 if (i.on_node())
00044 {
00045 result_t tmp = constant_term(
00046 Element<Series, T>(exp.exp_structure(),
00047 series_set_elt_value_t (i.node())));
00048 defined = tmp.second;
00049 res *= tmp.first;
00050 }
00051 else
00052 res *= i.semiring_elt();
00053 }
00054 return std::make_pair(res, defined);
00055 }
00056
00057 }
00058
00059 #endif // ! VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_CONSTANT_TERM_HXX