Simpatico  v1.10
PArrayIterator.h
1 #ifndef UTIL_P_ARRAY_ITERATOR_H
2 #define UTIL_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>
34  class PArrayIterator
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  Data* get() const
101  { return data_; }
102 
104 
105 
111  Data& operator* () const
112  {
113  assert(data_);
114  return *data_;
115  }
116 
122  Data* operator -> () const
123  {
124  assert(data_);
125  return data_;
126  }
127 
134  {
135  assert(current_);
136  ++current_;
137  if (current_ != end_) {
138  data_ = *current_;
139  } else {
140  data_ = 0;
141  }
142  return *this;
143  }
144 
146 
147  private:
148 
149  // Pointer to the current Data* pointer.
150  Data** current_;
151 
152  // Pointer to one element one past last Data* pointer in the set.
153  Data** end_;
154 
155  // Pointer to current Data object.
156  Data* data_;
157 
158  };
159 
160 }
161 #endif
bool isEnd() const
Is the current pointer at the end of the PArray?
Data & operator*() const
Return a reference to the current Data.
PArrayIterator< Data > & operator++()
Increment the current pointer.
void setEnd(Data **ptr)
Set the value of the end pointer.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
Data * operator->() const
Provide a pointer to the current Data object.
Forward iterator for a PArray.
Definition: ArraySet.h:19
void setNull()
Nullify the iterator.
PArrayIterator()
Default constructor.
void setCurrent(Data **ptr)
Set the current pointer value.