Alexandria  2.19
Please provide a description of the project.
GridConstructionHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2021 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef GRIDCONTAINER_GRIDCONSTRUCTIONHELPER_H
26 #define GRIDCONTAINER_GRIDCONSTRUCTIONHELPER_H
27 
28 #include "GridContainer/GridAxis.h"
29 #include "TemplateLoopCounter.h"
30 #include <map>
31 #include <tuple>
32 #include <type_traits>
33 #include <vector>
34 
35 namespace Euclid {
36 namespace GridContainer {
37 
52 template <typename... Axes>
54 public:
67  template <int I>
70  result.push_back(std::get<I - 1>(axes).size());
71  return result;
72  }
73 
76  return std::vector<size_t>{};
77  }
78 
91  template <int I>
94  result.push_back(std::get<I - 1>(axes).name());
95  return result;
96  }
97 
100  return std::vector<std::string>{};
101  }
102 
117  template <int I>
118  static size_t getAxisIndexFactor(const std::tuple<GridAxis<Axes>...>& axes, const TemplateLoopCounter<I>&) {
119  return std::get<I>(axes).size() * getAxisIndexFactor(axes, TemplateLoopCounter<I - 1>{});
120  }
121 
124  return 1;
125  }
126 
143  template <int I>
147  return result;
148  }
149 
152  return std::vector<size_t>{1};
153  }
154 
155  template <int I>
156  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>& axes_tuple, size_t axis, size_t index, const TemplateLoopCounter<I>&) {
157  if (axis == I) {
158  auto& old_axis = std::get<I>(axes_tuple);
159  typename std::remove_reference<decltype(old_axis)>::type new_axis{old_axis.name(), {old_axis[index]}};
160  std::get<I>(axes_tuple) = std::move(new_axis);
161  return;
162  }
163  findAndFixAxis(axes_tuple, axis, index, TemplateLoopCounter<I + 1>{});
164  }
165 
166  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>&, size_t, size_t, const TemplateLoopCounter<sizeof...(Axes)>&) {
167  // does nothing
168  }
169 
170  template <typename IterType, int I>
171  static void fixIteratorAxes(IterType& iter, std::map<size_t, size_t> fix_indices, const TemplateLoopCounter<I>&) {
172  auto fix_pair = fix_indices.find(I);
173  if (fix_pair != fix_indices.end()) {
174  iter.template fixAxisByIndex<I>(fix_pair->second);
175  }
176  fixIteratorAxes(iter, fix_indices, TemplateLoopCounter<I + 1>{});
177  }
178 
179  template <typename IterType>
180  static void fixIteratorAxes(IterType&, std::map<size_t, size_t>, const TemplateLoopCounter<sizeof...(Axes)>&) {
181  // does nothing
182  }
183 };
184 
185 } // end of namespace GridContainer
186 } // end of namespace Euclid
187 
188 #endif /* GRIDCONTAINER_GRIDCONSTRUCTIONHELPER_H */
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
GridContainer construction helper class.
static size_t getAxisIndexFactor(const std::tuple< GridAxis< Axes >... > &, const TemplateLoopCounter<-1 > &)
Method which terminates the iteration when calculating the axis index factors.
static std::vector< std::string > createAxesNamesVector(const std::tuple< GridAxis< Axes >... > &, const TemplateLoopCounter< 0 > &)
Method which terminates the iteration when creating the axes names vector.
static size_t getAxisIndexFactor(const std::tuple< GridAxis< Axes >... > &axes, const TemplateLoopCounter< I > &)
Returns the index factor of an axis.
static void fixIteratorAxes(IterType &, std::map< size_t, size_t >, const TemplateLoopCounter< sizeof...(Axes)> &)
static std::vector< size_t > createAxisIndexFactorVector(const std::tuple< GridAxis< Axes >... > &, const TemplateLoopCounter< 0 > &)
Method which terminates the iteration when creating the axes index factors.
static std::vector< size_t > createAxisIndexFactorVector(const std::tuple< GridAxis< Axes >... > &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the index factors of the given axes.
static std::vector< std::string > createAxesNamesVector(const std::tuple< GridAxis< Axes >... > &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the names of the given axes.
static void findAndFixAxis(std::tuple< GridAxis< Axes >... > &axes_tuple, size_t axis, size_t index, const TemplateLoopCounter< I > &)
static std::vector< size_t > createAxesSizesVector(const std::tuple< GridAxis< Axes >... > &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the sizes of the given axes.
static std::vector< size_t > createAxesSizesVector(const std::tuple< GridAxis< Axes >... > &, const TemplateLoopCounter< 0 > &)
Method which terminates the iteration when creating the axes sizes vector.
static void fixIteratorAxes(IterType &iter, std::map< size_t, size_t > fix_indices, const TemplateLoopCounter< I > &)
static void findAndFixAxis(std::tuple< GridAxis< Axes >... > &, size_t, size_t, const TemplateLoopCounter< sizeof...(Axes)> &)
T end(T... args)
T find(T... args)
T move(T... args)
T push_back(T... args)