Vaucanson  1.4.1
automata_base.hxx
1 // automata_base.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, 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_BASE_HXX
18 # define VCSN_AUTOMATA_CONCEPT_AUTOMATA_BASE_HXX
19 
20 # include <vaucanson/automata/concept/copy.hh>
21 # include <vaucanson/automata/concept/automata_base.hh>
23 
24 namespace vcsn {
25 
26  template <typename Self>
28  {}
29 
30  template <typename Self>
32  Structure<Self>(other)
33  {}
34 
35  template <typename Self>
36  const typename AutomataBase<Self>::series_set_t&
38  {
39  return this->self().series();
40  }
41 
42 
44  template <typename Self, typename T>
46  {}
47 
49  template <typename Self, typename T>
51  MetaElement<Structure<Self>, T>::MetaElement(a)
52  {}
53 
55  template <typename Self, typename T>
56  typename MetaElement<AutomataBase<Self>, T>::tag_t&
58  {
59  return op_tag(this->structure(), this->value());
60  }
61 
63  template <typename Self, typename T>
64  const typename MetaElement<AutomataBase<Self>, T>::tag_t&
66  {
67  return op_tag(this->structure(), this->value());
68  }
69 
71  template <typename Self, typename T>
72  typename MetaElement<AutomataBase<Self>, T>::geometry_t&
74  {
75  return op_geometry(this->structure(), this->value());
76  }
77 
79  template <typename Self, typename T>
80  const typename MetaElement<AutomataBase<Self>, T>::geometry_t&
82  {
83  return op_geometry(this->structure(), this->value());
84  }
85 
87  template <typename Self, typename T>
88  bool
89  MetaElement<AutomataBase<Self>, T>::exists() const
90  {
91  return op_exists(this->structure(), this->value());
92  }
93 
95  template <typename Self, typename T>
96  typename automaton_traits<T>::states_t
97  MetaElement<AutomataBase<Self>, T>::states() const
98  {
99  return op_states(this->structure(), this->value());
100  }
101 
103  template <typename Self, typename T>
104  typename automaton_traits<T>::transitions_t
105  MetaElement<AutomataBase<Self>, T>::transitions() const
106  {
107  return op_transitions(this->structure(), this->value());
108  }
109 
111  template <typename Self, typename T>
112  const typename MetaElement<AutomataBase<Self>, T>::series_set_t&
113  MetaElement<AutomataBase<Self>, T>::series() const
114  {
115  return this->structure().series();
116  }
117 
119  template <typename Self, typename T>
120  typename automaton_traits<T>::initial_support_t
121  MetaElement<AutomataBase<Self>, T>::initial() const
122  {
123  return op_initial(this->structure(), this->value());
124  }
125 
127  template <typename Self, typename T>
128  typename automaton_traits<T>::final_support_t
129 
131  {
132  return op_final(this->structure(), this->value());
133  }
134 
137  template <typename Self, typename T>
138  bool
139  MetaElement<AutomataBase<Self>, T>::is_initial(const typename automaton_traits<T>::hstate_t& state) const
140  {
141  return op_is_initial(this->structure(), this->value(), state);
142  }
143 
144  template <typename Self, typename T>
145  bool
146  MetaElement<AutomataBase<Self>, T>::is_initial(unsigned state) const
147  {
148  return op_is_initial(this->structure(), this->value(), state);
149  }
150 
152  template <typename Self, typename T>
153  bool
154  MetaElement<AutomataBase<Self>, T>::is_final(const typename automaton_traits<T>::hstate_t& state) const
155  {
156  return op_is_final(this->structure(), this->value(), state);
157  }
158 
159  template <typename Self, typename T>
160  bool
161  MetaElement<AutomataBase<Self>, T>::is_final(unsigned state) const
162  {
163  return op_is_final(this->structure(), this->value(), state);
164  }
165 
167  template <typename Self, typename T>
168  void
169  MetaElement<AutomataBase<Self>, T>::set_initial(const typename automaton_traits<T>::hstate_t& state)
170  {
171  op_set_initial(this->structure(),
172  this->value(),
173  state,
174  this->structure().series().
175  identity(SELECT(series_set_elt_value_t)));
176  }
177 
178  template <typename Self, typename T>
179  void
180  MetaElement<AutomataBase<Self>, T>::set_initial(unsigned state)
181  {
182  op_set_initial(this->structure(),
183  this->value(),
184  state,
185  this->structure().series().
186  identity(SELECT(series_set_elt_value_t)));
187  }
188 
190  template <typename Self, typename T>
191  void
193  set_initial(const typename automaton_traits<T>::hstate_t& state, const series_set_elt_t& s)
194  {
195  op_set_initial(this->structure(), this->value(), state, s);
196  }
197 
198  template <typename Self, typename T>
199  void
201  set_initial(unsigned state, const series_set_elt_t& s)
202  {
203  op_set_initial(this->structure(), this->value(), state, s);
204  }
205 
207  template <typename Self, typename T>
208  void
209  MetaElement<AutomataBase<Self>, T>::set_final(const typename automaton_traits<T>::hstate_t& state)
210  {
211  op_set_final(this->structure(),
212  this->value(),
213  state,
214  this->structure().series().
215  identity(SELECT(series_set_elt_value_t)));
216  }
217 
218  template <typename Self, typename T>
219  void
220  MetaElement<AutomataBase<Self>, T>::set_final(unsigned state)
221  {
222  op_set_final(this->structure(),
223  this->value(),
224  state,
225  this->structure().series().
226  identity(SELECT(series_set_elt_value_t)));
227  }
228 
230  template <typename Self, typename T>
231  void
233  set_final(const typename automaton_traits<T>::hstate_t& state, const series_set_elt_t& s)
234  {
235  op_set_final(this->structure(), this->value(), state, s);
236  }
237 
238  template <typename Self, typename T>
239  void
241  set_final(unsigned state, const series_set_elt_t& s)
242  {
243  op_set_final(this->structure(), this->value(), state, s);
244  }
245 
247  template <typename Self, typename T>
248  void
249  MetaElement<AutomataBase<Self>, T>::unset_initial(const typename automaton_traits<T>::hstate_t& state)
250  {
251  op_set_initial(this->structure(),
252  this->value(),
253  state,
254  algebra::zero_as<series_set_elt_value_t>::
255  of(this->structure().series()));
256  }
257 
258  template <typename Self, typename T>
259  void
260  MetaElement<AutomataBase<Self>, T>::unset_initial(unsigned state)
261  {
262  op_set_initial(this->structure(),
263  this->value(),
264  state,
265  algebra::zero_as<series_set_elt_value_t>::
266  of(this->structure().series()));
267  }
268 
270  template <typename Self, typename T>
271  void
272  MetaElement<AutomataBase<Self>, T>::unset_final(const typename automaton_traits<T>::hstate_t& state)
273  {
274  op_set_final(this->structure(),
275  this->value(),
276  state,
277  algebra::zero_as<series_set_elt_value_t>::
278  of(this->structure().series()));
279  }
280 
281  template <typename Self, typename T>
282  void
283  MetaElement<AutomataBase<Self>, T>::unset_final(unsigned state)
284  {
285  op_set_final(this->structure(),
286  this->value(),
287  state,
288  algebra::zero_as<series_set_elt_value_t>::
289  of(this->structure().series()));
290  }
291 
293  template <typename Self, typename T>
294  void
295  MetaElement<AutomataBase<Self>, T>::clear_initial()
296  {
297  return op_clear_initial(this->structure(), this->value());
298  }
299 
301  template <typename Self, typename T>
302  void
304  {
305  return op_clear_final(this->structure(), this->value());
306  }
307 
309  template <typename Self, typename T>
310  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_t
311  MetaElement<AutomataBase<Self>, T>::get_initial(const typename automaton_traits<T>::hstate_t& state) const
312  {
313  return op_get_initial(this->structure(), this->value(), state);
314  }
315 
316  template <typename Self, typename T>
317  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_t
318  MetaElement<AutomataBase<Self>, T>::get_initial(unsigned state) const
319  {
320  return op_get_initial(this->structure(), this->value(), state);
321  }
322 
324  template <typename Self, typename T>
325  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_t
326  MetaElement<AutomataBase<Self>, T>::get_final(const typename automaton_traits<T>::hstate_t& state) const
327  {
328  return op_get_final(this->structure(), this->value(), state);
329  }
330 
331  template <typename Self, typename T>
332  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_t
333  MetaElement<AutomataBase<Self>, T>::get_final(unsigned state) const
334  {
335  return op_get_final(this->structure(), this->value(), state);
336  }
337 
339  template <typename Self, typename T>
340  typename automaton_traits<T>::hstate_t
342  {
343  return op_add_state(this->structure(), this->value());
344  }
345 
347  template <typename Self, typename T>
348  typename automaton_traits<T>::hstate_t
349  MetaElement<AutomataBase<Self>, T>::get_state(unsigned state) const
350  {
351  return op_get_state(this->structure(), this->value(), state);
352  }
353 
356  template <typename Self, typename T>
357  typename automaton_traits<T>::hstate_t
358  MetaElement<AutomataBase<Self>, T>::choose_state() const
359  {
360  return op_choose_state(this->structure(), this->value());
361  }
362 
364  template <typename Self, typename T>
365  typename automaton_traits<T>::htransition_t
366  MetaElement<AutomataBase<Self>, T>::add_transition(const typename automaton_traits<T>::hstate_t& src,
367  const typename automaton_traits<T>::hstate_t& dst,
368  const label_t& label)
369  {
370  return op_add_transition(this->structure(), this->value(),
371  src, dst, label);
372  }
373 
374  template <typename Self, typename T>
375  typename automaton_traits<T>::htransition_t
376  MetaElement<AutomataBase<Self>, T>::add_transition(unsigned src,
377  unsigned dst,
378  const label_t& label)
379  {
380  return op_add_transition(this->structure(), this->value(),
381  src, dst, label);
382  }
383 
385  template <typename Self, typename T>
386  typename automaton_traits<T>::htransition_t
388  add_weighted_transition(const typename automaton_traits<T>::hstate_t& src,
389  const typename automaton_traits<T>::hstate_t& dst,
390  const semiring_elt_t& w,
391  const monoid_elt_value_t& m)
392  {
393  return op_add_weighted_transition(this->structure(), this->value(),
394  src, dst, w, m);
395  }
396 
397  template <typename Self, typename T>
398  typename automaton_traits<T>::htransition_t
400  add_weighted_transition(unsigned src,
401  unsigned dst,
402  const semiring_elt_t& w,
403  const monoid_elt_value_t& m)
404  {
405  return op_add_weighted_transition(this->structure(), this->value(),
406  src, dst, w, m);
407  }
408 
412  template <typename Self, typename T>
413  typename automaton_traits<T>::htransition_t
414  MetaElement<AutomataBase<Self>, T>::add_series_transition(const typename automaton_traits<T>::hstate_t& src,
415  const typename automaton_traits<T>::hstate_t& dst,
416  const series_set_elt_t& e)
417  {
418  return op_add_series_transition(this->structure(), this->value(),
419  src, dst, e);
420  }
421 
422  template <typename Self, typename T>
423  typename automaton_traits<T>::htransition_t
424  MetaElement<AutomataBase<Self>, T>::add_series_transition(unsigned src,
425  unsigned dst,
426  const series_set_elt_t& e)
427  {
428  return op_add_series_transition(this->structure(), this->value(),
429  src, dst, e);
430  }
431 
433  template <typename Self, typename T>
434  typename automaton_traits<T>::htransition_t
435  MetaElement<AutomataBase<Self>, T>::add_spontaneous(const typename automaton_traits<T>::hstate_t& src,
436  const typename automaton_traits<T>::hstate_t& dst)
437  {
438  semiring_elt_t w(this->structure().series().semiring());
439  w = algebra::identity_as<semiring_elt_value_t>
440  ::of(this->structure().series().semiring());
441  return op_add_spontaneous(this->structure(), this->value(), src, dst, w);
442  }
443 
444  template <typename Self, typename T>
445  typename automaton_traits<T>::htransition_t
446  MetaElement<AutomataBase<Self>, T>::add_spontaneous(unsigned src,
447  unsigned dst)
448  {
449  semiring_elt_t w(this->structure().series().semiring());
450  w = algebra::identity_as<semiring_elt_value_t>
451  ::of(this->structure().series().semiring());
452  return op_add_spontaneous(this->structure(), this->value(), src, dst, w);
453  }
454 
455  template <typename Self, typename T>
456  typename automaton_traits<T>::htransition_t
457  MetaElement<AutomataBase<Self>, T>::add_spontaneous(const typename automaton_traits<T>::hstate_t& src,
458  const typename automaton_traits<T>::hstate_t& dst,
459  const semiring_elt_t& w)
460  {
461  return op_add_spontaneous(this->structure(), this->value(), src, dst, w);
462  }
463 
464  template <typename Self, typename T>
465  typename automaton_traits<T>::htransition_t
466  MetaElement<AutomataBase<Self>, T>::add_spontaneous(unsigned src,
467  unsigned dst,
468  const semiring_elt_t& w)
469  {
470  return op_add_spontaneous(this->structure(), this->value(), src, dst, w);
471  }
472 
474  template <typename Self, typename T>
475  typename automaton_traits<T>::htransition_t
476  MetaElement<AutomataBase<Self>, T>::add_letter_transition(const typename automaton_traits<T>::hstate_t& src,
477  const typename automaton_traits<T>::hstate_t& dst,
478  const letter_t& l)
479  {
480  return op_add_letter_transition(this->structure(), this->value(),
481  src, dst, l);
482  }
483 
484  template <typename Self, typename T>
485  typename automaton_traits<T>::htransition_t
486  MetaElement<AutomataBase<Self>, T>::add_letter_transition(unsigned src,
487  unsigned dst,
488  const letter_t& l)
489  {
490  return op_add_letter_transition(this->structure(), this->value(),
491  src, dst, l);
492  }
493 
496  template <typename Self, typename T>
497  typename automaton_traits<T>::htransition_t
498  MetaElement<AutomataBase<Self>, T>::add_letter_transition(const typename automaton_traits<T>::hstate_t& src,
499  const typename automaton_traits<T>::hstate_t& dst,
500  const std::string& l)
501  {
502  return op_add_letter_transition(this->structure(), this->value(),
503  src, dst, algebra::letter_traits<letter_t>::
504  literal_to_letter(l).second);
505  }
506 
507  template <typename Self, typename T>
508  typename automaton_traits<T>::htransition_t
509  MetaElement<AutomataBase<Self>, T>::add_letter_transition(unsigned src,
510  unsigned dst,
511  const std::string& l)
512  {
513  return op_add_letter_transition(this->structure(), this->value(),
514  src, dst, algebra::letter_traits<letter_t>::
515  literal_to_letter(l).second);
516  }
517 
519  template <typename Self, typename T>
520  void
521  MetaElement<AutomataBase<Self>, T>::update(const typename automaton_traits<T>::htransition_t& e, const label_t& l)
522  {
523  op_update(this->structure(), this->value(), e, l);
524  }
525 
527  template <typename Self, typename T>
528  void
529  MetaElement<AutomataBase<Self>, T>::del_state(const typename automaton_traits<T>::hstate_t& s)
530  {
531  return op_del_state(this->structure(), this->value(), s);
532  }
533 
534  template <typename Self, typename T>
535  void
536  MetaElement<AutomataBase<Self>, T>::del_state(unsigned state)
537  {
538  return op_del_state(this->structure(), this->value(), state);
539  }
540 
542  template <typename Self, typename T>
543  void
544  MetaElement<AutomataBase<Self>, T>::del_transition(const typename automaton_traits<T>::htransition_t& e)
545  {
546  return op_del_transition(this->structure(), this->value(), e);
547  }
548 
550  template <typename Self, typename T>
551  bool
552  MetaElement<AutomataBase<Self>, T>::has_state(const typename automaton_traits<T>::hstate_t& s) const
553  {
554  return op_has_state(this->structure(), this->value(), s);
555  }
556 
557  template <typename Self, typename T>
558  bool
559  MetaElement<AutomataBase<Self>, T>::has_state(unsigned state) const
560  {
561  return op_has_state(this->structure(), this->value(), state);
562  }
563 
565  template <typename Self, typename T>
566  bool
567  MetaElement<AutomataBase<Self>, T>::has_transition(const typename automaton_traits<T>::htransition_t& e) const
568  {
569  return op_has_transition(this->structure(), this->value(), e);
570  }
571 
573  template <typename Self, typename T>
574  typename automaton_traits<T>::hstate_t
575  MetaElement<AutomataBase<Self>, T>::src_of(const typename automaton_traits<T>::htransition_t& e) const
576  {
577  return op_src_of(this->structure(), this->value(), e);
578  }
579 
581  template <typename Self, typename T>
582  typename automaton_traits<T>::hstate_t
583  MetaElement<AutomataBase<Self>, T>::dst_of(const typename automaton_traits<T>::htransition_t& e) const
584  {
585  return op_dst_of(this->structure(), this->value(), e);
586  }
587 
589  template <typename Self, typename T>
590  typename automaton_traits<T>::label_t
591  MetaElement<AutomataBase<Self>, T>::label_of(const typename automaton_traits<T>::htransition_t& e) const
592  {
593  return op_label_of(this->structure(), this->value(), e);
594  }
595 
597  template <typename Self, typename T>
598  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_t
599  MetaElement<AutomataBase<Self>, T>::series_of(const typename automaton_traits<T>::htransition_t& e) const
600  {
601  return op_series_of(this->structure(), this->value(), e);
602  }
603 
605  template <typename Self, typename T>
606  typename MetaElement<AutomataBase<Self>, T>::series_set_elt_value_t
607  MetaElement<AutomataBase<Self>, T>::series_value_of(const typename automaton_traits<T>::htransition_t& e) const
608  {
609  return op_series_value_of(this->structure(), this->value(), e);
610  }
611 
613  template <typename Self, typename T>
614  bool
615  MetaElement<AutomataBase<Self>, T>::is_spontaneous(const typename automaton_traits<T>::htransition_t& e) const
616  {
617  return op_is_spontaneous(this->structure(), this->value(), e);
618  }
619 
621  template <typename Self, typename T>
622  typename MetaElement<AutomataBase<Self>, T>::monoid_elt_t
623  MetaElement<AutomataBase<Self>, T>::word_of(const typename automaton_traits<T>::htransition_t& e) const
624  {
625  return op_word_of(this->structure(), this->value(), e);
626  }
627 
629  template <typename Self, typename T>
630  typename MetaElement<AutomataBase<Self>, T>::semiring_elt_t
631  MetaElement<AutomataBase<Self>, T>::weight_of(const typename automaton_traits<T>::htransition_t& e) const
632  {
633  return op_weight_of(this->structure(), this->value(), e);
634  }
635 
637  template <typename Self, typename T>
638  typename MetaElement<AutomataBase<Self>, T>::monoid_elt_value_t
639  MetaElement<AutomataBase<Self>, T>::word_value_of(const typename automaton_traits<T>::htransition_t& e) const
640  {
641  return op_word_value_of(this->structure(), this->value(), e);
642  }
643 
647  template <typename Self, typename T>
648  typename MetaElement<AutomataBase<Self>, T>::letter_t
649  MetaElement<AutomataBase<Self>, T>::letter_of(const typename automaton_traits<T>::htransition_t& e) const
650  {
651  return op_letter_of(this->structure(), this->value(), e);
652  }
653 
654  template<typename S, typename St, typename T>
655  St& op_rout(const AutomataBase<S>& s, St& st, const T& v)
656  {
657  Element<S, T> r(s.self(), v);
658  st << "{ "
659  << r.states().size() << " states, "
660  << r.transitions().size() << " transitions, "
661  << "#I = " << r.initial().size() << ", "
662  << "#T = " << r.final().size()
663  << " }";
664  return st;
665  }
666 
667  /*----------------------------------------------.
668  | automaton to generalized automaton convertion |
669  `----------------------------------------------*/
670 
671  template <typename Auto_>
672  typename generalized_traits<Auto_>::automaton_t
673  generalized(const Auto_& from)
674  {
675  typename generalized_traits<Auto_>::automaton_t to(from.structure());
676  auto_copy(to, from);
677  return to;
678  }
679 
680 } // ! vcsn
681 
682 #endif // ! VCSN_AUTOMATA_CONCEPT_AUTOMATA_BASE_HXX