automaton_maker.thxx

00001 //                                                              -*- C++ -*-
00002 // automaton_maker.thxx: this file is part of the Vaucanson project.
00003 //
00004 // Vaucanson, a generic library for finite state machines.
00005 //
00006 // Copyright (C) 2004, 2005, 2006, 2007, 2008 The Vaucanson Group.
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // The complete GNU General Public Licence Notice can be found as the
00014 // `COPYING' file in the root directory.
00015 //
00016 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00017 //
00018 
00019 /*
00020  * CPP guard should not be inserted here as
00021  * VCSN_CONTEXT_NAMESPACE could be changed.
00022  */
00023 
00024 #include <vaucanson/algorithms/aut_to_exp.hh>
00025 #include <vaucanson/algorithms/standard_of.hh>
00026 #include <vaucanson/algorithms/thompson.hh>
00027 
00028 namespace vcsn
00029 {
00030   namespace VCSN_GRAPH_IMPL
00031   {
00032     VCSN_CONTEXT_NAMESPACE
00033     {
00034 
00035       /*-----------------.
00036       | make_automaton() |
00037       `-----------------*/
00038 
00039       template <class InputIterator>
00040       automata_set_t
00041       make_automata_set(InputIterator begin,
00042                         InputIterator end)
00043       {
00044         alphabet_t              alpha;
00045         for (InputIterator e = begin; e != end; ++e)
00046           alpha.insert(*e);
00047         semiring_t              semiring;
00048         monoid_t                freemonoid (alpha);
00049         series_set_t            series (semiring, freemonoid);
00050         return automata_set_t (series);
00051       }
00052 
00053       template <class InputIterator>
00054       automaton_t
00055       make_automaton(InputIterator begin,
00056                      InputIterator end)
00057       {
00058         return automaton_t (make_automata_set(begin, end));
00059       }
00060 
00061       template <class T>
00062       automaton_t
00063       make_automaton(const T& alphabet)
00064       {
00065         return make_automaton(alphabet.begin(), alphabet.end());
00066       }
00067 
00068       template <class InputIterator>
00069       automaton_letter_t
00070       make_automaton_letter(InputIterator begin,
00071                             InputIterator end)
00072       {
00073         return automaton_letter_t (make_automata_set(begin, end));
00074       }
00075 
00076       template <class T>
00077       automaton_letter_t
00078       make_automaton_letter(const T& alphabet)
00079       {
00080         return make_automaton_letter(alphabet.begin(), alphabet.end());
00081       }
00082 
00083       template <class InputIterator>
00084       gen_automaton_t
00085       make_gen_automaton(InputIterator begin,
00086                          InputIterator end)
00087       {
00088         return gen_automaton_t (make_automata_set(begin, end));
00089       }
00090 
00091       template <class T>
00092       gen_automaton_t
00093       make_gen_automaton(const T& alphabet)
00094       {
00095         return make_gen_automaton(alphabet.begin(), alphabet.end());
00096       }
00097 
00098 
00099       /*---------------.
00100       | make_rat_exp() |
00101       `---------------*/
00102 
00103       template <class Iterator>
00104       rat_exp_t
00105       make_rat_exp(const Iterator& begin,
00106                    const Iterator& end,
00107                    const std::string& exp,
00108                    const vcsn::algebra::token_representation<typename Iterator::value_type> tok_rep = vcsn::algebra::token_representation<typename Iterator::value_type>())
00109       {
00110         alphabet_t      alphabet;
00111         for (Iterator i = begin; i != end; ++i)
00112           alphabet.insert(*i);
00113         monoid_t                monoid (alphabet);
00114         semiring_t      semiring;
00115         series_set_t    series (semiring, monoid);
00116 
00117         rat_exp_t       r (series);
00118         std::pair<bool, std::string> p = parse(exp, r, tok_rep);
00119 
00120         postcondition_ (not p.first, p.second);
00121 
00122         return r;
00123       }
00124 
00125       template <class T>
00126       rat_exp_t
00127       make_rat_exp(const T& alphabet,
00128                    const std::string& exp,
00129                    const vcsn::algebra::token_representation<typename T::letter_t> tok_rep = vcsn::algebra::token_representation<typename T::letter_t>())
00130       {
00131         return make_rat_exp(alphabet.begin(), alphabet.end(), exp, tok_rep);
00132       }
00133 
00134       /*--------------.
00135       | standard_of() |
00136       `--------------*/
00137 
00138       template <class SeriesImpl>
00139       automaton_t
00140       do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
00141       {
00142         automaton_t r = make_automaton(structure.monoid().alphabet());
00143         standard_of(r, impl);
00144         return r;
00145       }
00146 
00147       template <class SeriesSet, class SeriesImpl>
00148       automaton_t
00149       standard_of(const Element<SeriesSet, SeriesImpl>& e)
00150       {
00151         return do_standard_of(e.structure(), e.value());
00152       }
00153 
00154       /*--------------.
00155       | thompson_of() |
00156       `--------------*/
00157 
00158       template <class SeriesImpl>
00159       automaton_t
00160       do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
00161       {
00162         automaton_t r = make_automaton(structure.monoid().alphabet());
00163         thompson_of(r, impl);
00164         return r;
00165       }
00166 
00167       template <class SeriesSet, class SeriesImpl>
00168       automaton_t
00169       thompson_of(const Element<SeriesSet, SeriesImpl>& e)
00170       {
00171         return do_thompson_of(e.structure(), e.value());
00172       }
00173 
00174       /*-------------.
00175       | aut_to_exp() |
00176       `-------------*/
00177 
00178       inline
00179       rat_exp_t
00180       aut_to_exp(const automaton_t& a)
00181       {
00182         return aut_to_exp(generalized(a));
00183       }
00184 
00185       template <class Chooser>
00186       rat_exp_t
00187       aut_to_exp(const automaton_t& a, const Chooser& c)
00188       {
00189         return aut_to_exp(generalized(a), c);
00190       }
00191 
00192     } // End of VCSN_CONTEXT_NAMESPACE.
00193   } // End of VCSN_GRAPH_IMPL
00194 } // End of namespace vcsn.

Generated on Thu Oct 9 20:22:33 2008 for Vaucanson by  doxygen 1.5.1