Vaucanson  1.4.1
bmig_support.hxx
1 // boost_support.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 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_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
18 # define VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
19 
20 # include <vaucanson/automata/implementation/bmig/bmig_support.hh>
21 
22 namespace vcsn
23 {
24  namespace misc
25  {
26  //Specialization for std::vector<boost::shared_ptr<std::size_t> >
27  inline
28  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::SupportIterator (const container_t* c,
29  int i)
30  : current_(i), container_size_(c->size()), container_(c)
31  {}
32 
33  inline
34  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::handler_t
35  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator* () const
36  {
37  return handler_t((*container_)[current_]);
38  }
39 
40  inline
41  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >&
42  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator++ ()
43  {
44  if (container_->size() == container_size_)
45  ++current_;
46  else
47  container_size_ = container_->size();
48  return *this;
49  }
50 
51  inline
52  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >&
53  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator-- ()
54  {
55  if (container_->size() == container_size_)
56  --current_;
57  else
58  container_size_ = container_->size();
59  return *this;
60  }
61 
62  inline
63  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >
64  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator++ (int)
65  {
66  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > > tmp = *this;
67  ++(*this);
68  return tmp;
69  }
70 
71  inline
72  bool
73  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator!= (const SupportIterator& o) const
74  {
75  return o.current_ != current_;
76  }
77 
78  inline
79  bool
80  SupportIterator<std::vector<boost::shared_ptr<std::size_t> > >::operator== (const SupportIterator& o) const
81  {
82  return ! (*this != o);
83  }
84 
85  //Specialization for std::vector<boost::shared_ptr<std::size_t> >
86  inline
87  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::SupportIterator (const container_t* c, set_iterator it)
88  : current_(it), container_size_(c->size()), container_(c)
89  {}
90 
91  inline
92  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::handler_t
93  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator* () const
94  {
95  return handler_t(*current_);
96  }
97 
98  inline
99  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >&
100  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator++ ()
101  {
102  if (container_->size() == container_size_)
103  ++current_;
104  else
105  container_size_ = container_->size();
106  return *this;
107  }
108 
109  inline
110  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >&
111  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator-- ()
112  {
113  if (container_->size() == container_size_)
114  --current_;
115  else
116  container_size_ = container_->size();
117  return *this;
118  }
119 
120  inline
121  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >
122  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator++ (int)
123  {
124  SupportIterator<std::set<boost::shared_ptr<std::size_t> > > tmp = *this;
125  ++(*this);
126  return tmp;
127  }
128 
129  inline
130  bool
131  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator!= (const SupportIterator& o) const
132  {
133  return o.current_ != current_;
134  }
135 
136  inline
137  bool
138  SupportIterator<std::set<boost::shared_ptr<std::size_t> > >::operator== (const SupportIterator& o) const
139  {
140  return ! (*this != o);
141  }
142 
143  /*------------------.
144  | SupportIterator. |
145  `------------------*/
146 
147  //Specialization for vcsn::bmig::InitialContainer.
148  template <typename U, typename HState>
149  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >
150  ::SupportIterator (const container_t* c, container_iterator i)
151  : container_ (c)
152  {
153  if (i != c->end())
154  {
155  i_ = i++;
156  next_ = i;
157  }
158  else
159  {
160  i_ = i;
161  next_ = i;
162  }
163  }
164 
165  template <typename U, typename HState>
166  typename SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::handler_t
167  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator* () const
168  {
169  return handler_t(i_->first);
170  }
171 
172  template <typename U, typename HState>
173  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >&
174  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator++ ()
175  {
176  if (next_ != container_->end())
177  i_ = next_++;
178  else
179  i_ = next_;
180  return *this;
181  }
182 
183  template <typename U, typename HState>
184  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >
185  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator++ (int)
186  {
187  SupportIterator<vcsn::bmig::InitialContainer<U, HState> > tmp = *this;
188  ++(*this);
189  return tmp;
190  }
191 
192  template <typename U, typename HState>
193  bool
194  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator!= (const SupportIterator& o) const
195  {
196  return o.i_ != i_;
197  }
198 
199  template <typename U, typename HState>
200  bool
201  SupportIterator<vcsn::bmig::InitialContainer<U, HState> >::operator== (const SupportIterator& o) const
202  {
203  return ! (*this != o);
204  }
205 
206 
207 
208  /*----------.
209  | Support. |
210  `----------*/
211 
213  template <class U, class HState>
214  Support<vcsn::bmig::InitialContainer<U, HState> >::Support (const Support& s)
215  : m_ (s.m_)
216  {
217  }
218 
219  template <class U, class HState>
220  Support<vcsn::bmig::InitialContainer<U, HState> >::Support (const Support::container_t& m)
221  : m_ (m)
222  {
223  }
224 
225  template <class U, class HState>
226  unsigned
227  Support<vcsn::bmig::InitialContainer<U, HState> >::size () const
228  {
229  return m_.size ();
230  }
231 
232  template <class U, class HState>
233  typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
234  Support<vcsn::bmig::InitialContainer<U, HState> >::find (const HState& k) const
235  {
236  return m_.find (k.value());
237  }
238 
239  template <class U, class HState>
240  bool
241  Support<vcsn::bmig::InitialContainer<U, HState> >::empty () const
242  {
243  return m_.empty ();
244  }
245 
246  template <class U, class HState>
247  typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
248  Support<vcsn::bmig::InitialContainer<U, HState> >::begin () const
249  {
250  return iterator (&m_, m_.begin ());
251  }
252 
253  template <class U, class HState>
254  typename Support<vcsn::bmig::InitialContainer<U, HState> >::iterator
255  Support<vcsn::bmig::InitialContainer<U, HState> >::end () const
256  {
257  return iterator (&m_, m_.end ());
258  }
259 
260  template <class U, class HState>
261  typename Support<vcsn::bmig::InitialContainer<U, HState> >::handler_t
262  Support<vcsn::bmig::InitialContainer<U, HState> >::back () const
263  {
264  return handler_t(*max_element (begin (), end ()));
265  }
266 
267  }
268 }
269 
270 namespace vcsn
271 {
272  namespace misc
273  {
274 
275  /*----------.
276  | Support. |
277  `----------*/
278 
280  inline
281  Support<std::vector<boost::shared_ptr<std::size_t> > >
282  ::Support (const std::vector<boost::shared_ptr<std::size_t> >& m)
283  : m_ (m)
284  {
285  }
286 
287  inline
288  unsigned
289  Support<std::vector<boost::shared_ptr<std::size_t> > >
290  ::size () const
291  {
292  return m_.size ();
293  }
294 
295  inline
296  Support<std::vector<boost::shared_ptr<std::size_t> > >::iterator
297  Support<std::vector<boost::shared_ptr<std::size_t> > >
298  ::find (const handler<state_h, boost::shared_ptr<std::size_t> >& k) const
299  {
300  if (k < m_.size())
301  return iterator(&m_, k);
302  else
303  return iterator(&m_, m_.size());
304  }
305 
306  inline
307  bool
308  Support<std::vector<boost::shared_ptr<std::size_t> > >
309  ::empty () const
310  {
311  return m_.empty ();
312  }
313 
314  inline
315  Support<std::vector<boost::shared_ptr<std::size_t> > >::const_iterator
316  Support<std::vector<boost::shared_ptr<std::size_t> > >
317  ::begin () const
318  {
319  return iterator (&m_, 0);
320  }
321 
322  inline
323  Support<std::vector<boost::shared_ptr<std::size_t> > >::const_iterator
324  Support<std::vector<boost::shared_ptr<std::size_t> > >
325  ::end () const
326  {
327  return iterator (&m_, m_.size());
328  }
329 
330  inline
331  Support<std::vector<boost::shared_ptr<std::size_t> > >::handler_t
332  Support<std::vector<boost::shared_ptr<std::size_t> > >
333  ::back () const
334  {
335  return handler_t(m_.back());
336  }
337 
339  inline
340  Support<std::set<boost::shared_ptr<std::size_t> > >
341  ::Support (const std::set<boost::shared_ptr<std::size_t> >& m)
342  : m_ (m)
343  {
344  }
345 
346  inline
347  unsigned
348  Support<std::set<boost::shared_ptr<std::size_t> > >
349  ::size () const
350  {
351  return m_.size ();
352  }
353 
354  inline
355  Support<std::set<boost::shared_ptr<std::size_t> > >::iterator
356  Support<std::set<boost::shared_ptr<std::size_t> > >
357  ::find (const handler<state_h, boost::shared_ptr<std::size_t> >& k) const
358  {
359  return iterator(&m_, m_.find(k.value()));
360  }
361 
362  inline
363  bool
364  Support<std::set<boost::shared_ptr<std::size_t> > >
365  ::empty () const
366  {
367  return m_.empty ();
368  }
369 
370  inline
371  Support<std::set<boost::shared_ptr<std::size_t> > >::const_iterator
372  Support<std::set<boost::shared_ptr<std::size_t> > >
373  ::begin () const
374  {
375  return iterator (&m_, m_.begin());
376  }
377 
378  inline
379  Support<std::set<boost::shared_ptr<std::size_t> > >::const_iterator
380  Support<std::set<boost::shared_ptr<std::size_t> > >
381  ::end () const
382  {
383  return iterator (&m_, m_.end());
384  }
385 
386  inline
387  Support<std::set<boost::shared_ptr<std::size_t> > >::handler_t
388  Support<std::set<boost::shared_ptr<std::size_t> > >
389  ::back () const
390  {
391  //FIXME Maybe wrong! Compare pointers instead of id.
392  return handler_t(*max_element (begin (), end ()));
393  }
394 
395 
396  }
397 }
398 
399 
400 #endif // !VCSN_AUTOMATA_IMPLEMENTATION_BMIG_BMIG_SUPPORT_HXX
401