00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #ifndef VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HH
00018 # define VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HH
00019 
00020 # include <map>
00021 # include <vaucanson/automata/concept/automata_base.hh>
00022 # include <vaucanson/algorithms/standard.hh>
00023 # include <vaucanson/misc/usual_macros.hh>
00024 
00025 namespace vcsn {
00026   namespace algorithm_patterns
00027   {
00028 
00029     
00030     
00031     template <typename Self, typename Etiq>
00032     struct Comparator
00033     {
00034       bool operator()(const Etiq& e1, const Etiq& e2) const;
00035     };
00036 
00037     
00038 
00039 
00040 
00041     
00042     
00043     
00044     
00045     
00046     
00047     
00048     template <typename Self, typename T_auto, typename Etiq>
00049     class IncAutomataConstructor
00050     {
00051     public:
00052       
00053       typedef T_auto*                                           T_auto_p;
00054       AUTOMATON_TYPES(T_auto);
00055       AUTOMATON_FREEMONOID_TYPES(T_auto);
00056       
00057       
00058       
00059       typedef
00060       std::pair<hstate_t, bool>                                 StateMarked;
00061       typedef
00062       std::map<Etiq, StateMarked, Comparator<Self, Etiq> >      StateMap;
00063       typedef typename StateMap::iterator                       iterator;
00064 
00065       
00066       void      run();
00067       
00068       T_auto_p  get() const;
00069       
00070       
00071       static bool compare(const Etiq& e1, const Etiq& e2);
00072     protected:
00073       
00074       IncAutomataConstructor(const series_set_t& series, const Etiq& etiq);
00075       IncAutomataConstructor(const series_set_t& series,
00076                              const std::list<Etiq>& listexp);
00077       
00078       void      link_to(const Etiq& etiq, const letter_t& l);
00079       void      link_to(const Etiq& etiq, const series_set_elt_t& el);
00080       
00081       void      set_final();
00082       void      set_final(const series_set_elt_t& el);
00083     private:
00084       
00085       void on_state_caller(const Etiq& e);
00086       
00087       hstate_t  add_state(const Etiq& etiq);
00088       
00089       int                               unvisited;
00090       T_auto_p                          auto_p;
00091       StateMap                          states_map;
00092       iterator                          current_state;
00093     };
00094 
00095     
00096 
00097 
00098 
00099     
00100     
00101     
00102     
00103     
00104     
00105     
00106     template <typename Self, typename T_auto, typename Etiq>
00107     class MathAutomataConstructor
00108     {
00109     public:
00110       
00111       AUTOMATON_TYPES(T_auto);
00112       AUTOMATON_FREEMONOID_TYPES(T_auto);
00113       typedef T_auto*                                           T_auto_p;
00114       typedef std::map<Etiq, hstate_t, Comparator<Self, Etiq> > StateMap;
00115       typedef typename StateMap::iterator                       iterator;
00116 
00117       
00118       void      run();
00119       
00120       T_auto_p  get() const;
00121       
00122       
00123       static bool compare(const Etiq& e1, const Etiq& e2);
00124     protected:
00125       
00126       template <typename Container>
00127       MathAutomataConstructor(const series_set_t& series,
00128                               const Container container);
00129     private:
00130       
00131       bool is_initial_caller(const Etiq& e) const;
00132       bool is_final_caller(const Etiq& e) const;
00133       
00134       template <typename Container>
00135       void link_to(const hstate_t& state,
00136                    const letter_t& letter,
00137                    const Container container);
00138       
00139       T_auto_p                          auto_p;
00140       StateMap                          states_map;
00141     };
00142 
00143   }
00144 }
00145 
00146 
00147 # if !defined VCSN_USE_INTERFACE_ONLY && !defined VCSN_USE_LIB
00148 #include <vaucanson/algorithms/internal/build_pattern.hxx>
00149 #endif // VCSN_USE_INTERFACE_ONLY
00150 
00151 
00152 #endif // ! VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HH