17 #ifndef VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HXX
18 # define VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HXX
22 namespace algorithm_patterns
26 template <
typename Self,
typename Etiq>
28 Comparator<Self, Etiq>::operator()(
const Etiq& e1,
const Etiq& e2)
const
30 return Self::compare(e1, e2);
38 template <
typename Self,
typename T_auto,
typename Etiq>
39 IncAutomataConstructor<Self, T_auto, Etiq>::IncAutomataConstructor
41 const series_set_t& series,
const Etiq& etiq
44 automata_set_t a_set(series);
45 auto_p =
new T_auto(a_set);
47 auto_p->set_initial(add_state(etiq));
48 current_state = states_map.end();
52 template <
typename Self,
typename T_auto,
typename Etiq>
53 IncAutomataConstructor<Self, T_auto, Etiq>::IncAutomataConstructor
55 const series_set_t& series,
const std::list<Etiq>& listexp
58 automata_set_t a_set(series);
59 auto_p =
new T_auto(a_set);
62 for (
typename std::list<Etiq>::const_iterator it = listexp.begin();
63 it != listexp.end(); ++it)
64 auto_p->set_initial(add_state(*it));
66 current_state = states_map.end();
71 template <
typename Self,
typename T_auto,
typename Etiq>
79 template <
typename Self,
typename T_auto,
typename Etiq>
81 IncAutomataConstructor<Self, T_auto, Etiq>::run()
85 for (current_state = states_map.begin();
86 current_state != states_map.end();
89 if (!(current_state->second.second))
91 on_state_caller(current_state->first);
93 current_state->second.second =
true;
100 template <
typename Self,
typename T_auto,
typename Etiq>
102 IncAutomataConstructor<Self, T_auto, Etiq>::link_to
104 const Etiq& etiq,
const letter_t& l
107 typename T_auto::hstate_t s;
108 iterator i = states_map.find(etiq);
110 if (i == states_map.end())
114 auto_p->add_letter_transition(current_state->second.first, s, l);
117 template <
typename Self,
typename T_auto,
typename Etiq>
119 IncAutomataConstructor<Self, T_auto, Etiq>::link_to
121 const Etiq& etiq,
const series_set_elt_t& el
124 typename T_auto::hstate_t s;
125 iterator i = states_map.find(etiq);
127 if (i == states_map.end())
131 auto_p->add_series_transition(current_state->second.first, s, el);
135 template <
typename Self,
typename T_auto,
typename Etiq>
136 typename T_auto::hstate_t
137 IncAutomataConstructor<Self, T_auto, Etiq>::add_state(
const Etiq& etiq)
139 typename T_auto::hstate_t res = auto_p->add_state();
140 states_map[etiq] = std::pair<typename T_auto::hstate_t, bool>(res,
false);
146 template <
typename Self,
typename T_auto,
typename Etiq>
148 IncAutomataConstructor<Self, T_auto, Etiq>::set_final()
150 auto_p->set_final(current_state->second.first);
154 template <
typename Self,
typename T_auto,
typename Etiq>
156 IncAutomataConstructor<Self, T_auto, Etiq>::set_final
157 (
const series_set_elt_t& el)
159 auto_p->set_final(current_state->second.first, el);
166 template <
typename Self,
typename T_auto,
typename Etiq>
168 IncAutomataConstructor<Self, T_auto, Etiq>::on_state_caller(
const Etiq& e)
170 static_cast<Self&
>(*this).on_state(e);
174 template <
typename Self,
typename T_auto,
typename Etiq>
176 IncAutomataConstructor<Self, T_auto, Etiq>::compare
178 const Etiq& e1,
const Etiq& e2
190 template <
typename Self,
typename T_auto,
typename Etiq>
191 template <
typename Container>
192 MathAutomataConstructor<Self, T_auto, Etiq>::MathAutomataConstructor
194 const series_set_t& series,
const Container container
197 typedef typename Container::iterator c_iterator;
199 automata_set_t a_set(series);
200 auto_p =
new T_auto(a_set);
202 for (c_iterator i = container.begin(); i != container.end(); ++i)
203 states_map[*i] = auto_p->add_state();
207 template <
typename Self,
typename T_auto,
typename Etiq>
218 template <
typename Self,
typename T_auto,
typename Etiq>
220 MathAutomataConstructor<Self, T_auto, Etiq>::run()
222 alphabet_t alpha =
get()->series().monoid().alphabet();
223 for (iterator i = states_map.begin(); i != states_map.end(); ++i)
225 if (is_initial_caller(i->first))
226 auto_p->set_initial(i->second);
227 if (is_final_caller(i->first))
228 auto_p->set_final(i->second);
229 for (alphabet_iterator a = alpha.begin(); a != alpha.end(); ++a)
230 link_to(i->second, *a, static_cast<Self&>(*this).delta(i->first, *a));
236 template <
typename Self,
typename T_auto,
typename Etiq>
238 MathAutomataConstructor<Self, T_auto, Etiq>::is_initial_caller
243 return static_cast<const Self&
>(*this).is_initial(e);
246 template <
typename Self,
typename T_auto,
typename Etiq>
248 MathAutomataConstructor<Self, T_auto, Etiq>::is_final_caller
253 return static_cast<const Self&
>(*this).is_final(e);
258 template <
typename Self,
typename T_auto,
typename Etiq>
259 template <
typename Container>
261 MathAutomataConstructor<Self, T_auto, Etiq>::link_to
263 const typename T_auto::hstate_t& state,
const letter_t& letter,
const Container container
266 typedef typename Container::iterator c_iterator;
267 for (c_iterator j = container.begin(); j != container.end(); ++j)
269 iterator tmp = states_map.find(*j);
270 if (tmp != states_map.end())
271 auto_p->add_letter_transition(state, tmp->second, letter);
276 template <
typename Self,
typename T_auto,
typename Etiq>
278 MathAutomataConstructor<Self, T_auto, Etiq>::compare
280 const Etiq& e1,
const Etiq& e2
289 #endif // ! VCSN_ALGORITHMS_INTERNAL_BUILD_PATTERN_HXX