words.hxx

00001 // words.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_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     | Words<A> |
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       // We can not project if the type does not support it.
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       // We assume we can access the first projection with "first".
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       // We can not project if the type does not support it.
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       // We can not project if the type does not support it.
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       // We assume we can access the second projection with "second".
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       // We can not project if the type does not support it.
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   } // ! algebra
00131 
00132 } // ! vcsn
00133 
00134 
00135 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_WORDS_HXX

Generated on Thu Oct 9 20:22:42 2008 for Vaucanson by  doxygen 1.5.1