Vaucanson  1.4.1
history.hxx
1 // history.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_HISTORY_HXX
18 # define VCSN_AUTOMATA_CONCEPT_HISTORY_HXX
19 
20 # include <list>
21 # include <map>
22 
23 # include <vaucanson/automata/concept/history.hh>
24 
25 namespace vcsn {
26 
27  namespace history {
28 
29  template <class T>
30  Event<T>::Event(event_kind_t e) : kind_(e)
31  {}
32 
33  template <class T>
34  Event<T>::~Event()
35  {}
36 
37  template <class T>
38  event_kind_t
39  Event<T>::get_event_kind() const
40  {
41  return kind_;
42  }
43 
44  template <class T>
45  BinaryEvent<T>::BinaryEvent(event_kind_t e, const T& first,
46  const T& second) :
47  Event<T>(e),
48  first_(first),
49  second_(second)
50  {}
51 
52  template <class T>
53  const T&
54  BinaryEvent<T>::get_first() const
55  {
56  return first_;
57  }
58 
59  template <class T>
60  const T&
61  BinaryEvent<T>::get_second() const
62  {
63  return second_;
64  }
65 
66  template <class T>
67  UnaryEvent<T>::UnaryEvent(event_kind_t e, const T& first) :
68  Event<T>(e),
69  first_(first)
70  {}
71 
72  template <class T>
73  const T&
74  UnaryEvent<T>::get_first() const
75  {
76  return first_;
77  }
78 
79  // FIXME : use std::find_if with a good function object.
80  template <class AutoType_>
81  bool
82  AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
83  hstate_t s)
84  {
85  // FIXME: fix this code.
86 // for (typename state_events_t::const_iterator ev
87 // = states_events_[s].begin();
88 // ev != states_events_[s].end();
89 // ++ev)
90 // if (ev->second->get_event_kind() == e)
91 // return false;
92 // states_events_[s].push_front(new Event<hstate_t>(e));
93  return true;
94  }
95 
96  template <class AutoType_>
97  bool
98  AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
99  hstate_t s,
100  hstate_t first)
101  {
102  for (typename state_events_t::const_iterator ev
103  = states_events_[s].begin();
104  ev != states_events_[s].end();
105  ++ev)
106  if (ev->get_event_kind() == e)
107  return false;
108  states_events_[s].push_front(UnaryEvent<hstate_t>(e, first));
109  return true;
110  }
111 
112  template <class AutoType_>
113  bool
114  AutomatonHistory<AutoType_>::set_state_event_about(event_kind_t e,
115  hstate_t s,
116  hstate_t first,
117  hstate_t second)
118  {
119  for (typename state_events_t::const_iterator ev =
120  states_events_[s].begin();
121  ev != states_events_[s].end();
122  ++ev)
123  if (ev->get_event_kind() == e)
124  return false;
125  states_events_[s].push_front(BinaryEvent<hstate_t>
126  (e, first, second));
127  return true;
128  }
129 
130  template <class AutoType_>
131  const Event<typename AutoType_::hstate_t>
132  AutomatonHistory<AutoType_>::get_state_event_about(event_kind_t e,
133  hstate_t s) const
134  {
135  typename states_events_t::const_iterator se = states_events_.find(s);
136  if (se == states_events_.end())
137  return 0;
138  for (typename state_events_t::const_iterator ev = se->second.begin();
139  ev != se->second.end();
140  ++ev)
141  if (ev->get_event_kind() == e)
142  return *ev;
143  return 0;
144  }
145 
146  template <class AutoType_>
147  bool
148  AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
149  htransition_t transition)
150  {
151  for (typename transition_events_t::const_iterator ev
152  = transitions_events_[transition].begin();
153  ev != transitions_events_[transition].end();
154  ++ev)
155  if (ev->get_event_kind() == e)
156  return false;
157  transitions_events_[transition].push_front(Event<htransition_t>(e));
158  return true;
159  }
160 
161  template <class AutoType_>
162  bool
163  AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
164  htransition_t transition,
165  htransition_t first)
166  {
167  for (typename transition_events_t::const_iterator ev
168  = transitions_events_[transition].begin();
169  ev != transitions_events_[transition].end();
170  ++ev)
171  if (ev->get_event_kind() == e)
172  return false;
173  transitions_events_[transition].push_front(UnaryEvent<htransition_t>(e, first));
174  return true;
175  }
176 
177  template <class AutoType_>
178  bool
179  AutomatonHistory<AutoType_>::set_transition_event_about(event_kind_t e,
180  htransition_t transition,
181  htransition_t first,
182  htransition_t second)
183  {
184  for (typename transition_events_t::const_iterator ev
185  = transitions_events_[transition].begin();
186  ev != transitions_events_[transition].end();
187  ++ev)
188  if (ev->get_event_kind() == e)
189  return false;
190  transitions_events_[transition].push_front
191  (BinaryEvent<htransition_t>(e, first, second));
192  return true;
193  }
194 
195  template <class AutoType_>
196  const Event<typename AutoType_::htransition_t>
197  AutomatonHistory<AutoType_>::get_transition_event_about(event_kind_t e,
198  htransition_t transition
199  ) const
200  {
201  typename transitions_events_t::const_iterator ee =
202  transitions_events_.find(transition);
203  if (ee == transitions_events_.end())
204  return 0;
205  for (typename transition_events_t::const_iterator ev = ee->second.begin();
206  ev != ee->second.end();
207  ++ev)
208  if (ev->get_event_kind() == e)
209  return (*ev);
210  return 0;
211  }
212 
213  template <class AutoType_>
214  bool
215  AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e)
216  {
217  for (typename auto_events_t::const_iterator ev = auto_events_.begin();
218  ev != auto_events_.end();
219  ++ev)
220  if (ev->second->get_event_kind() == e)
221  return false;
222  auto_events_.push_front(Event<AutoType_>(e));
223  return true;
224  }
225 
226  template <class AutoType_>
227  bool
228  AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e,
229  AutoType_ first)
230  {
231  for (typename auto_events_t::const_iterator ev = auto_events_.begin();
232  ev != auto_events_.end();
233  ++ev)
234  if (ev->second->get_event_kind() == e)
235  return false;
236  auto_events_.push_front(Event<AutoType_>(e, first));
237  return true;
238  }
239 
240  template <class AutoType_>
241  bool
242  AutomatonHistory<AutoType_>::set_auto_event_about(event_kind_t e,
243  AutoType_ first,
244  AutoType_ second)
245  {
246  for (typename auto_events_t::const_iterator ev = auto_events_.begin();
247  ev != auto_events_.end();
248  ++ev)
249  if (ev->get_event_kind() == e)
250  return false;
251  auto_events_.push_front(BinaryEvent<AutoType_>(e, first, second));
252  return true;
253  }
254 
255  template <class AutoType_>
256  const Event<AutoType_>
257  AutomatonHistory<AutoType_>::get_auto_event_about(event_kind_t e) const
258  {
259  for (typename auto_events_t::const_iterator ev = auto_events_.begin();
260  ev != auto_events_.end();
261  ++ev)
262  if (ev->get_event_kind() == e)
263  return (*ev);
264  return 0;
265  }
266 
267  template <class T>
268  std::ostream&
269  operator<<(std::ostream& out, const Event<T>& e)
270  {
271  out << e.get_event_kind();
272  return out;
273  }
274 
275 
276  } // history
277 
278 } // vcsn
279 
280 #endif // ! VCSN_AUTOMATA_CONCEPT_HISTORY_HXX