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

- File List
- File Members

# krat_exp_realtime.hxx

    00001 // krat_exp_realtime.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, 2006, 2011 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_KRAT_EXP_REALTIME_HXX
    00018 # define VCSN_ALGORITHMS_KRAT_EXP_REALTIME_HXX
    00019
    00020 # include <vaucanson/algorithms/krat_exp_realtime.hh>
    00021
    00022 # include <vaucanson/algebra/concept/series_base.hh>
    00023 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
    00024
    00025 namespace vcsn {
    00026
    00027   namespace algebra
    00028   {
    00029     template <class Exp_,
    00030               class Dispatch_>
    00031     class KRatExpIsRealtime :
    00032       public algebra::KRatExpMatcher<
    00033       KRatExpIsRealtime<Exp_, Dispatch_>,
    00034       Exp_,
    00035       bool,
    00036       Dispatch_
    00037       >
    00038     {
    00039     public :
    00040       typedef KRatExpIsRealtime<Exp_, Dispatch_>        this_class;
    00041       typedef bool                                      return_type;
    00042       typedef typename Exp_::monoid_elt_value_t         monoid_elt_value_t;
    00043       typedef typename Exp_::semiring_elt_value_t       semiring_elt_value_t;
    00044       INHERIT_CONSTRUCTORS(this_class, Exp_, bool, Dispatch_);
    00045
    00046       MATCH__(Sum, l, r)
    00047       {
    00048         return this->match(l) and this->match(r);
    00049       }
    00050       END
    00051
    00052       MATCH__(Product, l, r)
    00053       {
    00054         return this->match(l) and this->match(r);
    00055       }
    00056       END
    00057
    00058       MATCH_(Star, e)
    00059       {
    00060         return this->match(e);
    00061       }
    00062       END
    00063
    00064       MATCH__(LeftWeight, w, e)
    00065       {
    00066         (void)w; // Avoid warning.
    00067         return this->match(e);
    00068       }
    00069       END
    00070
    00071       MATCH__(RightWeight, e, w)
    00072       {
    00073         (void)w; // Avoid warning.
    00074         return this->match(e);
    00075       }
    00076       END
    00077
    00078       MATCH_(Constant, m)
    00079       {
    00080         typename monoid_elt_value_t::const_iterator i = m.begin();
    00081         return ++i == m.end();
    00082       }
    00083       END
    00084
    00085       MATCH(Zero)
    00086       {
    00087         return true;
    00088       }
    00089       END
    00090
    00091       MATCH(One)
    00092       {
    00093         return true;
    00094       }
    00095       END
    00096     };
    00097
    00098   } // End of namespace algebra.
    00099
    00100   template <class Exp_, class S_>
    00101   bool
    00102   do_is_realtime(const algebra::SeriesBase<S_>&, const Exp_& exp)
    00103   {
    00104     typedef S_                          S;
    00105     typedef typename Exp_::value_t      T;
    00106
    00107     algebra::KRatExpIsRealtime< T, algebra::DispatchFunction<T> >
    00108       matcher;
    00109     return matcher.match(exp.value());
    00110   }
    00111
    00112
    00113   namespace algebra {
    00114
    00115     template <class Series, class T, class Dispatch>
    00116     struct KRatExpRealtime : algebra::KRatExpIdentity<
    00117       KRatExpRealtime<Series, T, Dispatch>,
    00118       Series,
    00119       T,
    00120       Dispatch
    00121       >
    00122     {
    00123       typedef KRatExpRealtime<Series, T, Dispatch>      self_t;
    00124       typedef Element<Series, T>                        return_type;
    00125       typedef typename Element<Series, T>::semiring_elt_t semiring_elt_t;
    00126       typedef typename semiring_elt_t::value_t          semiring_elt_value_t;
    00127       typedef typename Element<Series, T>::monoid_elt_t monoid_elt_t;
    00128       typedef typename monoid_elt_t::value_t            monoid_elt_value_t;
    00129       typedef typename monoid_elt_t::set_t              monoid_t;
    00130       typedef typename monoid_t::alphabet_t             alphabet_t;
    00131       typedef typename alphabet_t::letter_t             letter_t;
    00132       INHERIT_CONSTRUCTORS(self_t, T, semiring_elt_t, Dispatch);
    00133
    00134       KRatExpRealtime(const Element<Series, T>& exp) :
    00135         KRatExpIdentity<KRatExpRealtime<Series, T, Dispatch>,
    00136                         Series,
    00137                         T,
    00138                         Dispatch
    00139                         >(exp)
    00140       {}
    00141
    00142       MATCH_(Constant, m)
    00143       {
    00144         return_type     exp = identity_as<T>::of(this->exp_.structure());
    00145         return_type     tmp (this->exp_.structure());
    00146         monoid_elt_t    letter (this->exp_.structure().monoid());
    00147         for (typename monoid_elt_value_t::const_iterator i = m.begin();
    00148              i != m.end(); ++i)
    00149           {
    00150             letter = *i;
    00151             tmp = letter;
    00152             exp *= tmp;
    00153           }
    00154         return exp;
    00155       }
    00156       END
    00157     };
    00158
    00159   } // algebra
    00160
    00161
    00162   template <class Exp_, class S_>
    00163   Exp_
    00164   do_realtime(const algebra::SeriesBase<S_>&, const Exp_& exp)
    00165   {
    00166     typedef S_                          S;
    00167     typedef typename Exp_::value_t      T;
    00168
    00169     algebra::KRatExpRealtime< S, T, algebra::DispatchFunction<T> >
    00170       matcher(exp);
    00171     return matcher.match(exp.value());
    00172   }
    00173
    00174   template <class Exp_, class S_>
    00175   void
    00176   do_realtime_here(const algebra::SeriesBase<S_>&, Exp_& exp)
    00177   {
    00178     typedef S_                          S;
    00179     typedef typename Exp_::value_t      T;
    00180
    00181     algebra::KRatExpRealtime< S, T, algebra::DispatchFunction<T> >
    00182       matcher(exp);
    00183     exp = matcher.match(exp.value());
    00184   }
    00185
    00186 } // vcsn
    00187
    00188 #endif // ! VCSN_ALGORITHMS_KRAT_EXP_REALTIME_HXX