history.hxx

00001 // history.hxx: 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 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_HISTORY_HXX
00018 # define VCSN_AUTOMATA_CONCEPT_HISTORY_HXX
00019 
00020 # include <list>
00021 # include <map>
00022 
00023 # include <vaucanson/automata/concept/history.hh>
00024 
00025 namespace vcsn {
00026 
00027   namespace history {
00028 
00029     template <class T>
00030     Event<T>::Event(event_kind_t e) : kind_(e)
00031     {}
00032 
00033     template <class T>
00034     Event<T>::~Event()
00035     {}
00036 
00037     template <class T>
00038     event_kind_t
00039     Event<T>::get_event_kind() const
00040     {
00041       return kind_;
00042     }
00043 
00044     template <class T>
00045     BinaryEvent<T>::BinaryEvent(event_kind_t e, const T& first,
00046                                 const T& second) :
00047       Event<T>(e),
00048       first_(first),
00049       second_(second)
00050     {}
00051 
00052     template <class T>
00053     const T&
00054     BinaryEvent<T>::get_first() const
00055     {
00056       return first_;
00057     }
00058 
00059     template <class T>
00060     const T&
00061     BinaryEvent<T>::get_second() const
00062     {
00063       return second_;
00064     }
00065 
00066     template <class T>
00067     UnaryEvent<T>::UnaryEvent(event_kind_t e, const T& first) :
00068       Event<T>(e),
00069       first_(first)
00070     {}
00071 
00072     template <class T>
00073     const T&
00074     UnaryEvent<T>::get_first() const
00075     {
00076       return first_;
00077     }
00078 
00079     // FIXME : use std::find_if with a good function object.
00080     template <class AutoType_>
00081     bool
00082     AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
00083                                                        hstate_t s)
00084     {
00085       // FIXME: fix this code.
00086 //       for (typename state_events_t::const_iterator ev
00087 //           = states_events_[s].begin();
00088 //         ev != states_events_[s].end();
00089 //         ++ev)
00090 //      if (ev->second->get_event_kind() == e)
00091 //        return false;
00092 //       states_events_[s].push_front(new Event<hstate_t>(e));
00093       return true;
00094     }
00095 
00096     template <class AutoType_>
00097     bool
00098     AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
00099                                                        hstate_t s,
00100                                                        hstate_t first)
00101     {
00102       for (typename state_events_t::const_iterator ev
00103              = states_events_[s].begin();
00104            ev != states_events_[s].end();
00105            ++ev)
00106         if (ev->get_event_kind() == e)
00107           return false;
00108       states_events_[s].push_front(UnaryEvent<hstate_t>(e, first));
00109       return true;
00110     }
00111 
00112     template <class AutoType_>
00113     bool
00114     AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
00115                                                        hstate_t s,
00116                                                        hstate_t first,
00117                                                        hstate_t second)
00118     {
00119       for (typename state_events_t::const_iterator ev =
00120              states_events_[s].begin();
00121            ev != states_events_[s].end();
00122            ++ev)
00123         if (ev->get_event_kind() == e)
00124           return false;
00125       states_events_[s].push_front(BinaryEvent<hstate_t>
00126                                    (e, first, second));
00127       return true;
00128     }
00129 
00130     template <class AutoType_>
00131     const Event<hstate_t>
00132     AutomatonHistory<AutoType_>::get_state_event_about(event_kind_t e,
00133                                                        hstate_t     s) const
00134     {
00135       typename states_events_t::const_iterator se = states_events_.find(s);
00136       if (se == states_events_.end())
00137         return 0;
00138       for (typename state_events_t::const_iterator ev = se->second.begin();
00139            ev != se->second.end();
00140            ++ev)
00141         if (ev->get_event_kind() == e)
00142           return *ev;
00143       return 0;
00144     }
00145 
00146     template <class AutoType_>
00147     bool
00148     AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
00149                                                             htransition_t transition)
00150     {
00151       for (typename transition_events_t::const_iterator ev
00152              = transitions_events_[transition].begin();
00153            ev != transitions_events_[transition].end();
00154            ++ev)
00155         if (ev->get_event_kind() == e)
00156           return false;
00157       transitions_events_[transition].push_front(Event<htransition_t>(e));
00158       return true;
00159     }
00160 
00161     template <class AutoType_>
00162     bool
00163     AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
00164                                                             htransition_t transition,
00165                                                             htransition_t first)
00166     {
00167       for (typename transition_events_t::const_iterator ev
00168              = transitions_events_[transition].begin();
00169            ev != transitions_events_[transition].end();
00170            ++ev)
00171         if (ev->get_event_kind() == e)
00172           return false;
00173       transitions_events_[transition].push_front(UnaryEvent<htransition_t>(e, first));
00174       return true;
00175     }
00176 
00177     template <class AutoType_>
00178     bool
00179     AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
00180                                                             htransition_t transition,
00181                                                             htransition_t first,
00182                                                             htransition_t second)
00183     {
00184       for (typename transition_events_t::const_iterator ev
00185              = transitions_events_[transition].begin();
00186            ev != transitions_events_[transition].end();
00187            ++ev)
00188         if (ev->get_event_kind() == e)
00189           return false;
00190       transitions_events_[transition].push_front
00191         (BinaryEvent<htransition_t>(e, first, second));
00192       return true;
00193     }
00194 
00195     template <class AutoType_>
00196     const Event<htransition_t>
00197     AutomatonHistory<AutoType_>::get_transition_event_about(event_kind_t e,
00198                                                             htransition_t transition
00199       ) const
00200     {
00201       typename transitions_events_t::const_iterator ee =
00202         transitions_events_.find(transition);
00203       if (ee == transitions_events_.end())
00204         return 0;
00205       for (typename transition_events_t::const_iterator ev = ee->second.begin();
00206            ev != ee->second.end();
00207            ++ev)
00208         if (ev->get_event_kind() == e)
00209           return (*ev);
00210       return 0;
00211     }
00212 
00213     template <class AutoType_>
00214     bool
00215     AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e)
00216     {
00217       for (typename auto_events_t::const_iterator ev = auto_events_.begin();
00218            ev != auto_events_.end();
00219            ++ev)
00220         if (ev->second->get_event_kind() == e)
00221           return false;
00222       auto_events_.push_front(Event<AutoType_>(e));
00223       return true;
00224     }
00225 
00226     template <class AutoType_>
00227     bool
00228     AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e,
00229                                                       AutoType_ first)
00230     {
00231       for (typename auto_events_t::const_iterator ev = auto_events_.begin();
00232            ev != auto_events_.end();
00233            ++ev)
00234         if (ev->second->get_event_kind() == e)
00235           return false;
00236       auto_events_.push_front(Event<AutoType_>(e, first));
00237       return true;
00238     }
00239 
00240     template <class AutoType_>
00241     bool
00242     AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e,
00243                                                       AutoType_ first,
00244                                                       AutoType_ second)
00245     {
00246       for (typename auto_events_t::const_iterator ev = auto_events_.begin();
00247            ev != auto_events_.end();
00248            ++ev)
00249         if (ev->get_event_kind() == e)
00250           return false;
00251       auto_events_.push_front(BinaryEvent<AutoType_>(e, first, second));
00252       return true;
00253     }
00254 
00255     template <class AutoType_>
00256     const Event<AutoType_>
00257     AutomatonHistory<AutoType_>::get_auto_event_about(event_kind_t e) const
00258     {
00259       for (typename auto_events_t::const_iterator ev = auto_events_.begin();
00260            ev != auto_events_.end();
00261            ++ev)
00262         if (ev->get_event_kind() == e)
00263           return (*ev);
00264       return 0;
00265     }
00266 
00267     template <class T>
00268     std::ostream&
00269     operator<<(std::ostream& out, const Event<T>& e)
00270     {
00271       out << e.get_event_kind();
00272       return out;
00273     }
00274 
00275 
00276   } // history
00277 
00278 } // vcsn
00279 
00280 #endif // ! VCSN_AUTOMATA_CONCEPT_HISTORY_HXX

Generated on Sat Jul 29 17:13:00 2006 for Vaucanson by  doxygen 1.4.6