ESyS-Particle  2.3.2
StlIterator.h
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2014 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 
14 #ifndef ESYS_LSMSTLITERATOR_H
15 #define ESYS_LSMSTLITERATOR_H
16 
17 #include <string>
18 #include <vector>
19 #include <sstream>
20 
21 namespace esys
22 {
23  namespace lsm
24  {
25  template <typename TmplIteratable>
26  class ForwardConstIterator;
27 
28  template <typename TmplIteratable>
30  {
31  public:
32  typedef typename TmplIteratable::value_type value_type;
33  typedef typename TmplIteratable::reference reference;
34  typedef typename TmplIteratable::iterator iterator;
35 
36  inline ForwardIterator(TmplIteratable &container)
37  : m_it(container.begin()),
38  m_end(container.end())
39  {
40  }
41 
42  inline ForwardIterator(const iterator &begin, const iterator &end)
43  : m_it(begin),
44  m_end(end)
45  {
46  }
47 
48  inline bool hasNext() const
49  {
50  return (m_it != m_end);
51  }
52 
53  inline reference current() const
54  {
55  iterator it = m_it;
56  it--;
57  return *(it);
58  }
59 
60  inline reference next()
61  {
62  reference ref = (*m_it);
63  m_it++;
64  return ref;
65  }
66 
67  friend class ForwardConstIterator<TmplIteratable>;
68 
69  private:
72  };
73 
74  template <typename TmplIteratable>
76  {
77  public:
78  typedef typename TmplIteratable::value_type value_type;
79  typedef typename TmplIteratable::const_reference reference;
80  typedef typename TmplIteratable::const_iterator iterator;
81 
82  inline ForwardConstIterator(const TmplIteratable &container)
83  : m_it(container.begin()),
84  m_end(container.end())
85  {
86  }
87 
88  inline ForwardConstIterator(const iterator &begin, const iterator &end)
89  : m_it(begin),
90  m_end(end)
91  {
92  }
93 
95  : m_it(it.m_it),
96  m_end(it.m_end)
97  {
98  }
99 
100  inline bool hasNext() const
101  {
102  return (m_it != m_end);
103  }
104 
105  inline reference current() const
106  {
107  iterator it = m_it;
108  it--;
109  return *(it);
110  }
111 
112  inline reference next()
113  {
114  reference ref = (*m_it);
115  m_it++;
116  return ref;
117  }
118 
119  private:
122  };
123  }
124 }
125 
126 #endif