automaton_functions.thxx

00001 //                                                              -*- C++ -*-
00002 // automaton_functions.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 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 
00024 namespace vcsn
00025 {
00026 
00027   namespace VCSN_CONTEXT_NAMESPACE
00028   {
00029 
00030     /*-----------------.
00031     | make_automaton() |
00032     `-----------------*/
00033 
00034     template <class InputIterator>
00035     automata_set_t make_automata_set(InputIterator begin,
00036                                      InputIterator end)
00037     {
00038       alphabet_t                alpha;
00039       for (InputIterator e = begin; e != end; ++e)
00040         alpha.insert(*e);
00041       semiring_t                semiring;
00042       monoid_t                  freemonoid (alpha);
00043       series_set_t              series (semiring, freemonoid);
00044       return automata_set_t (series);
00045     }
00046 
00047     template <class InputIterator>
00048     automaton_t make_automaton(InputIterator begin,
00049                                InputIterator end)
00050     {
00051       return automaton_t (make_automata_set(begin, end));
00052     }
00053 
00054     template <class T>
00055     automaton_t make_automaton(const T& alphabet)
00056     {
00057       return make_automaton(alphabet.begin(), alphabet.end());
00058     }
00059 
00060     template <class InputIterator>
00061     gen_automaton_t make_gen_automaton(InputIterator begin,
00062                                        InputIterator end)
00063     {
00064       return gen_automaton_t (make_automata_set(begin, end));
00065     }
00066 
00067     template <class T>
00068     gen_automaton_t make_gen_automaton(const T& alphabet)
00069     {
00070       return make_gen_automaton(alphabet.begin(), alphabet.end());
00071     }
00072 
00073 
00074     /*---------------.
00075     | make_rat_exp() |
00076     `---------------*/
00077 
00078     template <class Iterator>
00079     rat_exp_t make_rat_exp(const Iterator& begin,
00080                            const Iterator& end,
00081                            const std::string& exp)
00082     {
00083       alphabet_t        alphabet;
00084       for (Iterator i = begin; i != end; ++i)
00085         alphabet.insert(*i);
00086       monoid_t          monoid (alphabet);
00087       semiring_t        semiring;
00088       series_set_t      series (semiring, monoid);
00089 
00090       rat_exp_t r (series);
00091       std::pair<bool, std::string> p = parse(exp, r);
00092 
00093       postcondition_ (not p.first, p.second);
00094 
00095       return r;
00096     }
00097 
00098     template <class T>
00099     rat_exp_t make_rat_exp(const T& alphabet, const std::string& exp)
00100     {
00101       return make_rat_exp(alphabet.begin(), alphabet.end(), exp);
00102     }
00103 
00104     /*--------------.
00105     | standard_of() |
00106     `--------------*/
00107 
00108     template <class SeriesImpl>
00109     automaton_t
00110     do_standard_of(const series_set_t& structure, const SeriesImpl& impl)
00111     {
00112       automaton_t r = make_automaton(structure.monoid().alphabet());
00113       standard_of(r, impl);
00114       return r;
00115     }
00116 
00117     template <class SeriesSet, class SeriesImpl>
00118     automaton_t
00119     standard_of(const Element<SeriesSet, SeriesImpl>& e)
00120     {
00121       return do_standard_of(e.structure(), e.value());
00122     }
00123 
00124     /*--------------.
00125     | thompson_of() |
00126     `--------------*/
00127 
00128     template <class SeriesImpl>
00129     automaton_t
00130     do_thompson_of(const series_set_t& structure, const SeriesImpl& impl)
00131     {
00132       automaton_t r = make_automaton(structure.monoid().alphabet());
00133       thompson_of(r, impl);
00134       return r;
00135     }
00136 
00137     template <class SeriesSet, class SeriesImpl>
00138     automaton_t
00139     thompson_of(const Element<SeriesSet, SeriesImpl>& e)
00140     {
00141       return do_thompson_of(e.structure(), e.value());
00142     }
00143 
00144     /*-------------.
00145     | aut_to_exp() |
00146     `-------------*/
00147 
00148     inline
00149     rat_exp_t
00150     aut_to_exp(const automaton_t& a)
00151     {
00152       return aut_to_exp(generalized(a));
00153     }
00154 
00155     template <class Chooser>
00156     rat_exp_t
00157     aut_to_exp(const automaton_t& a, const Chooser& c)
00158     {
00159       return aut_to_exp(generalized(a), c);
00160     }
00161 
00162   } // End of namespace VCSN_CONTEXT_NAMESPACE.
00163 
00164 } // End of namespace vcsn.

Generated on Fri Jul 28 12:18:29 2006 for Vaucanson by  doxygen 1.4.6