Vaucanson 1.4
|
00001 // pair_str_words.hxx: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2004, 2005, 2007, 2008, 2010 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_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX 00018 # define VCSN_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX 00019 00020 # include <vaucanson/algebra/implementation/monoid/pair_str_words.hh> 00021 00022 namespace vcsn { 00023 00024 namespace algebra { 00025 00026 template <class Self, typename T> 00027 typename 00028 MetaElement<algebra::FreeMonoidProductBase<Self>, T>::first_monoid_elt_t 00029 op_first(const algebra::FreeMonoidProductBase<Self>& s, T& v) 00030 { 00031 return Element<typename virtual_types<Self>::first_monoid_t, 00032 typename T::first_type> (s.first_monoid(), v.first); 00033 } 00034 00035 template <class Self, typename T> 00036 typename 00037 MetaElement<algebra::FreeMonoidProductBase<Self>, T>::second_monoid_elt_t 00038 op_second(const algebra::FreeMonoidProductBase<Self>& s, T& v) 00039 { 00040 return Element<typename virtual_types<Self>::second_monoid_t, 00041 typename T::second_type> (s.second_monoid(), v.second); 00042 } 00043 00044 template <class F, class S> 00045 void 00046 op_in_mul(const algebra::FreeMonoidProduct<F, S>& s, 00047 std::pair<std::basic_string<typename F::letter_t>, 00048 std::basic_string<typename S::letter_t> >& dst, 00049 const std::pair<std::basic_string<typename F::letter_t>, 00050 std::basic_string<typename S::letter_t> >& src) 00051 { 00052 dst.first += src.first; 00053 dst.second += src.second; 00054 } 00055 00056 template<class F, class S> 00057 std::pair<std::basic_string<typename F::letter_t>, 00058 std::basic_string<typename S::letter_t> > 00059 op_mul(const algebra::FreeMonoidProduct<F, S>&, 00060 const std::pair<std::basic_string<typename F::letter_t>, 00061 std::basic_string<typename S::letter_t> >& a, 00062 const std::pair<std::basic_string<typename F::letter_t>, 00063 std::basic_string<typename S::letter_t> >& b) 00064 { 00065 return std::pair< std::basic_string<typename F::letter_t>, 00066 std::basic_string<typename S::letter_t> > 00067 (a.first + b.first, a.second + b.second); 00068 } 00069 00070 template<class F, class S> 00071 const std::pair<std::basic_string<typename F::letter_t>, 00072 std::basic_string<typename S::letter_t> > 00073 identity_value(SELECTOR2(algebra::FreeMonoidProduct<F, S>), 00074 SELECTOR2(std::pair<std::basic_string<typename F::letter_t>, 00075 std::basic_string<typename S::letter_t> >)) 00076 { 00077 static const std::pair<std::basic_string<typename F::letter_t>, 00078 std::basic_string<typename S::letter_t> > 00079 instance; 00080 return instance; 00081 } 00082 00083 template <class F, class S> 00084 Element<algebra::FreeMonoidProduct<F, S>, 00085 std::pair<std::basic_string<typename F::letter_t>, 00086 std::basic_string<typename S::letter_t> > > 00087 op_choose(const algebra::FreeMonoidProduct<F, S>& s, 00088 SELECTOR2(std::pair<std::basic_string<typename F::letter_t>, 00089 std::basic_string<typename S::letter_t> >)) 00090 { 00091 typedef std::basic_string<typename F::letter_t> T1; 00092 typedef std::basic_string<typename S::letter_t> T2; 00093 00094 std::pair< T1, T2 > res(s.first_monoid().choose(SELECT(T1)).value(), 00095 s.second_monoid().choose(SELECT(T2)).value()); 00096 00097 return Element<algebra::FreeMonoidProduct<F, S>, 00098 std::pair< T1, T2 > > (s, res); 00099 } 00100 00101 template<typename Self, typename T> 00102 void 00103 op_in_mirror(const algebra::FreeMonoidProductBase<Self>& s, T& v) 00104 { 00105 op_in_mirror(s.first_monoid(), v.first); 00106 op_in_mirror(s.second_monoid(), v.second); 00107 } 00108 00109 template<typename Self, typename T, typename Ftor> 00110 typename Ftor::result_type 00111 op_length(const algebra::FreeMonoidProductBase<Self>&, const T& v, Ftor f) 00112 { 00113 return f(v.first.length(), v.second.length()); 00114 } 00115 00116 template<typename F, typename S, 00117 typename A1, typename A2, typename A3, typename A4> 00118 bool 00119 op_is_atom(const algebra::FreeMonoidProduct<F, S>&, 00120 const std::pair<std::basic_string<typename F::letter_t, A1, A2>, 00121 std::basic_string<typename S::letter_t, A3, A4> 00122 >& v) 00123 { 00124 return (v.first.length() <= 1) && (v.second.length() <= 1); 00125 } 00126 00127 template <typename F, typename S, typename St> 00128 St& 00129 op_rout(const FreeMonoidProduct<F, S>& s, 00130 St& st, 00131 const std::pair<std::basic_string<typename F::letter_t>, 00132 std::basic_string<typename S::letter_t> >& v) 00133 { 00134 if (v.first.empty() && v.second.empty()) 00135 st << s.representation()->empty; 00136 else 00137 { 00138 st << s.representation()->open_par; 00139 op_rout(s.first_monoid(), st, v.first); 00140 st << s.representation()->sep; 00141 op_rout(s.second_monoid(), st, v.second); 00142 st << s.representation()->close_par; 00143 } 00144 00145 return st; 00146 } 00147 00148 } // ! algebra 00149 00150 } // ! vcsn 00151 00152 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX