Simpatico  v1.10
mcMd/neighbor/PairIterator.h
1 #ifndef MCMD_PAIR_ITERATOR_H
2 #define MCMD_PAIR_ITERATOR_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
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 #include "PairList.h"
12 #include <util/global.h>
13 
14 namespace McMd
15 {
16 
17  using namespace Util;
18 
19  class Atom;
20 
49  {
50 
51  public:
52 
59  PairIterator();
60 
69  PairIterator(const PairList &pairList);
70 
71  // Use default C++ destructor.
72 
76  PairIterator& operator++ ();
77 
84  bool isEnd() const;
85 
92  bool notEnd() const;
93 
100  void getPair(Atom* &atom1Ptr, Atom* &atom2Ptr) const;
101 
102  private:
103 
105  Atom* const * atom1Ptrs_;
106 
108  Atom* const * atom2Ptrs_;
109 
111  const int * first_;
112 
114  int nAtom1_;
115 
117  int nAtom2_;
118 
120  int atom1Id_;
121 
123  int atom2Id_;
124 
125  //friend:
126 
127  friend class PairList;
128 
129  }; // end class PairIterator
130 
131 
132  /*
133  * Default constructor.
134  */
136  : atom1Ptrs_(0),
137  atom2Ptrs_(0),
138  first_(0),
139  nAtom1_(0),
140  nAtom2_(0),
141  atom1Id_(0),
142  atom2Id_(0)
143  {}
144 
145  /*
146  * Constructor, initialized iterator.
147  */
148  inline PairIterator::PairIterator(const PairList &pairList)
149  : atom1Ptrs_(0),
150  atom2Ptrs_(0),
151  first_(0),
152  nAtom1_(0),
153  nAtom2_(0),
154  atom1Id_(0),
155  atom2Id_(0)
156  { pairList.begin(*this); }
157 
158  /*
159  * Get pointers to current pair of Atoms.
160  */
161  inline void PairIterator::getPair(Atom* &atom1Ptr, Atom* &atom2Ptr) const
162  {
163  assert(atom1Id_ >=0);
164  assert(atom1Id_ < nAtom1_);
165  assert(atom2Id_ >=0);
166  assert(atom2Id_ < nAtom2_);
167  atom1Ptr = atom1Ptrs_[atom1Id_];
168  atom2Ptr = atom2Ptrs_[atom2Id_];
169  }
170 
171  /*
172  * Increment current pair.
173  */
175  {
176  assert(atom1Id_ >=0);
177  assert(atom1Id_ < nAtom1_);
178  assert(atom2Id_ >=0);
179  assert(atom2Id_ < nAtom2_);
180  ++atom2Id_;
181  if (atom2Id_ == first_[atom1Id_+1]) {
182  ++atom1Id_;
183  }
184  return *this;
185  }
186 
187  /*
188  * Return true if at end of the pair list.
189  */
190  inline bool PairIterator::isEnd() const
191  { return (atom2Id_ == nAtom2_); }
192 
193  /*
194  * Return true if not at end of pair list.
195  */
196  inline bool PairIterator::notEnd() const
197  { return (atom2Id_ != nAtom2_); }
198 
199 
200 }
201 #endif
PairIterator & operator++()
Increment to next pair.
A Verlet neighbor list.
bool isEnd() const
Return true if at end of PairList.
File containing preprocessor macros for error handling.
void getPair(Atom *&atom1Ptr, Atom *&atom2Ptr) const
Get pointers for current pair of Atoms.
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Iterator for pairs in a PairList.
void begin(PairIterator &iterator) const
Initialize a PairIterator.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
PairIterator()
Default constructor.
bool notEnd() const
Return true if not at end of PairList.