Vaucanson  1.4.1
self_iterator.hxx
1 // support.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, 2007 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_MISC_SELF_ITERATOR_HXX
18 # define VCSN_MISC_SELF_ITERATOR_HXX
19 
21 
22 namespace vcsn
23 {
24  namespace misc
25  {
26 
27  template <template <class> class C, class T>
28  inline
29  SelfIterator<C, T>::SelfIterator (const C<T>& c)
30  : c_ (&c),
31  pos_ (c.begin ())
32  {}
33 
34  template <template <class> class C, class T>
35  inline
36  SelfIterator<C, T>::SelfIterator ()
37  : c_ (0),
38  pos_ ()
39  {}
40 
41  template <template <class> class C, class T>
42  inline
43  SelfIterator<C, T>::SelfIterator (const SelfIterator& s)
44  : c_ (s.c_),
45  pos_ (s.pos_)
46  {}
47 
48  template <template <class> class C, class T>
49  inline
50  const T&
52  {
53  return *pos_;
54  }
55 
56  template <template <class> class C, class T>
57  inline
58  const SelfIterator<C, T>&
59  SelfIterator<C, T>::operator++ ()
60  {
61  pos_++;
62  return *this;
63  }
64 
65  template <template <class> class C, class T>
66  inline
67  SelfIterator<C, T>
68  SelfIterator<C, T>::operator++ (int)
69  {
70  SelfIterator<C, T> res (*this);
71  ++pos_;
72  return res;
73  }
74 
75  template <template <class> class C, class T>
76  inline
77  bool
78  SelfIterator<C, T>::operator!= (const SelfIterator<C, T>& o) const
79  {
80  if (c_ == 0)
81  if (o.c_ == 0)
82  return false;
83  else
84  return o.pos_ != o.c_->end ();
85  else if (o.c_ == 0)
86  return pos_ != c_->end ();
87  return o.c_ != c_ || o.pos_ != pos_;
88  }
89 
90  template <template <class> class C, class T>
91  inline
92  bool
93  SelfIterator<C, T>::operator== (const SelfIterator<C, T>& o) const
94  {
95  if (c_ == 0)
96  return o.c_ == 0 || o.pos_ == o.c_->end ();
97  else if (o.c_ == 0)
98  return pos_ == c_->end ();
99  return o.c_ == c_ && o.pos_ == pos_;
100  }
101 
102  } // misc
103 } // vcsn
104 
105 #endif // ! VCSN_MISC_SELF_ITERATOR_HXX