Simpatico  v1.10
ConstPArrayIterator.h
1 #ifndef UTIL_CONST_P_ARRAY_ITERATOR_H
2 #define UTIL_CONST_P_ARRAY_ITERATOR_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 namespace Util
12 {
13 
33  template <typename Data>
35  {
36 
37  public:
38 
45  : current_(0),
46  end_(0),
47  data_(0)
48  {}
49 
55  void setCurrent(Data** ptr)
56  {
57  current_ = ptr;
58  data_ = *ptr;
59  }
60 
66  void setEnd(Data** ptr)
67  { end_ = ptr; }
68 
72  void setNull()
73  {
74  current_ = 0;
75  end_ = 0;
76  data_ = 0;
77  }
78 
84  bool isEnd() const
85  { return (current_ == end_); }
86 
92  bool notEnd() const
93  { return (current_ != end_); }
94 
100  const Data* get() const
101  { return data_; }
102 
104 
105 
111  const Data& operator* () const
112  { return *data_; }
113 
119  const Data* operator -> () const
120  { return data_; }
121 
128  {
129  ++current_;
130  if (current_ != end_) {
131  data_ = *current_;
132  } else {
133  data_ = 0;
134  }
135  return *this;
136  }
137 
139 
140  private:
141 
142  // Pointer to the current Data* pointer.
143  Data** current_;
144 
145  // Pointer to one element one past last Data* pointer in the array.
146  Data** end_;
147 
148  // Pointer to current Data object.
149  Data* data_;
150 
151  };
152 
153 }
154 #endif
Forward iterator for a PArray.
void setCurrent(Data **ptr)
Set the current pointer value.
void setNull()
Nullify the iterator.
const Data * operator->() const
Provide a pointer to the current Data object.
ConstPArrayIterator()
Default constructor.
Utility classes for scientific computation.
Definition: accumulators.mod:1
const Data & operator*() const
Return a const refererence to the current Data.
bool notEnd() const
Is the current pointer not at the end of the array?
bool isEnd() const
Is the current pointer at the end of the array.
void setEnd(Data **ptr)
Set the value of the end pointer.
ConstPArrayIterator< Data > & operator++()
Increment the current pointer.