OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_key_dx_iterator.hpp
1 /*
2  * grid_key_dx_iterator.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_HPP_
9 #define OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_HPP_
10 
11 
12 
26 template<unsigned int dim>
28 {
29 #ifdef DEBUG
30  // Actual status of the iterator, when the iterator is not initialized cannot be used
31  // and reinitialize must be called
32  bool initialized = false;
33 #endif
34 
35  grid_sm<dim,void> grid_base;
36 
45  size_t get_gk(size_t i) const
46  {
47  return gk.get(i);
48  }
49 
50 protected:
51 
53 
54 public:
55 
63  {
64 #ifdef DEBUG
65  initialized = false;
66 #endif
67  }
68 
74  : grid_base(g_it.grid_base)
75  {
77 
78  for (size_t i = 0 ; i < dim ; i++)
79  {
80  gk.set_d(i,g_it.get_gk(i));
81  }
82 
83 #ifdef DEBUG
84  initialized = true;
85 #endif
86  }
87 
92  template<typename T> grid_key_dx_iterator(const grid_sm<dim,T> & g)
93  : grid_base(g)
94  {
95  reset();
96 
97 #ifdef DEBUG
98  initialized = true;
99 #endif
100  }
101 
107  {
108  grid_base = key_it.grid_base;
109 
111 
112  for (size_t i = 0 ; i < dim ; i++)
113  {gk.set_d(i,key_it.get_gk(i));}
114 
115  return *this;
116  }
117 
125  {
127 
128  size_t id = gk.get(0);
129  gk.set_d(0,id+1);
130 
132 
133  size_t i = 0;
134  for ( ; i < dim-1 ; i++)
135  {
136  size_t id = gk.get(i);
137  if (id >= grid_base.size(i))
138  {
139  // ! overflow, increment the next index
140 
141  gk.set_d(i,0);
142  id = gk.get(i+1);
143  gk.set_d(i+1,id+1);
144  }
145  else
146  {
147  break;
148  }
149  }
150 
151  return *this;
152  }
153 
162  void set(int d, size_t sz)
163  {
164  // set the counter dim to sz
165 
166  gk.set_d(d,sz);
167  }
168 
177  bool isNext()
178  {
179  if (gk.get(dim-1) < (long int)grid_base.size(dim-1))
180  {
182 
183  return true;
184  }
185 
187  return false;
188  }
189 
197  const grid_key_dx<dim> & get()
198  {
199  return gk;
200  }
201 
208  {
209  grid_base = key.grid_base;
210  reset();
211  }
212 
216  void reset()
217  {
219 
220  for (size_t i = 0 ; i < dim ; i++)
221  {gk.set_d(i,0);}
222  }
223 };
224 
225 
226 #endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_HPP_ */
void reinitialize(const grid_key_dx_iterator< dim > &key)
Reinitialize the grid_key_dx_iterator.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:552
size_t get_gk(size_t i) const
return the index i of the gk key
void set(int d, size_t sz)
Set the dimension.
void reset()
Reset the iterator (it restart from the beginning)
grid_key_dx_iterator()
Default constructor.
bool isNext()
Check if there is the next element.
grid_key_dx_iterator< dim > operator=(const grid_key_dx_iterator< dim > &key_it)
Constructor from another grid_key_dx_iterator.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
grid_key_dx_iterator< dim > & operator++()
Get the next element.
grid_key_dx_iterator(const grid_key_dx_iterator< dim > &g_it)
Constructor from a grid_key_dx_iterator<dim>
grid_key_dx_iterator(const grid_sm< dim, T > &g)
Constructor require a grid_sm<dim,T>