Vaucanson  1.4.1
pair_str_words.hxx
1 // pair_str_words.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005, 2007, 2008, 2010 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX
19 
20 # include <vaucanson/algebra/implementation/monoid/pair_str_words.hh>
21 
22 namespace vcsn {
23 
24  namespace algebra {
25 
26  template <class Self, typename T>
27  typename
29  op_first(const algebra::FreeMonoidProductBase<Self>& s, T& v)
30  {
31  return Element<typename virtual_types<Self>::first_monoid_t,
32  typename T::first_type> (s.first_monoid(), v.first);
33  }
34 
35  template <class Self, typename T>
36  typename
38  op_second(const algebra::FreeMonoidProductBase<Self>& s, T& v)
39  {
40  return Element<typename virtual_types<Self>::second_monoid_t,
41  typename T::second_type> (s.second_monoid(), v.second);
42  }
43 
44  template <class F, class S>
45  void
46  op_in_mul(const algebra::FreeMonoidProduct<F, S>& s,
47  std::pair<std::basic_string<typename F::letter_t>,
48  std::basic_string<typename S::letter_t> >& dst,
49  const std::pair<std::basic_string<typename F::letter_t>,
50  std::basic_string<typename S::letter_t> >& src)
51  {
52  dst.first += src.first;
53  dst.second += src.second;
54  }
55 
56  template<class F, class S>
57  std::pair<std::basic_string<typename F::letter_t>,
58  std::basic_string<typename S::letter_t> >
59  op_mul(const algebra::FreeMonoidProduct<F, S>&,
60  const std::pair<std::basic_string<typename F::letter_t>,
61  std::basic_string<typename S::letter_t> >& a,
62  const std::pair<std::basic_string<typename F::letter_t>,
63  std::basic_string<typename S::letter_t> >& b)
64  {
65  return std::pair< std::basic_string<typename F::letter_t>,
66  std::basic_string<typename S::letter_t> >
67  (a.first + b.first, a.second + b.second);
68  }
69 
70  template<class F, class S>
71  const std::pair<std::basic_string<typename F::letter_t>,
72  std::basic_string<typename S::letter_t> >
73  identity_value(SELECTOR2(algebra::FreeMonoidProduct<F, S>),
74  SELECTOR2(std::pair<std::basic_string<typename F::letter_t>,
75  std::basic_string<typename S::letter_t> >))
76  {
77  static const std::pair<std::basic_string<typename F::letter_t>,
78  std::basic_string<typename S::letter_t> >
79  instance;
80  return instance;
81  }
82 
83  template <class F, class S>
84  Element<algebra::FreeMonoidProduct<F, S>,
85  std::pair<std::basic_string<typename F::letter_t>,
86  std::basic_string<typename S::letter_t> > >
87  op_choose(const algebra::FreeMonoidProduct<F, S>& s,
88  SELECTOR2(std::pair<std::basic_string<typename F::letter_t>,
89  std::basic_string<typename S::letter_t> >))
90  {
91  typedef std::basic_string<typename F::letter_t> T1;
92  typedef std::basic_string<typename S::letter_t> T2;
93 
94  std::pair< T1, T2 > res(s.first_monoid().choose(SELECT(T1)).value(),
95  s.second_monoid().choose(SELECT(T2)).value());
96 
97  return Element<algebra::FreeMonoidProduct<F, S>,
98  std::pair< T1, T2 > > (s, res);
99  }
100 
101  template<typename Self, typename T>
102  void
103  op_in_mirror(const algebra::FreeMonoidProductBase<Self>& s, T& v)
104  {
105  op_in_mirror(s.first_monoid(), v.first);
106  op_in_mirror(s.second_monoid(), v.second);
107  }
108 
109  template<typename Self, typename T, typename Ftor>
110  typename Ftor::result_type
111  op_length(const algebra::FreeMonoidProductBase<Self>&, const T& v, Ftor f)
112  {
113  return f(v.first.length(), v.second.length());
114  }
115 
116  template<typename F, typename S,
117  typename A1, typename A2, typename A3, typename A4>
118  bool
119  op_is_atom(const algebra::FreeMonoidProduct<F, S>&,
120  const std::pair<std::basic_string<typename F::letter_t, A1, A2>,
121  std::basic_string<typename S::letter_t, A3, A4>
122  >& v)
123  {
124  return (v.first.length() <= 1) && (v.second.length() <= 1);
125  }
126 
127  template <typename F, typename S, typename St>
128  St&
129  op_rout(const FreeMonoidProduct<F, S>& s,
130  St& st,
131  const std::pair<std::basic_string<typename F::letter_t>,
132  std::basic_string<typename S::letter_t> >& v)
133  {
134  if (v.first.empty() && v.second.empty())
135  st << s.representation()->empty;
136  else
137  {
138  st << s.representation()->open_par;
139  op_rout(s.first_monoid(), st, v.first);
140  st << s.representation()->sep;
141  op_rout(s.second_monoid(), st, v.second);
142  st << s.representation()->close_par;
143  }
144 
145  return st;
146  }
147 
148  } // ! algebra
149 
150 } // ! vcsn
151 
152 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_MONOID_PAIR_STR_WORDS_HXX