1 | /* |
2 | * grid_key_dx_iterator_sp.hpp |
3 | * |
4 | * Created on: Dec 15, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SP_HPP_ |
9 | #define OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SP_HPP_ |
10 | |
11 | |
12 | |
13 | /** |
14 | * |
15 | * Grid key class iterator, iterate through a starting linearized grid element |
16 | * to a stop linearized grid element in particular if linearize is the function |
17 | * that linearize all the grid_key_dx, it create an iterator that pass through |
18 | * Linearize^(-1)(start) Linearize^(-1)(start+1) ....... Linearize^(-1)(stop) |
19 | * |
20 | * \param dim dimensionality of the grid |
21 | * |
22 | * Usage: In general you never create object directly, but you get it from a grid_cpu or grid_gpu with |
23 | * getIteratorLinStartStop() |
24 | * |
25 | */ |
26 | |
27 | template<unsigned int dim> |
28 | class grid_key_dx_iterator_sp : public grid_key_dx_iterator<dim> |
29 | { |
30 | //! stop point |
31 | grid_key_dx<dim> gk_stop; |
32 | |
33 | public: |
34 | |
35 | /*! \brief Constructor require a grid grid<dim,T> |
36 | * |
37 | * It construct an iterator from one index to another, in particular |
38 | * if linearize is the function that linearize all the grid_key, it |
39 | * create an iterator that pass through Linearize^(-1)(start) |
40 | * Linearize^(-1)(start+1) ....... Linearize^(-1)(stop) |
41 | * |
42 | * For example for start (1,1) and stop (3,3) the point indicated with # are |
43 | * explored by the iterator |
44 | * |
45 | * \verbatim |
46 | * |
47 | +-----+-----+-----+-----+-----+-----+ (6,5) |
48 | | | | | | | | |
49 | | | | | | | | |
50 | | | | | | | | |
51 | +-----+-----+-----+-----+-----+-----+ |
52 | | | | | | | | |
53 | | | | | | | | |
54 | | | | | | | | |
55 | #-----#-----#-----#-----+-----+-----+ |
56 | | | | | | | | |
57 | | | | | | | | |
58 | | | | | | | | |
59 | #-----#-----#-----#-----#-----#-----# |
60 | | | | | | | | |
61 | | | | | | | | |
62 | +-----#-----#-----#-----#-----#-----# |
63 | | | | | | | | |
64 | | | | | | | | |
65 | | | | | | | | |
66 | +-----+-----+-----+-----+-----+-----+ |
67 | (0,0) |
68 | * |
69 | * |
70 | * \endverbatim |
71 | * |
72 | * |
73 | * \tparam T type of object that the grid store |
74 | * |
75 | * \param g Grid on which iterate |
76 | * \param from starting point |
77 | * \param to end point |
78 | * |
79 | */ |
80 | template<typename T> grid_key_dx_iterator_sp(grid_sm<dim,T> & g, mem_id from, mem_id to) |
81 | :grid_key_dx_iterator<dim>(g) |
82 | { |
83 | //! Convert to a grid_key |
84 | this->gk = g.InvLinId(from); |
85 | |
86 | //! Convert to a grid_key |
87 | gk_stop = g.InvLinId(to); |
88 | } |
89 | |
90 | /*! \brief Check if there is the next element |
91 | * |
92 | * Check if there is the next element |
93 | * |
94 | * \return true if there is the next, false otherwise |
95 | * |
96 | */ |
97 | |
98 | bool isNext() |
99 | { |
100 | //! for all dimensions |
101 | for (int i = dim-1 ; i >= 0 ; i-- ) |
102 | { |
103 | //! check if we still have points |
104 | if (this->gk.get(i) < gk_stop.get(i)) |
105 | return true; |
106 | else if (this->gk.get(i) > gk_stop.get(i)) |
107 | return false; |
108 | } |
109 | |
110 | //! (Final point) we we still have one point |
111 | return true; |
112 | } |
113 | }; |
114 | |
115 | |
116 | #endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SP_HPP_ */ |
117 | |