OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
CellListIterator.hpp
1 
2 /*
3  * CellListIt.hpp
4  *
5  * Created on: May 18, 2016
6  * Author: Yaroslav Zaluzhnyi
7  */
8 
9 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
10 #define OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_
11 
12 template<typename T>
14 {
15 private:
16 
18  T & NN;
19 
21  size_t cell_count;
22 
24  size_t p_count;
25 
26 
30  inline void fp()
31  {
32  ++p_count;
33 
34  const auto & SFCkeys = NN.getCellSFC().getKeys();
35 
36  if (p_count >= NN.getNelements(SFCkeys.get(cell_count)))
37  {
38  p_count = 0;
39  ++cell_count;
40 
41  while (cell_count < SFCkeys.size() && NN.getNelements(SFCkeys.get(cell_count)) == 0)
42  ++cell_count;
43  }
44  }
45 
46 public:
47 
48  // Constructor
49  ParticleIt_CellP(T & NN)
50  :NN(NN)
51  {
52  reset();
53  }
54 
55  // Destructor
57  {
58  }
59 
60 
61 
68  {
69  fp();
70  while (isNext() && this->get() >= NN.get_gm())
71  {
72  fp();
73  }
74 
75  return *this;
76  }
77 
78 
84  inline bool isNext()
85  {
86  if (cell_count >= NN.getCellSFC().getKeys().size())
87  {
88  return false;
89  }
90 
91  return true;
92  }
93 
94 
101  inline size_t get()
102  {
103  auto cell_id = NN.getCellSFC().getKeys().get(cell_count);
104  auto p = NN.get(cell_id,p_count);
105 
106  return p;
107  }
108 
112  void reset()
113  {
114  cell_count = 0;
115  p_count = -1;
116 
117  this->operator++();
118  }
119 };
120 
121 
122 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_CELLLISTITERATOR_HPP_ */
size_t cell_count
Cells counter.
T & NN
Cell lisy.
void fp()
Handles incrementing of cells and particles counters.
bool isNext()
Checks if there is a next element.
void reset()
Reset an iterator (set the counters to the first valid ones)
size_t p_count
Particles counter.
ParticleIt_CellP & operator++()
Get the next element.