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> |
13 | class ParticleIt_CellP |
14 | { |
15 | private: |
16 | |
17 | //! Cell lisy |
18 | T & NN; |
19 | |
20 | //! Cells counter |
21 | size_t cell_count; |
22 | |
23 | //! Particles counter |
24 | long int p_count; |
25 | |
26 | |
27 | /*! \brief Handles incrementing of cells and particles counters |
28 | * |
29 | */ |
30 | inline void fp() |
31 | { |
32 | ++p_count; |
33 | |
34 | const auto & SFCkeys = NN.getCellSFC().getKeys(); |
35 | |
36 | if (p_count >= (long int)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 |
56 | ~ParticleIt_CellP() |
57 | { |
58 | } |
59 | |
60 | |
61 | |
62 | /*! \brief Get the next element |
63 | * |
64 | * \return cell list iterator |
65 | * |
66 | */ |
67 | inline ParticleIt_CellP & operator++() |
68 | { |
69 | fp(); |
70 | while (isNext() && this->get() >= NN.get_gm()) |
71 | { |
72 | fp(); |
73 | } |
74 | |
75 | return *this; |
76 | } |
77 | |
78 | |
79 | /*! \brief Checks if there is a next element |
80 | * |
81 | * \return true if there is the next, false otherwise |
82 | * |
83 | */ |
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 | |
95 | /*! \brief Get the real particle id |
96 | |
97 | * |
98 | * \return the real particle id |
99 | * |
100 | */ |
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 | |
109 | /*! \brief Reset an iterator (set the counters to the first valid ones) |
110 | * |
111 | */ |
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_ */ |
123 | |