- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# partial_rat_exp_constant_term.hxx

    00001 // partial_rat_exp_constant_term.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005 The Vaucanson Group.
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License
    00009 // as published by the Free Software Foundation; either version 2
    00010 // of the License, or (at your option) any later version.
    00011 //
    00012 // The complete GNU General Public Licence Notice can be found as the
    00013 // `COPYING' file in the root directory.
    00014 //
    00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
    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 } // vcsn
    00058
    00059 #endif // ! VCSN_ALGORITHMS_INTERNAL_PARTIAL_RAT_EXP_CONSTANT_TERM_HXX