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, 2005, 2006, 2007 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   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<typename A>
00097     std::basic_string<typename A::letter_t>
00098     op_convert(SELECTOR(algebra::FreeMonoid<A>) mon,
00099                SELECTOR(std::basic_string<typename A::letter_t>),
00100                const std::string& str)
00101     {
00102       Element<algebra::FreeMonoid<A>, std::basic_string<typename A::letter_t> > x(mon);
00103       std::string::const_iterator i = str.begin();
00104       parse_word(x, str, i, std::set<char>());
00105       return x.value();
00106     }
00107 
00108     template<typename A>
00109     std::basic_string<typename A::letter_t>
00110     op_convert(SELECTOR(algebra::FreeMonoid<A>) M,
00111                SELECTOR(std::basic_string<typename A::letter_t>) bs,
00112                const char* str)
00113     {
00114       return op_convert(M, bs, std::string(str));
00115     }
00116 
00117     template <class A>
00118     Element<algebra::FreeMonoid<A>, std::basic_string<typename A::letter_t> >
00119     op_choose(const algebra::FreeMonoid<A>& s,
00120               SELECTOR(std::basic_string<typename A::letter_t>))
00121     {
00122       unsigned length =
00123         misc::random::generate<unsigned>(0, op_choose_max_word_length);
00124       std::basic_string<typename A::letter_t> r;
00125       for (unsigned i = 0; i < length; ++i)
00126         r = r + s.alphabet().choose();
00127       return Element<algebra::FreeMonoid<A>,
00128         std::basic_string<typename A::letter_t> >(s, r);
00129     }
00130 
00131   } // algebra
00132 
00133 } // vcsn
00134 
00135 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_FREE_MONOID_STR_WORDS_HXX

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