Vaucanson  1.4.1
kind_adapter.hh
1 // kind_adapter.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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_AUTOMATA_IMPLEMENTATION_KIND_ADAPTER_HH
18 # define VCSN_AUTOMATA_IMPLEMENTATION_KIND_ADAPTER_HH
19 
20 # include <vaucanson/automata/concept/automata_kind.hh>
21 
22 namespace vcsn {
23 
26 
27 #define ADAPT_ADD_LETTER_TRANSITION_TO_SERIES_LABEL(T...) \
28  typename automaton_traits<T>::htransition_t \
29  op_add_letter_transition(const AutomataBase<S>& s, \
30  T& v, \
31  const typename automaton_traits<T>::hstate_t& from,\
32  const typename automaton_traits<T>::hstate_t& to,\
33  const typename Element<S, T >::letter_t & l) \
34  { \
35  typedef typename S::series_set_t series_set_t; \
36  typedef typename series_set_t::monoid_t monoid_t; \
37  typedef typename series_set_t::semiring_t semiring_t; \
38  typedef typename Element<S, T >::monoid_elt_value_t \
39  monoid_elt_value_t; \
40  typedef typename Element<S, T >::semiring_elt_value_t \
41  semiring_elt_value_t; \
42  typedef typename Element<S, T >::series_set_elt_value_t \
43  series_set_elt_value_t; \
44  \
45  Element<series_set_t, series_set_elt_value_t> label (s.series()); \
46  \
47  Element<monoid_t, monoid_elt_value_t> word (s.series().monoid(), l); \
48  label.assoc(word, \
49  s.series().semiring().identity(SELECT(semiring_elt_value_t))); \
50  \
51  return op_add_transition(s, v, from, to, label.value()); \
52  }
53 
54 #define ADAPT_LETTER_OF_TO_SERIES_LABEL(T...) \
55  typename Element<AutomataBase<S>, T >::letter_t \
56  op_letter_of(const AutomataBase<S>& s, \
57  const T& v, \
58  const typename automaton_traits<T>::htransition_t& e) \
59  { \
60  typedef typename S::series_set_t series_set_t; \
61  typedef typename series_set_t::monoid_t monoid_t; \
62  typedef typename Element<S, T >::monoid_elt_value_t \
63  word_value_t; \
64  typedef typename Element<S, T >::series_set_elt_value_t \
65  series_set_elt_value_t; \
66  \
67  Element<series_set_t, series_set_elt_value_t> sl = op_series_of(s, v, e); \
68  precondition(sl.supp().size() == 1); \
69  Element<monoid_t, word_value_t> w = sl.choose_from_supp(); \
70  precondition(w.length() == 1); \
71  return *w.begin(); \
72  }
73 
74 #define ADAPT_WORD_OF_TO_SERIES_LABEL(T...) \
75  typename Element<AutomataBase<S>, T >::monoid_elt_t \
76  op_word_of(const AutomataBase<S>& s, \
77  const T& v, \
78  const typename automaton_traits<T>::htransition_t& e) \
79  { \
80  typedef typename S::series_set_t series_set_t; \
81  typedef typename series_set_t::monoid_t monoid_t; \
82  typedef typename Element<S, T >::monoid_elt_value_t \
83  word_value_t; \
84  typedef typename Element<S, T >::series_set_elt_value_t \
85  series_set_elt_value_t; \
86  \
87  Element<series_set_t, series_set_elt_value_t> sl = op_series_of(s, v, e); \
88  precondition(sl.supp().size() == 1); \
89  Element<monoid_t, word_value_t> w = sl.choose_from_supp(); \
90  return w; \
91  }
92 
95 #define ADAPT_ADD_SERIE_TRANSITION_TO_LETTERS_LABEL(T...) \
96  typename automaton_traits<T>::htransition_t \
97  op_add_series_transition(const AutomataBase<S>& a_set, \
98  T& v, \
99  const typename automaton_traits<T>::hstate_t& from,\
100  const typename automaton_traits<T>::hstate_t& to, \
101  const typename Element<S,T>::series_set_elt_t& s) \
102  { \
103  assertion(s.supp().size() == 1); \
104  typedef typename Element<S, T>::series_set_elt_t::value_t::monoid_elt_value_t\
105  monoid_elt_value_t; \
106  typename automaton_traits<T>::htransition_t res; \
107  monoid_elt_value_t supp = *s.supp().begin(); \
108  for (typename monoid_elt_value_t::const_iterator it = supp.begin(); \
109  it != supp.end(); ++it) \
110  res = op_add_letter_transition(a_set, v, from, to, *it); \
111  return res; \
112  }
113 
114 #define ADAPT_WORD_OF_TO_LETTERS_LABEL(T...) \
115  typename Element<AutomataBase<S>, T >::monoid_elt_t \
116  op_word_of(const AutomataBase<S>& a_set, \
117  const T& v, \
118  const typename automaton_traits<T>::htransition_t& e)\
119  { \
120  typedef T value_t; \
121  typedef typename S::series_set_t series_set_t; \
122  typedef typename series_set_t::monoid_t monoid_t; \
123  typedef typename Element<S, value_t>::monoid_elt_value_t \
124  word_value_t; \
125  Element<monoid_t, word_value_t> \
126  w(a_set.series().monoid()); \
127  w += op_letter_of(a_set, v, e); \
128  return w; \
129  }
130 
131 #define ADAPT_SERIE_OF_TO_LETTERS_LABEL(T...) \
132  typename Element<AutomataBase<S>, T >::series_set_elt_t \
133  op_series_of(const AutomataBase<S>& a_set, \
134  const T& v, \
135  const typename automaton_traits<T>::htransition_t& e) \
136  { \
137  typedef T value_t; \
138  \
139  typedef typename S::series_set_t series_set_t; \
140  typedef typename series_set_t::monoid_t monoid_t; \
141  typedef typename Element<S, value_t>::monoid_elt_value_t \
142  word_value_t; \
143  typedef typename Element<S, value_t>::semiring_elt_value_t \
144  semiring_elt_value_t; \
145  typedef typename Element<S, value_t>::series_set_elt_value_t \
146  series_set_elt_value_t; \
147  Element<monoid_t, word_value_t> w(a_set.series().monoid()); \
148  w = op_letter_of(a_set, v, e); \
149  Element<series_set_t, series_set_elt_value_t> s(a_set.series()); \
150  s.assoc(w, algebra::identity_as<semiring_elt_value_t> \
151  ::of(a_set.series().semiring())); \
152  return s; \
153  }
154 
155 } // vcsn
156 
157 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
158 # include <vaucanson/automata/implementation/kind_adapter.hxx>
159 # endif // VCSN_USE_INTERFACE_ONLY
160 
161 #endif // ! VCSN_AUTOMATA_IMPLEMENTATION_KIND_ADAPTER_HH