dune-grid 3.0-git
multiindex.hh
Go to the documentation of this file.
1#ifndef DUNE_GRID_UTILITY_MULTIINDEX_HH
2#define DUNE_GRID_UTILITY_MULTIINDEX_HH
3
9#include<array>
10
11namespace Dune
12{
13 namespace FactoryUtilities
14 {
15 template<std::size_t dim>
16 class MultiIndex : public std::array<unsigned int,dim>
17 {
18 // The range of each component
19 std::array<unsigned int,dim> limits_;
20
21 public:
23 MultiIndex(const std::array<unsigned int,dim>& limits) : limits_(limits)
24 {
25 std::fill(this->begin(), this->end(), 0);
26 }
27
30 {
31 for (std::size_t i=0; i<dim; i++)
32 {
33 // Augment digit
34 (*this)[i]++;
35
36 // If there is no carry-over we can stop here
37 if ((*this)[i]<limits_[i])
38 break;
39
40 (*this)[i] = 0;
41 }
42 return *this;
43 }
44
46 size_t cycle() const
47 {
48 size_t result = 1;
49 for (std::size_t i=0; i<dim; i++)
50 result *= limits_[i];
51 return result;
52 }
53 };
54 }
55}
56
57#endif
Include standard header files.
Definition agrid.hh:60
Definition multiindex.hh:17
MultiIndex(const std::array< unsigned int, dim > &limits)
Constructor with a given range for each digit.
Definition multiindex.hh:23
MultiIndex< dim > & operator++()
Increment the MultiIndex.
Definition multiindex.hh:29
size_t cycle() const
Compute how many times you can call operator++ before getting to (0,...,0) again.
Definition multiindex.hh:46