Vaucanson 1.4
|
00001 // automata.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, 2005, 2008 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_HXX 00018 # define VCSN_AUTOMATA_CONCEPT_AUTOMATA_HXX 00019 00020 #include <vaucanson/automata/concept/automata_base.hh> 00021 #include <vaucanson/misc/unique.hh> 00022 00023 namespace vcsn { 00024 00025 template <typename Series, typename Kind> 00026 Automata<Series, Kind>::Automata(const series_set_t& s): 00027 SetSlot<Series>(s) 00028 {} 00029 00030 template <typename Series, typename Kind> 00031 const Series& 00032 Automata<Series, Kind>::series() const 00033 { 00034 return this->_structure_get(); 00035 } 00036 00037 template <typename Series, typename Kind> 00038 bool 00039 operator==(const Automata<Series, Kind>& lhs, 00040 const Automata<Series, Kind>& rhs) 00041 { 00042 return & lhs.series() == & rhs.series(); 00043 } 00044 00045 # define PROJECTION_TRAITS \ 00046 projection_traits<Automata<S, K>, T> 00047 00048 template <typename S, typename K, typename T> 00049 inline typename PROJECTION_TRAITS::first_projection_t 00050 PROJECTION_TRAITS:: 00051 first_projection(const PROJECTION_TRAITS::automaton_t& aut) 00052 { 00053 // We can not project if the type does not support it. 00054 static_assertion_(not (misc::static_eq<first_projection_t, 00055 undefined_type>::value), need_first_projection); 00056 00057 semiring_t semiring = aut.series().semiring(); 00058 alphabet_t A = aut.series().monoid().alphabet(); 00059 00060 // Project the alphabet. 00061 typename alphabet_traits_t::first_projection_t B = 00062 alphabet_traits_t::first_projection(A); 00063 00064 // Construct the monoid. 00065 typename word_traits_t::first_monoid_t freemonoid(B); 00066 00067 // Construct the series. 00068 typename first_projection_t::series_set_t series(semiring, freemonoid); 00069 00070 // Construct the automaton structure. 00071 typename first_projection_t::set_t set_t(series); 00072 00073 return first_projection_t(set_t); 00074 } 00075 00076 template <typename S, typename K, typename T> 00077 inline typename PROJECTION_TRAITS::second_projection_t 00078 PROJECTION_TRAITS:: 00079 second_projection(const PROJECTION_TRAITS::automaton_t& aut) 00080 { 00081 // We can not project if the type does not support it. 00082 static_assertion_(not (misc::static_eq<second_projection_t, 00083 undefined_type>::value), need_second_projection); 00084 00085 semiring_t semiring = aut.series().semiring(); 00086 alphabet_t A = aut.series().monoid().alphabet(); 00087 00088 // Project the alphabet. 00089 typename alphabet_traits_t::second_projection_t B = 00090 alphabet_traits_t::second_projection(A); 00091 00092 // Construct the monoid. 00093 typename word_traits_t::second_monoid_t freemonoid(B); 00094 00095 // Construct the series. 00096 typename second_projection_t::series_set_t series(semiring, freemonoid); 00097 00098 // Construct the automaton structure. 00099 typename second_projection_t::set_t set_t(series); 00100 00101 return second_projection_t(set_t); 00102 } 00103 00104 template <typename S, typename K, typename T> 00105 inline typename PROJECTION_TRAITS::series_first_projection_t 00106 PROJECTION_TRAITS:: 00107 series_first_projection(const PROJECTION_TRAITS::first_series_t& series, 00108 const PROJECTION_TRAITS::series_set_elt_t& ss) 00109 { 00110 // We can not project if the type does not support it. 00111 static_assertion_(not (misc::static_eq<first_projection_t, 00112 undefined_type>::value), need_first_projection); 00113 00114 series_first_projection_t ret(series); 00115 00116 for_all_const_(series_set_elt_t::support_t, s, ss.supp()) 00117 ret.assoc(word_traits_t::first_projection(*s), 00118 ss.get(*s)); 00119 00120 return ret; 00121 } 00122 00123 template <typename S, typename K, typename T> 00124 inline typename PROJECTION_TRAITS::series_second_projection_t 00125 PROJECTION_TRAITS:: 00126 series_second_projection(const PROJECTION_TRAITS::second_series_t& series, 00127 const PROJECTION_TRAITS::series_set_elt_t& ss) 00128 { 00129 // We can not project if the type does not support it. 00130 static_assertion_(not (misc::static_eq<second_projection_t, 00131 undefined_type>::value), need_second_projection); 00132 00133 series_second_projection_t ret(series); 00134 00135 for_all_const_(series_set_elt_t::support_t, s, ss.supp()) 00136 ret.assoc(word_traits_t::second_projection(*s), 00137 ss.get(*s)); 00138 00139 return ret; 00140 } 00141 00142 # undef PROJECTION_TRAITS 00143 00144 } // ! vcsn 00145 00146 #endif // ! VCSN_AUTOMATA_CONCEPT_AUTOMATA_HXX