00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_STR_WORDS_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_STR_WORDS_HXX
00019
00020 # include <vaucanson/algebra/implementation/free_monoid/str_words.hh>
00021
00022 # include <vaucanson/misc/char_traits.hh>
00023
00024 namespace vcsn {
00025
00026 namespace algebra {
00027
00028 template<typename A>
00029 void
00030 op_in_mul(const algebra::FreeMonoid<A>&,
00031 std::basic_string<typename A::letter_t>& dst,
00032 const std::basic_string<typename A::letter_t>& src)
00033 {
00034 dst += src;
00035 }
00036
00037 template<typename A>
00038 std::basic_string<typename A::letter_t>
00039 op_mul(const algebra::FreeMonoid<A>&,
00040 const std::basic_string<typename A::letter_t>& a,
00041 const std::basic_string<typename A::letter_t>& b)
00042 {
00043 return a + b;
00044 }
00045
00046 template <typename A>
00047 bool
00048 op_xeq(const algebra::FreeMonoid<A>& s,
00049 const std::basic_string<typename A::letter_t>& a,
00050 const std::basic_string<typename A::letter_t>& b)
00051 {
00052 typename std::basic_string<typename A::letter_t>::const_iterator
00053 m = b.begin();
00054 typename std::basic_string<typename A::letter_t>::const_iterator l;
00055 for (l = a.begin(); m != b.end() && l != a.end(); ++l)
00056 {
00057 if (! s.alphabet().letter_equality(*l, *m))
00058 return false;
00059 ++m;
00060 }
00061 return (m == b.end() && l == a.end());
00062 }
00063
00064 template<typename A>
00065 const std::basic_string<typename A::letter_t>&
00066 identity_value(SELECTOR(algebra::FreeMonoid<A>),
00067 SELECTOR(std::basic_string<typename A::letter_t>))
00068 {
00069 static const std::basic_string<typename A::letter_t> instance;
00070 return instance;
00071 }
00072
00073 template<typename A>
00074 const std::basic_string<typename A::letter_t,
00075 misc::char_traits<typename A::letter_t> >&
00076 identity_value(SELECTOR(algebra::FreeMonoid<A>),
00077 SELECTOR2(std::basic_string<typename A::letter_t,
00078 misc::char_traits<typename A::letter_t> >))
00079 {
00080 static const std::basic_string<typename A::letter_t,
00081 misc::char_traits<typename A::letter_t> > instance;
00082 return instance;
00083 }
00084
00085 template<typename A>
00086 std::basic_string<typename A::letter_t>
00087 op_convert(SELECTOR(algebra::FreeMonoid<A>),
00088 SELECTOR(std::basic_string<typename A::letter_t>),
00089 const typename A::letter_t& c)
00090 {
00091 std::basic_string<typename A::letter_t> str;
00092 str = c;
00093 return str;
00094 }
00095
00096 template <class A>
00097 Element<algebra::FreeMonoid<A>, std::basic_string<typename A::letter_t> >
00098 op_choose(const algebra::FreeMonoid<A>& s,
00099 SELECTOR(std::basic_string<typename A::letter_t>))
00100 {
00101 unsigned length =
00102 misc::random::generate<unsigned>(0, op_choose_max_word_length);
00103 std::basic_string<typename A::letter_t> r;
00104 for (unsigned i = 0; i < length; ++i)
00105 r = r + s.alphabet().choose();
00106 return Element<algebra::FreeMonoid<A>,
00107 std::basic_string<typename A::letter_t> >(s, r);
00108 }
00109
00110 }
00111
00112 }
00113
00114 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_STR_WORDS_HXX