18 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_MONOID_STR_WORDS_HXX
19 # define VCSN_ALGEBRA_IMPLEMENTATION_MONOID_STR_WORDS_HXX
21 # include <vaucanson/algebra/implementation/monoid/str_words.hh>
32 std::basic_string<typename A::letter_t>& v,
33 const std::string& in)
36 return std::make_pair(
true, 0);
38 std::string& empty = s.representation()->empty;
39 int empty_size = empty.size();
40 std::string& concat = s.representation()->concat;
41 int concat_size = concat.size();
42 bool last_token_is_letter =
false;
45 for (i = 0; i < in.size();)
48 if ((concat_size > 0) && !in.compare(i, concat_size, concat))
50 if (!last_token_is_letter)
51 return std::make_pair(
false, i);
53 last_token_is_letter =
false;
63 if (!in.compare(i, empty_size, empty))
66 last_token_is_letter =
true;
72 std::pair<bool, typename A::letter_t> letter =
73 op_parse(s.alphabet().structure(), s.alphabet().value(), in, i);
75 return std::make_pair(
false, i);
76 v.push_back(letter.second);
77 last_token_is_letter =
true;
79 return std::make_pair(last_token_is_letter, i);
84 op_in_mul(
const algebra::FreeMonoid<A>&,
85 std::basic_string<typename A::letter_t>& dst,
86 const std::basic_string<typename A::letter_t>& src)
92 std::basic_string<typename A::letter_t>
93 op_mul(
const algebra::FreeMonoid<A>&,
94 const std::basic_string<typename A::letter_t>& a,
95 const std::basic_string<typename A::letter_t>& b)
100 template<
typename A,
typename St,
typename U,
typename V>
102 op_rout(
const FreeMonoid<A>& s,
104 const std::basic_string<typename A::letter_t, U, V>& v)
107 st << s.representation()->empty;
111 typedef typename A::letter_t letter_t;
112 typedef algebra::letter_traits<letter_t> letter_traits_t;
113 typedef typename std::basic_string<letter_t, U, V>::const_iterator
116 iter_t i = v.begin();
119 st << letter_traits_t::letter_to_literal(*i);
125 st << s.representation()->concat
126 << letter_traits_t::letter_to_literal(*i);
134 template <
typename A>
136 op_xeq(
const algebra::FreeMonoid<A>& s,
137 const std::basic_string<typename A::letter_t>& a,
138 const std::basic_string<typename A::letter_t>& b)
140 typename std::basic_string<typename A::letter_t>::const_iterator
142 typename std::basic_string<typename A::letter_t>::const_iterator l;
143 for (l = a.begin(); m != b.end() && l != a.end(); ++l)
145 if (! s.alphabet().letter_equality(*l, *m))
149 return (m == b.end() && l == a.end());
153 const std::basic_string<typename A::letter_t>&
154 identity_value(
SELECTOR(algebra::FreeMonoid<A>),
155 SELECTOR(std::basic_string<typename A::letter_t>))
157 static const std::basic_string<typename A::letter_t> instance;
162 const std::basic_string<
typename A::letter_t,
163 misc::char_traits<typename A::letter_t> >&
164 identity_value(
SELECTOR(algebra::FreeMonoid<A>),
165 SELECTOR2(std::basic_string<
typename A::letter_t,
166 misc::char_traits<typename A::letter_t> >))
168 static const std::basic_string<
typename A::letter_t,
169 misc::char_traits<typename A::letter_t> > instance;
174 std::basic_string<typename A::letter_t>
175 op_convert(
SELECTOR(algebra::FreeMonoid<A>),
176 SELECTOR(std::basic_string<typename A::letter_t>),
177 const typename A::letter_t& c)
179 std::basic_string<typename A::letter_t> str;
184 template<
typename A,
typename B,
typename C,
typename D>
186 op_is_atom(
const algebra::FreeMonoid<A>&,
187 const std::basic_string<B, C, D>& v)
189 return v.size() <= 1;
194 Element<algebra::FreeMonoid<A>, std::basic_string<typename A::letter_t> >
195 op_choose(
const algebra::FreeMonoid<A>& s,
196 SELECTOR(std::basic_string<typename A::letter_t>))
200 std::basic_string<typename A::letter_t> r;
201 for (
unsigned i = 0; i < length; ++i)
202 r = r + s.alphabet().choose();
203 return Element<algebra::FreeMonoid<A>,
204 std::basic_string<typename A::letter_t> >(s, r);
207 # define WORD_TRAITS \
208 word_traits<FreeMonoid<A>, std::basic_string<typename A::letter_t> >
210 template <
typename A>
211 inline typename WORD_TRAITS::first_projection_value_t
212 WORD_TRAITS::first_projection(
const WORD_TRAITS::word_value_t& str)
215 static_assertion_(not (misc::static_eq<first_projection_t,
216 undefined_type>::value), need_first_projection);
218 first_projection_value_t R;
221 for_all_const_(word_value_t, i, str)
227 template <typename A>
228 inline typename WORD_TRAITS::first_projection_t
229 WORD_TRAITS::first_projection(const WORD_TRAITS::first_monoid_t& mon,
230 const WORD_TRAITS::word_t& word)
233 static_assertion_(not (misc::static_eq<first_projection_t,
234 undefined_type>::value), need_first_projection);
236 first_projection_t R(mon);
238 R.value() = first_projection(word.value());
243 template <
typename A>
244 inline typename WORD_TRAITS::second_projection_value_t
245 WORD_TRAITS::second_projection(
const WORD_TRAITS::word_value_t& str)
248 static_assertion_(not (misc::static_eq<second_projection_t,
249 undefined_type>::value), need_second_projection);
251 second_projection_value_t R;
254 for_all_const_(word_value_t, i, str)
260 template <typename A>
261 inline typename WORD_TRAITS::second_projection_t
262 WORD_TRAITS::second_projection(const WORD_TRAITS::second_monoid_t& mon,
263 const WORD_TRAITS::word_t& word)
266 static_assertion_(not (misc::static_eq<second_projection_t,
267 undefined_type>::value), need_second_projection);
269 second_projection_t R(mon);
271 R.value() = second_projection(word.value());
282 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_MONOID_STR_WORDS_HXX