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 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/krat_exp_expand.hh>
00025 #include <vaucanson/algorithms/aut_to_exp.hh>
00026 #include <vaucanson/algorithms/standard_of.hh>
00027 #include <vaucanson/algorithms/thompson.hh>
00028 
00029 namespace vcsn
00030 {
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     gen_automaton_t 
00070     make_gen_automaton(InputIterator begin,
00071                        InputIterator end)
00072     {
00073       return gen_automaton_t (make_automata_set(begin, end));
00074     }
00075 
00076     template <class T>
00077     gen_automaton_t 
00078     make_gen_automaton(const T& alphabet)
00079     {
00080       return make_gen_automaton(alphabet.begin(), alphabet.end());
00081     }
00082 
00083 
00084     /*---------------.
00085     | make_rat_exp() |
00086     `---------------*/
00087 
00088     template <class Iterator>
00089     rat_exp_t 
00090     make_rat_exp(const Iterator& begin,
00091                  const Iterator& end,
00092                  const std::string& exp)
00093     {
00094       alphabet_t        alphabet;
00095       for (Iterator i = begin; i != end; ++i)
00096         alphabet.insert(*i);
00097       monoid_t          monoid (alphabet);
00098       semiring_t        semiring;
00099       series_set_t      series (semiring, monoid);
00100 
00101       rat_exp_t r (series);
00102       std::pair<bool, std::string> p = parse(exp, r);
00103 
00104       postcondition_ (not p.first, p.second);
00105 
00106       return r;
00107     }
00108 
00109     template <class T>
00110     rat_exp_t 
00111     make_rat_exp(const T& alphabet, const std::string& exp)
00112     {
00113       return make_rat_exp(alphabet.begin(), alphabet.end(), exp);
00114     }
00115 
00116     /*--------------.
00117     | standard_of() |
00118     `--------------*/
00119 
00120     template <class SeriesImpl>
00121     automaton_t
00122     do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
00123     {
00124       automaton_t r = make_automaton(structure.monoid().alphabet());
00125       standard_of(r, impl);
00126       return r;
00127     }
00128 
00129     template <class SeriesSet, class SeriesImpl>
00130     automaton_t
00131     standard_of(const Element<SeriesSet, SeriesImpl>& e)
00132     {
00133       return do_standard_of(e.structure(), e.value());
00134     }
00135 
00136     /*--------------.
00137     | thompson_of() |
00138     `--------------*/
00139 
00140     template <class SeriesImpl>
00141     automaton_t
00142     do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
00143     {
00144       automaton_t r = make_automaton(structure.monoid().alphabet());
00145       thompson_of(r, impl);
00146       return r;
00147     }
00148 
00149     template <class SeriesSet, class SeriesImpl>
00150     automaton_t
00151     thompson_of(const Element<SeriesSet, SeriesImpl>& e)
00152     {
00153       return do_thompson_of(e.structure(), e.value());
00154     }
00155 
00156     /*-------------.
00157     | aut_to_exp() |
00158     `-------------*/
00159 
00160     inline
00161     rat_exp_t
00162     aut_to_exp(const automaton_t& a)
00163     {
00164       return aut_to_exp(generalized(a));
00165     }
00166 
00167     template <class Chooser>
00168     rat_exp_t
00169     aut_to_exp(const automaton_t& a, const Chooser& c)
00170     {
00171       return aut_to_exp(generalized(a), c);
00172     }
00173 
00174   } // End of VCSN_CONTEXT_NAMESPACE.
00175 
00176 } // End of namespace vcsn.

Generated on Sun Jul 29 19:35:17 2007 for Vaucanson by  doxygen 1.5.2