automata_base.hh

00001 // automata_base.hh: 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 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_AUTOMATA_CONCEPT_AUTOMATA_BASE_HH
00018 # define VCSN_AUTOMATA_CONCEPT_AUTOMATA_BASE_HH
00019 
00020 # include <iterator>
00021 # include <vaucanson/design_pattern/design_pattern.hh>
00022 # include <vaucanson/automata/concept/handlers.hh>
00023 # include <vaucanson/automata/concept/delta_kind.hh>
00024 # include <vaucanson/algebra/concept/series_base.hh>
00025 
00026 namespace vcsn {
00027     
00031   /*-------------------.
00032   | AutomataBase<Self> |
00033   `-------------------*/
00035 
00039   template <typename Self>
00040   struct AutomataBase
00041     : Structure<Self>
00042   {
00043     public:
00045       typedef typename virtual_types<Self>::series_set_t  series_set_t;
00046 
00047     protected:
00049       AutomataBase();
00050 
00052       AutomataBase(const AutomataBase& other);
00053 
00054     public:
00056       const series_set_t& series() const;
00057   };
00058 
00059   // traits for automaton implementation.
00060   template <typename T>
00061   struct automaton_traits {
00062       typedef undefined_type label_t;
00063       typedef undefined_type series_set_elt_value_t;
00064       typedef undefined_type word_value_t;
00065       typedef undefined_type semiring_elt_value_t;
00066       typedef undefined_type letter_t;
00067       typedef undefined_type tag_t;
00068       typedef undefined_type states_t;
00069       typedef undefined_type state_data_t;
00070       typedef undefined_type state_iterator;
00071       typedef undefined_type transitions_t;
00072       typedef undefined_type transition_data_t;
00073       typedef undefined_type transition_iterator;
00074       typedef undefined_type initial_t;
00075       typedef undefined_type initial_iterator;
00076       typedef undefined_type initial_support_t;
00077       typedef undefined_type final_t;
00078       typedef undefined_type final_iterator;
00079       typedef undefined_type final_support_t;
00080       typedef undefined_type geometry_t;
00081   };
00082 
00083   /*-----------------------------------.
00084   | virtual_types<AutomataBase<Self> > |
00085   `-----------------------------------*/
00086   template <class S>
00087   struct virtual_types<AutomataBase<S> >
00088     : virtual_types<Structure<S> >
00089   { };
00090 
00091   /*------------------------------------.
00092   | dynamic_traits<AutomataBase<Self> > |
00093   `------------------------------------*/
00094   template <class S>
00095   struct dynamic_traits<AutomataBase<S> >
00096     : dynamic_traits<Structure<S> >
00097   { };
00098 
00099   /*-----------------------------------.
00100   | MetaElement<AutomataBase<Self>, T> |
00101   `-----------------------------------*/
00103 
00116   template <typename Self, typename T>
00117   struct MetaElement<AutomataBase<Self>, T>
00118     : MetaElement<Structure<Self>, T>
00119   {
00121       typedef MetaElement<AutomataBase<Self>, T>        self_t;
00122 
00124       typedef typename AutomataBase<Self>::series_set_t series_set_t;
00125 
00127       typedef typename automaton_traits<T>::series_set_elt_value_t
00128       series_set_elt_value_t;
00129 
00131       typedef Element<series_set_t, series_set_elt_value_t> series_set_elt_t;
00132 
00134       typedef typename series_set_t::monoid_t           monoid_t;
00135 
00137       typedef typename series_set_elt_t::monoid_elt_t   monoid_elt_t;
00138 
00140       typedef typename monoid_elt_t::value_t            monoid_elt_value_t;
00141 
00143       typedef typename monoid_t::letter_t               letter_t;
00144 
00146       typedef typename series_set_t::semiring_t         semiring_t;
00147 
00149       typedef typename series_set_elt_t::semiring_elt_t semiring_elt_t;
00150 
00152       typedef typename series_set_elt_t::semiring_elt_value_t
00153       semiring_elt_value_t;
00154 
00156       typedef typename automaton_traits<T>::tag_t               tag_t;
00157 
00159       typedef typename automaton_traits<T>::label_t     label_t;
00160 
00162       typedef typename automaton_traits<T>::states_t    states_t;
00163 
00165       typedef typename automaton_traits<T>::state_iterator state_iterator;
00166 
00168       typedef typename automaton_traits<T>::transitions_t transitions_t;
00169 
00171       typedef typename automaton_traits<T>::transition_iterator transition_iterator;
00172 
00174       typedef typename automaton_traits<T>::initial_t   initial_t;
00175 
00177       typedef typename automaton_traits<T>::initial_support_t initial_support_t;
00178 
00180       typedef typename automaton_traits<T>::initial_iterator initial_iterator;
00181 
00183       typedef typename automaton_traits<T>::final_t     final_t;
00184 
00186       typedef typename automaton_traits<T>::final_iterator final_iterator;
00187 
00189       typedef typename automaton_traits<T>::geometry_t  geometry_t;
00190 
00192       const series_set_t& series() const;
00193 
00195       tag_t& tag();
00196 
00198       const tag_t& tag() const;
00199 
00201       geometry_t& geometry();
00202 
00204       const geometry_t& geometry() const;
00205 
00207       bool exists() const;
00208 
00210       typename automaton_traits<T>::states_t
00211       states() const;
00212 
00214       typename automaton_traits<T>::transitions_t
00215       transitions() const;
00216 
00218       typename automaton_traits<T>::initial_support_t
00219       initial() const;
00220 
00222       typename automaton_traits<T>::final_support_t
00223       final() const;
00224 
00227       bool is_initial(hstate_t state) const;
00228 
00230       bool is_final(hstate_t state) const;
00231 
00233       void set_initial(hstate_t state);
00234 
00236       void set_initial(hstate_t state, const series_set_elt_t& m);
00237 
00239       void set_final(hstate_t state);
00240 
00242       void set_final(hstate_t state, const series_set_elt_t& m);
00243 
00245       void unset_initial(hstate_t state);
00246 
00248       void unset_final(hstate_t state);
00249 
00251       void clear_initial();
00252 
00254       void clear_final();
00255 
00257       Element<series_set_t, series_set_elt_value_t>
00258       get_initial(hstate_t state) const;
00259 
00261       Element<series_set_t, series_set_elt_value_t>
00262       get_final(hstate_t what) const;
00263 
00265       hstate_t add_state();
00266 
00269       hstate_t choose_state() const;
00270 
00272       htransition_t add_transition(hstate_t from, hstate_t to, const label_t& label);
00273 
00276       htransition_t add_weighted_transition(hstate_t from, hstate_t to,
00277                                             const semiring_elt_t& w,
00278                                             const monoid_elt_value_t& m);
00279 
00284       htransition_t add_series_transition(hstate_t from, hstate_t to,
00285                                           const series_set_elt_t& e);
00286 
00288       htransition_t add_spontaneous(hstate_t from, hstate_t to,
00289                                     const semiring_elt_t& w);
00290 
00291       htransition_t add_spontaneous(hstate_t from, hstate_t to);
00292 
00294       htransition_t add_letter_transition(hstate_t from, hstate_t to,
00295                                           const letter_t& l);
00296 
00298       void update(htransition_t e, const label_t& l);
00299 
00301       void del_state(hstate_t s);
00302 
00304       void del_transition(htransition_t e);
00305 
00307       bool has_state(hstate_t s) const;
00308 
00310       bool has_transition(htransition_t e) const;
00311 
00313       hstate_t src_of(htransition_t e) const;
00314 
00316       hstate_t dst_of(htransition_t e) const;
00317 
00319       typename automaton_traits<T>::label_t label_of(htransition_t e) const;
00320 
00322       series_set_elt_t series_of(htransition_t e) const;
00323 
00325       series_set_elt_value_t series_value_of(htransition_t e) const;
00326 
00328       bool is_spontaneous(htransition_t e) const;
00329 
00331       monoid_elt_t word_of(htransition_t e) const;
00332 
00334       semiring_elt_t weight_of(htransition_t e) const;
00335 
00337       monoid_elt_value_t word_value_of(htransition_t e) const;
00338 
00343       letter_t letter_of(htransition_t e) const;
00344 
00345       /*---------.
00346       | Deltas.  |
00347       `---------*/
00348 
00351       template <typename OutputIterator, typename Kind>
00352       void delta(OutputIterator res,
00353                  hstate_t from,
00354                  delta_kind::kind<Kind> k) const;
00355 
00358       template <typename OutputIterator, typename L, typename Kind>
00359       void delta(OutputIterator res,
00360                  hstate_t from,
00361                  const L& query,
00362                  delta_kind::kind<Kind> k) const;
00363 
00366       template <typename OutputIterator, typename L, typename Kind>
00367       void letter_delta(OutputIterator res,
00368                         hstate_t from,
00369                         const L& letter,
00370                         delta_kind::kind<Kind> k) const;
00371 
00374       template <typename OutputIterator, typename Kind>
00375       void spontaneous_delta(OutputIterator res,
00376                              hstate_t from,
00377                              delta_kind::kind<Kind> k) const;
00378 
00379       /*----------.
00380       | Deltacs.  |
00381       `----------*/
00382 
00385       template <typename Container, typename Kind>
00386       void deltac(Container& res, hstate_t from, delta_kind::kind<Kind> k) const;
00387 
00391       template <typename Container, typename L, typename Kind>
00392       void deltac(Container& res,
00393                   hstate_t from,
00394                   const L& query,
00395                   delta_kind::kind<Kind> k) const;
00396 
00399       template <typename Container, typename L, typename Kind>
00400       void letter_deltac(Container& res,
00401                          hstate_t from,
00402                          const L& letter,
00403                          delta_kind::kind<Kind> k) const;
00404 
00407       template <typename Container, typename Kind>
00408       void spontaneous_deltac(Container& res,
00409                               hstate_t from,
00410                               delta_kind::kind<Kind> k) const;
00411 
00412 
00413       /*----------.
00414       | Deltafs.  |
00415       `----------*/
00416 
00420       template <typename Functor, typename Kind>
00421       void deltaf(Functor& fun, hstate_t from, delta_kind::kind<Kind> k) const;
00422 
00426       template <typename Functor, typename L, typename Kind>
00427       void deltaf(Functor& fun,
00428                   hstate_t from,
00429                   const L& query,
00430                   delta_kind::kind<Kind> k) const;
00431 
00436       template <typename Functor, typename L, typename Kind>
00437       void letter_deltaf(Functor& fun,
00438                          hstate_t from,
00439                          const L& letter,
00440                          delta_kind::kind<Kind> k) const;
00441 
00446       template <typename Functor, typename Kind>
00447       void spontaneous_deltaf(Functor& fun,
00448                               hstate_t from,
00449                               delta_kind::kind<Kind> k) const;
00450 
00451       /*-----------------.
00452       | Reverse deltas.  |
00453       `-----------------*/
00454 
00457       template <typename OutputIterator, typename Kind>
00458       void rdelta(OutputIterator res,
00459                   hstate_t from,
00460                   delta_kind::kind<Kind> k) const;
00461 
00464       template <typename OutputIterator, typename L, typename Kind>
00465       void rdelta(OutputIterator res,
00466                   hstate_t from,
00467                   const L& query,
00468                   delta_kind::kind<Kind> k) const;
00469 
00472       template <typename OutputIterator, typename L, typename Kind>
00473       void letter_rdelta(OutputIterator res,
00474                          hstate_t from,
00475                          const L& letter,
00476                          delta_kind::kind<Kind> k) const;
00477 
00480       template <typename OutputIterator, typename Kind>
00481       void spontaneous_rdelta(OutputIterator res,
00482                               hstate_t from,
00483                               delta_kind::kind<Kind> k) const;
00484 
00485       /*------------------.
00486       | Reverse deltacs.  |
00487       `------------------*/
00488 
00491       template <typename Container, typename Kind>
00492       void rdeltac(Container& res, hstate_t from, delta_kind::kind<Kind> k) const;
00493 
00497       template <typename Container, typename L, typename Kind>
00498       void rdeltac(Container& res,
00499                    hstate_t from,
00500                    const L& query,
00501                    delta_kind::kind<Kind> k) const;
00502 
00505       template <typename Container, typename L, typename Kind>
00506       void letter_rdeltac(Container& res,
00507                           hstate_t from,
00508                           const L& letter,
00509                           delta_kind::kind<Kind> k) const;
00510 
00513       template <typename Container, typename Kind>
00514       void spontaneous_rdeltac(Container& res,
00515                                hstate_t from,
00516                                delta_kind::kind<Kind> k) const;
00517 
00518       /*------------------.
00519       | Reverse deltafs.  |
00520       `------------------*/
00521 
00524       template <typename Functor, typename Kind>
00525       void rdeltaf(Functor& fun, hstate_t from, delta_kind::kind<Kind> k) const;
00526 
00529       template <typename Functor, typename L, typename Kind>
00530       void rdeltaf(Functor& fun,
00531                    hstate_t from,
00532                    const L& query,
00533                    delta_kind::kind<Kind> k) const;
00534 
00537       template <typename Functor, typename L, typename Kind>
00538       void letter_rdeltaf(Functor& fun,
00539                           hstate_t from,
00540                           const L& letter,
00541                           delta_kind::kind<Kind> k) const;
00542 
00545       template <typename Functor, typename Kind>
00546       void spontaneous_rdeltaf(Functor& fun,
00547                                hstate_t from,
00548                                delta_kind::kind<Kind> k) const;
00549 
00550     protected:
00551       MetaElement();
00552       MetaElement(const MetaElement& other);
00553   };
00554 
00557   template <typename S, typename St, typename T>
00558   St& op_rout(const AutomataBase<S>& s, St& st, const T& r);
00559 
00560 } // vcsn
00561 
00562 # ifndef VCSN_USE_INTERFACE_ONLY
00563 #  include <vaucanson/automata/concept/automata_base.hxx>
00564 # endif // VCSN_USE_INTERFACE_ONLY
00565 
00566 #endif // ! VCSN_AUTOMATA_CONCEPT_AUTOMATA_BASE_HH

Generated on Sat Jul 29 17:12:58 2006 for Vaucanson by  doxygen 1.4.6