Vaucanson  1.4.1
automata.hxx
1 // automata.hxx: 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, 2008 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_CONCEPT_AUTOMATA_HXX
18 # define VCSN_AUTOMATA_CONCEPT_AUTOMATA_HXX
19 
20 #include <vaucanson/automata/concept/automata_base.hh>
21 #include <vaucanson/misc/unique.hh>
22 
23 namespace vcsn {
24 
25  template <typename Series, typename Kind>
26  Automata<Series, Kind>::Automata(const series_set_t& s):
27  SetSlot<Series>(s)
28  {}
29 
30  template <typename Series, typename Kind>
31  const Series&
33  {
34  return this->_structure_get();
35  }
36 
37  template <typename Series, typename Kind>
38  bool
39  operator==(const Automata<Series, Kind>& lhs,
40  const Automata<Series, Kind>& rhs)
41  {
42  return & lhs.series() == & rhs.series();
43  }
44 
45 # define PROJECTION_TRAITS \
46  projection_traits<Automata<S, K>, T>
47 
48  template <typename S, typename K, typename T>
49  inline typename PROJECTION_TRAITS::first_projection_t
50  PROJECTION_TRAITS::
51  first_projection(const PROJECTION_TRAITS::automaton_t& aut)
52  {
53  // We can not project if the type does not support it.
54  static_assertion_(not (misc::static_eq<first_projection_t,
55  undefined_type>::value), need_first_projection);
56 
57  semiring_t semiring = aut.series().semiring();
58  alphabet_t A = aut.series().monoid().alphabet();
59 
60  // Project the alphabet.
61  typename alphabet_traits_t::first_projection_t B =
62  alphabet_traits_t::first_projection(A);
63 
64  // Construct the monoid.
65  typename word_traits_t::first_monoid_t freemonoid(B);
66 
67  // Construct the series.
68  typename first_projection_t::series_set_t series(semiring, freemonoid);
69 
70  // Construct the automaton structure.
71  typename first_projection_t::set_t set_t(series);
72 
73  return first_projection_t(set_t);
74  }
75 
76  template <typename S, typename K, typename T>
77  inline typename PROJECTION_TRAITS::second_projection_t
78  PROJECTION_TRAITS::
79  second_projection(const PROJECTION_TRAITS::automaton_t& aut)
80  {
81  // We can not project if the type does not support it.
82  static_assertion_(not (misc::static_eq<second_projection_t,
83  undefined_type>::value), need_second_projection);
84 
85  semiring_t semiring = aut.series().semiring();
86  alphabet_t A = aut.series().monoid().alphabet();
87 
88  // Project the alphabet.
89  typename alphabet_traits_t::second_projection_t B =
90  alphabet_traits_t::second_projection(A);
91 
92  // Construct the monoid.
93  typename word_traits_t::second_monoid_t freemonoid(B);
94 
95  // Construct the series.
96  typename second_projection_t::series_set_t series(semiring, freemonoid);
97 
98  // Construct the automaton structure.
99  typename second_projection_t::set_t set_t(series);
100 
101  return second_projection_t(set_t);
102  }
103 
104  template <typename S, typename K, typename T>
105  inline typename PROJECTION_TRAITS::series_first_projection_t
106  PROJECTION_TRAITS::
107  series_first_projection(const PROJECTION_TRAITS::first_series_t& series,
108  const PROJECTION_TRAITS::series_set_elt_t& ss)
109  {
110  // We can not project if the type does not support it.
111  static_assertion_(not (misc::static_eq<first_projection_t,
112  undefined_type>::value), need_first_projection);
113 
114  series_first_projection_t ret(series);
115 
116  for_all_const_(series_set_elt_t::support_t, s, ss.supp())
117  ret.assoc(word_traits_t::first_projection(*s),
118  ss.get(*s));
119 
120  return ret;
121  }
122 
123  template <typename S, typename K, typename T>
124  inline typename PROJECTION_TRAITS::series_second_projection_t
125  PROJECTION_TRAITS::
126  series_second_projection(const PROJECTION_TRAITS::second_series_t& series,
127  const PROJECTION_TRAITS::series_set_elt_t& ss)
128  {
129  // We can not project if the type does not support it.
130  static_assertion_(not (misc::static_eq<second_projection_t,
131  undefined_type>::value), need_second_projection);
132 
133  series_second_projection_t ret(series);
134 
135  for_all_const_(series_set_elt_t::support_t, s, ss.supp())
136  ret.assoc(word_traits_t::second_projection(*s),
137  ss.get(*s));
138 
139  return ret;
140  }
141 
142 # undef PROJECTION_TRAITS
143 
144 } // ! vcsn
145 
146 #endif // ! VCSN_AUTOMATA_CONCEPT_AUTOMATA_HXX