Vaucanson 1.4
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, 2009, 2011 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       | make_automaton() |
00036       `-----------------*/
00037 
00038       template <class InputIterator>
00039       automata_set_t
00040       make_automata_set(InputIterator begin,
00041                         InputIterator end)
00042       {
00043         alphabet_t alpha;
00044 
00045         for (InputIterator e = begin; e != end; ++e)
00046           alpha.insert(*e);
00047 
00048         semiring_t      semiring;
00049         monoid_t        freemonoid(alpha);
00050         series_set_t    series(semiring, freemonoid);
00051 
00052         return automata_set_t(series);
00053       }
00054 
00055       template <class InputIterator>
00056       automata_set_t
00057       make_automata_set(InputIterator begin,
00058                         InputIterator end,
00059                         const monoid_rep_t& mrep,
00060                         const series_rep_t& srep)
00061       {
00062         alphabet_t alpha;
00063 
00064         for (InputIterator e = begin; e != end; ++e)
00065           alpha.insert(*e);
00066 
00067         semiring_t      semiring;
00068         monoid_t        freemonoid(alpha, mrep);
00069         series_set_t    series(semiring, freemonoid, srep);
00070         return automata_set_t(series);
00071       }
00072 
00073       template <class InputIterator>
00074       automaton_t
00075       make_automaton(InputIterator begin,
00076                      InputIterator end)
00077       {
00078         return automaton_t(make_automata_set(begin, end));
00079       }
00080 
00081       template <class InputIterator>
00082       automaton_t
00083       make_automaton(InputIterator begin,
00084                      InputIterator end,
00085                      const monoid_rep_t& mrep,
00086                      const series_rep_t& srep)
00087       {
00088         return automaton_t(make_automata_set(begin, end, mrep, srep));
00089       }
00090 
00091       template <class T>
00092       automaton_t
00093       make_automaton(const T& alphabet)
00094       {
00095         return make_automaton(alphabet.begin(), alphabet.end());
00096       }
00097 
00098       template <class T>
00099       automaton_t
00100       make_automaton(const T& alphabet,
00101                      const monoid_rep_t& mrep,
00102                      const series_rep_t& srep)
00103       {
00104         return make_automaton(alphabet.begin(), alphabet.end(), mrep, srep);
00105       }
00106 
00107       template <class InputIterator>
00108       automaton_letter_t
00109       make_automaton_letter(InputIterator begin,
00110                             InputIterator end)
00111       {
00112         return automaton_letter_t (make_automata_set(begin, end));
00113       }
00114 
00115       template <class T>
00116       automaton_letter_t
00117       make_automaton_letter(const T& alphabet)
00118       {
00119         return make_automaton_letter(alphabet.begin(), alphabet.end());
00120       }
00121 
00122       template <class InputIterator>
00123       gen_automaton_t
00124       make_gen_automaton(InputIterator begin,
00125                          InputIterator end)
00126       {
00127         return gen_automaton_t (make_automata_set(begin, end));
00128       }
00129 
00130       template <class T>
00131       gen_automaton_t
00132       make_gen_automaton(const T& alphabet)
00133       {
00134         return make_gen_automaton(alphabet.begin(), alphabet.end());
00135       }
00136 
00137       /*---------------.
00138       | make_rat_exp() |
00139       `---------------*/
00140 
00141       template <class Iterator>
00142       rat_exp_t
00143       make_rat_exp(const Iterator& begin,
00144                    const Iterator& end,
00145                    const std::string& exp,
00146                    const monoid_rep_t& mrep,
00147                    const series_rep_t& srep)
00148       {
00149         alphabet_t      alphabet;
00150         for (Iterator i = begin; i != end; ++i)
00151           alphabet.insert(*i);
00152         monoid_t        monoid (alphabet, mrep);
00153         semiring_t      semiring;
00154         series_set_t    series (semiring, monoid, srep);
00155 
00156         rat_exp_t       r (series);
00157         std::pair<bool, std::string> p = parse(exp, r);
00158 
00159         postcondition_ (not p.first, p.second);
00160 
00161         return r;
00162       }
00163 
00164       template <class T>
00165       rat_exp_t
00166       make_rat_exp(const T& alphabet,
00167                    const std::string& exp,
00168                    const monoid_rep_t& mrep,
00169                    const series_rep_t& srep)
00170       {
00171         return make_rat_exp(alphabet.begin(), alphabet.end(),
00172                             exp, mrep, srep);
00173       }
00174 
00175       /*--------------.
00176       | standard_of() |
00177       `--------------*/
00178 
00179       template <class SeriesImpl>
00180       automaton_t
00181       do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
00182       {
00183         automaton_t r = make_automaton(structure.monoid().alphabet(),
00184                                        *structure.monoid().representation(),
00185                                        *structure.representation());
00186         standard_of(r, impl);
00187         return r;
00188       }
00189 
00190       template <class SeriesSet, class SeriesImpl>
00191       automaton_t
00192       standard_of(const Element<SeriesSet, SeriesImpl>& e)
00193       {
00194         return do_standard_of(e.structure(), e.value());
00195       }
00196 
00197       /*--------------.
00198       | thompson_of() |
00199       `--------------*/
00200 
00201       template <class SeriesImpl>
00202       automaton_t
00203       do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
00204       {
00205         automaton_t r = make_automaton(structure.monoid().alphabet(),
00206                                        *structure.monoid().representation(),
00207                                        *structure.representation());
00208         thompson_of(r, impl);
00209         return r;
00210       }
00211 
00212       template <class SeriesSet, class SeriesImpl>
00213       automaton_t
00214       thompson_of(const Element<SeriesSet, SeriesImpl>& e)
00215       {
00216         return do_thompson_of(e.structure(), e.value());
00217       }
00218 
00219       /*-------------.
00220       | aut_to_exp() |
00221       `-------------*/
00222 
00223       inline
00224       rat_exp_t
00225       aut_to_exp(const automaton_t& a)
00226       {
00227         return aut_to_exp(generalized(a));
00228       }
00229 
00230       template <class Chooser>
00231       rat_exp_t
00232       aut_to_exp(const automaton_t& a, const Chooser& c)
00233       {
00234         return aut_to_exp(generalized(a), c);
00235       }
00236 
00237     } // End of VCSN_CONTEXT_NAMESPACE.
00238   } // End of VCSN_GRAPH_IMPL
00239 } // End of namespace vcsn.