str_words.hxx

00001 // 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) 2001, 2002, 2003, 2004 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_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   template<typename A>
00027   void
00028   op_in_mul(const algebra::FreeMonoid<A>&,
00029             std::basic_string<typename A::letter_t>& dst,
00030             const std::basic_string<typename A::letter_t>& src)
00031   {
00032     dst += src;
00033   }
00034 
00035   template<typename A>
00036   std::basic_string<typename A::letter_t>
00037   op_mul(const algebra::FreeMonoid<A>&,
00038          const std::basic_string<typename A::letter_t>& a,
00039          const std::basic_string<typename A::letter_t>& b)
00040   {
00041     return a + b;
00042   }
00043 
00044   template <typename A>
00045   bool
00046   op_xeq(const algebra::FreeMonoid<A>& s,
00047          const std::basic_string<typename A::letter_t>& a,
00048          const std::basic_string<typename A::letter_t>& b)
00049   {
00050     typename std::basic_string<typename A::letter_t>::const_iterator
00051       m = b.begin();
00052     typename std::basic_string<typename A::letter_t>::const_iterator l;
00053     for (l = a.begin(); m != b.end() && l != a.end(); ++l)
00054       {
00055         if (! s.alphabet().letter_equality(*l, *m))
00056           return false;
00057         ++m;
00058       }
00059     return (m == b.end() && l == a.end());
00060   }
00061 
00062   template<typename A>
00063   const std::basic_string<typename A::letter_t>&
00064   identity_value(SELECTOR(algebra::FreeMonoid<A>),
00065                  SELECTOR(std::basic_string<typename A::letter_t>))
00066   {
00067     static const std::basic_string<typename A::letter_t> instance;
00068     return instance;
00069   }
00070 
00071   template<typename A>
00072   const std::basic_string<typename A::letter_t,
00073                           misc::char_traits<typename A::letter_t> >&
00074   identity_value(SELECTOR(algebra::FreeMonoid<A>),
00075                  SELECTOR2(std::basic_string<typename A::letter_t,
00076                           misc::char_traits<typename A::letter_t> >))
00077   {
00078     static const std::basic_string<typename A::letter_t,
00079       misc::char_traits<typename A::letter_t> > instance;
00080     return instance;
00081   }
00082 
00083   template<typename A>
00084   std::basic_string<typename A::letter_t>
00085   op_convert(SELECTOR(algebra::FreeMonoid<A>),
00086              SELECTOR(std::basic_string<typename A::letter_t>),
00087              const typename A::letter_t& c)
00088   {
00089     std::basic_string<typename A::letter_t> str;
00090     str = c;
00091     return str;
00092   }
00093 
00094   template <class A>
00095   Element<algebra::FreeMonoid<A>, std::basic_string<typename A::letter_t> >
00096   op_choose(const algebra::FreeMonoid<A>& s,
00097             SELECTOR(std::basic_string<typename A::letter_t>))
00098   {
00099     unsigned length =
00100       misc::random::generate<unsigned>(0, op_choose_max_word_length);
00101     std::basic_string<typename A::letter_t> r;
00102     for (unsigned i = 0; i < length; ++i)
00103       r = r + s.alphabet().choose();
00104     return Element<algebra::FreeMonoid<A>,
00105       std::basic_string<typename A::letter_t> >(s, r);
00106   }
00107 
00108 } // vcsn
00109 
00110 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_STR_WORDS_HXX

Generated on Sat Jul 29 17:13:11 2006 for Vaucanson by  doxygen 1.4.6