Alexandria  2.27.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
69  const TemplateLoopCounter<I>&) {
71  result.push_back(std::get<I - 1>(axes).size());
72  return result;
73  }
74 
77  const TemplateLoopCounter<0>&) {
78  return std::vector<size_t>{};
79  }
80 
93  template <int I>
95  const TemplateLoopCounter<I>&) {
97  result.push_back(std::get<I - 1>(axes).name());
98  return result;
99  }
100 
103  const TemplateLoopCounter<0>&) {
104  return std::vector<std::string>{};
105  }
106 
121  template <int I>
122  static size_t getAxisIndexFactor(const std::tuple<GridAxis<Axes>...>& axes, const TemplateLoopCounter<I>&) {
123  return std::get<I>(axes).size() * getAxisIndexFactor(axes, TemplateLoopCounter<I - 1>{});
124  }
125 
128  return 1;
129  }
130 
147  template <int I>
149  const TemplateLoopCounter<I>&) {
152  return result;
153  }
154 
157  const TemplateLoopCounter<0>&) {
158  return std::vector<size_t>{1};
159  }
160 
161  template <int I>
162  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>& axes_tuple, size_t axis, size_t index,
163  const TemplateLoopCounter<I>&) {
164  if (axis == I) {
165  auto& old_axis = std::get<I>(axes_tuple);
166  typename std::remove_reference<decltype(old_axis)>::type new_axis{old_axis.name(), {old_axis[index]}};
167  std::get<I>(axes_tuple) = std::move(new_axis);
168  return;
169  }
170  findAndFixAxis(axes_tuple, axis, index, TemplateLoopCounter<I + 1>{});
171  }
172 
173  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>&, size_t, size_t,
174  const TemplateLoopCounter<sizeof...(Axes)>&) {
175  // does nothing
176  }
177 
178  template <typename IterType, int I>
179  static void fixIteratorAxes(IterType& iter, std::map<size_t, size_t> fix_indices, const TemplateLoopCounter<I>&) {
180  auto fix_pair = fix_indices.find(I);
181  if (fix_pair != fix_indices.end()) {
182  iter.template fixAxisByIndex<I>(fix_pair->second);
183  }
184  fixIteratorAxes(iter, fix_indices, TemplateLoopCounter<I + 1>{});
185  }
186 
187  template <typename IterType>
188  static void fixIteratorAxes(IterType&, std::map<size_t, size_t>, const TemplateLoopCounter<sizeof...(Axes)>&) {
189  // does nothing
190  }
191 };
192 
193 } // end of namespace GridContainer
194 } // end of namespace Euclid
195 
196 #endif /* GRIDCONTAINER_GRIDCONSTRUCTIONHELPER_H */
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< std::string > createAxesNamesVector(const std::tuple< GridAxis< Axes >...> &, const TemplateLoopCounter< 0 > &)
Method which terminates the iteration when creating the axes names vector.
T end(T...args)
static size_t getAxisIndexFactor(const std::tuple< GridAxis< Axes >...> &axes, const TemplateLoopCounter< I > &)
Returns the index factor of an axis.
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 >...> &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the names of the given axes.
T push_back(T...args)
static void fixIteratorAxes(IterType &iter, std::map< size_t, size_t > fix_indices, const TemplateLoopCounter< I > &)
static void fixIteratorAxes(IterType &, std::map< size_t, size_t >, const TemplateLoopCounter< sizeof...(Axes)> &)
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
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 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.
T move(T...args)
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.
T find(T...args)
GridContainer construction helper class.
static void findAndFixAxis(std::tuple< GridAxis< Axes >...> &axes_tuple, size_t axis, size_t index, const TemplateLoopCounter< I > &)
static void findAndFixAxis(std::tuple< GridAxis< Axes >...> &, size_t, size_t, const TemplateLoopCounter< sizeof...(Axes)> &)