Vaucanson  1.4.1
kinds.hxx
1 // kinds.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, 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_CONCEPT_KINDS_HXX
18 # define VCSN_AUTOMATA_CONCEPT_KINDS_HXX
19 
20 # include <iterator>
21 # include <algorithm>
22 
25 # include <vaucanson/automata/concept/handlers.hh>
26 
27 namespace vcsn {
28 
29  template<typename Series,
30  typename MonoidElt,
31  typename SemiringElt,
32  typename L>
33  ls_delta_letter_query<Series, MonoidElt, SemiringElt, L>::
34  ls_delta_letter_query(const Series& s, const L& l)
35  : s_(s),
36  l_(op_convert(SELECT(typename MonoidElt::set_t),
37  SELECT(typename MonoidElt::value_t),
38  l))
39  {}
40 
41  template<typename Series,
42  typename MonoidElt,
43  typename SemiringElt,
44  typename L>
45  template<typename Label>
46  bool ls_delta_letter_query<Series, MonoidElt, SemiringElt, L>::
47  operator()(const Label& label) const
48  {
49  return (op_series_get(s_.get(), label, l_)
50  != zero_value(SELECT(typename SemiringElt::set_t),
51  SELECT(typename SemiringElt::value_t)));
52  }
53 
54 
55 
56  template<typename Self, typename Series, typename SeriesT, typename LabelT>
57  Element<Series, SeriesT>
58  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
59  series_of(htransition_t e) const
60  {
61  return series_set_elt_t(auto_self().series(),
62  auto_self().label_of(e));
63  }
64 
65  template<typename Self, typename Series, typename SeriesT, typename LabelT>
66  const SeriesT&
67  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
68  series_value_of(htransition_t e) const
69  {
70  return auto_self().label_of(e);
71  }
72 
73  template<typename Self, typename Series, typename SeriesT, typename LabelT>
74  bool
75  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
76  is_spontaneous(htransition_t e) const
77  {
78  const series_set_elt_t& s = auto_self().label_of(e);
79 
80  return s == algebra::identity_as<SeriesT>::of(s.set());
81  }
82 
83  template<typename Self, typename Series, typename SeriesT, typename LabelT>
84  template<typename L>
85  L
86  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
87  letter_of(SELECTOR(L), htransition_t e) const
88  {
89  return *op_begin(auto_self().series().monoid(),
90  auto_self().label_of(e).begin()->first);
91  }
92 
93  template<typename Self, typename Series, typename SeriesT, typename LabelT>
94  typename Element<Series, SeriesT>::monoid_elt_t
95  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
96  word_of(htransition_t e) const
97  {
98  const LabelT& l = auto_self().label_of(e);
99 
100  return monoid_elt_t(auto_self().series().monoid(),
101  l.begin()->first);
102  }
103 
104  template<typename Self, typename Series, typename SeriesT, typename LabelT>
105  const typename Element<Series, SeriesT>::monoid_elt_t::value_t&
106  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
107  word_value_of(htransition_t e) const
108  {
109  return auto_self().label_of(e).begin()->first;
110  }
111 
112  template<typename Self, typename Series, typename SeriesT, typename LabelT>
113  template<typename S>
114  typename Self::htransition_t
115  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
116  add_series_transition(hstate_t from, hstate_t to,
117  const S& e)
118  {
119  return auto_self().add_transition(from, to, e.value());
120  }
121 
122  template<typename Self, typename Series, typename SeriesT, typename LabelT>
123  typename Self::htransition_t
124  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
125  add_spontaneous(hstate_t from, hstate_t to)
126  {
127  return auto_self().add_transition(from, to,
128  identity_value(SELECT(Series),
129  SELECT(SeriesT)));
130  }
131 
132  template<typename Self, typename Series, typename SeriesT, typename LabelT>
133  template<typename L>
134  typename Self::htransition_t
135  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
136  add_letter_transition(hstate_t from, hstate_t to,
137  const L& l)
138  {
139  return auto_self().add_transition(from, to,
140  series_set_elt_t(auto_self().series(),
141  monoid_elt_t(auto_self().series().monoid(),
142  l)
143  ).value()
144  );
145  }
146 
147  template<typename Self, typename Series, typename SeriesT, typename LabelT>
148  Self&
149  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
150  auto_self()
151  { return static_cast<Self&>(*this); }
152 
153  template<typename Self, typename Series, typename SeriesT, typename LabelT>
154  const Self&
155  AutoKind<labels_are_series, Self, Series, SeriesT, LabelT>::
156  auto_self() const
157  { return static_cast<const Self&>(*this); }
158 
159 }
160 
161 #endif // ! VCSN_AUTOMATA_CONCEPT_KINDS_HXX