00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_WORDS_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_WORDS_HXX
00019
00020 # include <vaucanson/algebra/implementation/free_monoid/words.hh>
00021
00022 namespace vcsn
00023 {
00024 namespace algebra
00025 {
00026
00027
00028
00029
00030 template <class A>
00031 FreeMonoid<A>::FreeMonoid(const A& a) : alph_(a)
00032 {}
00033
00034 template <class A>
00035 FreeMonoid<A>::FreeMonoid(const FreeMonoid& w) :
00036 FreeMonoidBase<FreeMonoid<A> >(w),
00037 alph_(w.alph_)
00038 {}
00039
00040 template <class A>
00041 A& FreeMonoid<A>::alphabet()
00042 {
00043 return alph_;
00044 }
00045
00046 template <class A>
00047 const A& FreeMonoid<A>::alphabet() const
00048 {
00049 return alph_;
00050 }
00051
00052 template<typename A>
00053 bool operator==(const FreeMonoid<A>& a,
00054 const FreeMonoid<A>& b)
00055 {
00056 return a.alphabet() == b.alphabet();
00057 }
00058
00059 # define WORD_TRAITS \
00060 word_traits<FreeMonoid<A>, std::basic_string<typename A::letter_t> >
00061
00062 template <typename A>
00063 inline typename WORD_TRAITS::first_projection_value_t
00064 WORD_TRAITS::first_projection(const WORD_TRAITS::word_value_t& str)
00065 {
00066
00067 static_assertion_(not (misc::static_eq<first_projection_t,
00068 undefined_type>::value), need_first_projection)
00069
00070 first_projection_value_t R;
00071
00072
00073 for_all_const_(word_value_t, i, str)
00074 R += (*i).first;
00075
00076 return R;
00077 }
00078
00079 template <typename A>
00080 inline typename WORD_TRAITS::first_projection_t
00081 WORD_TRAITS::first_projection(const WORD_TRAITS::first_monoid_t& mon,
00082 const WORD_TRAITS::word_t& word)
00083 {
00084
00085 static_assertion_(not (misc::static_eq<first_projection_t,
00086 undefined_type>::value), need_first_projection)
00087
00088 first_projection_t R(mon);
00089
00090 R.value() = first_projection(word.value());
00091
00092 return R;
00093 }
00094
00095 template <typename A>
00096 inline typename WORD_TRAITS::second_projection_value_t
00097 WORD_TRAITS::second_projection(const WORD_TRAITS::word_value_t& str)
00098 {
00099
00100 static_assertion_(not (misc::static_eq<second_projection_t,
00101 undefined_type>::value), need_second_projection)
00102
00103 second_projection_value_t R;
00104
00105
00106 for_all_const_(word_value_t, i, str)
00107 R += (*i).second;
00108
00109 return R;
00110 }
00111
00112 template <typename A>
00113 inline typename WORD_TRAITS::second_projection_t
00114 WORD_TRAITS::second_projection(const WORD_TRAITS::second_monoid_t& mon,
00115 const WORD_TRAITS::word_t& word)
00116 {
00117
00118 static_assertion_(not (misc::static_eq<second_projection_t,
00119 undefined_type>::value), need_second_projection)
00120
00121 second_projection_t R(mon);
00122
00123 R.value() = second_projection(word.value());
00124
00125 return R;
00126 }
00127
00128 # undef WORD_TRAITS
00129
00130 }
00131
00132 }
00133
00134
00135 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_WORDS_HXX