Alexandria  2.16
Please provide a description of the 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-2020 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 <vector>
29 #include <tuple>
30 #include <map>
31 #include <type_traits>
32 #include "GridContainer/GridAxis.h"
33 #include "TemplateLoopCounter.h"
34 
35 namespace Euclid {
36 namespace GridContainer {
37 
52 template<typename... Axes>
54 public:
55 
68  template<int I>
70  const TemplateLoopCounter<I>&) {
72  result.push_back(std::get<I-1>(axes).size());
73  return result;
74  }
75 
78  const TemplateLoopCounter<0>&) {
79  return std::vector<size_t>{};
80  }
81 
94  template<int I>
96  const TemplateLoopCounter<I>&) {
98  result.push_back(std::get<I-1>(axes).name());
99  return result;
100  }
101 
104  const TemplateLoopCounter<0>&) {
105  return std::vector<std::string>{};
106  }
107 
122  template<int I>
123  static size_t getAxisIndexFactor(const std::tuple<GridAxis<Axes>...>& axes,
124  const TemplateLoopCounter<I>&) {
125  return std::get<I>(axes).size() * getAxisIndexFactor(axes, TemplateLoopCounter<I-1>{});
126  }
127 
129  static size_t getAxisIndexFactor(const std::tuple<GridAxis<Axes>...>&,
130  const TemplateLoopCounter<-1>&) {
131  return 1;
132  }
133 
150  template<int I>
152  const std::tuple<GridAxis<Axes>...>& axes,const TemplateLoopCounter<I>&) {
155  return result;
156  }
157 
161  return std::vector<size_t> {1};
162  }
163 
164  template<int I>
165  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>& axes_tuple, size_t axis,
166  size_t index, const TemplateLoopCounter<I>&) {
167  if (axis == I) {
168  auto& old_axis = std::get<I>(axes_tuple);
169  typename std::remove_reference<decltype(old_axis)>::type new_axis {old_axis.name(), {old_axis[index]}};
170  std::get<I>(axes_tuple) = std::move(new_axis);
171  return;
172  }
173  findAndFixAxis(axes_tuple, axis, index, TemplateLoopCounter<I+1>{});
174  }
175 
176  static void findAndFixAxis(std::tuple<GridAxis<Axes>...>&, size_t,
177  size_t, const TemplateLoopCounter<sizeof...(Axes)>&) {
178  // does nothing
179  }
180 
181  template<typename IterType, int I>
182  static void fixIteratorAxes(IterType& iter, std::map<size_t, size_t> fix_indices,
183  const TemplateLoopCounter<I>&) {
184  auto fix_pair = fix_indices.find(I);
185  if (fix_pair != fix_indices.end()) {
186  iter.template fixAxisByIndex<I>(fix_pair->second);
187  }
188  fixIteratorAxes(iter, fix_indices, TemplateLoopCounter<I+1>{});
189  }
190 
191  template<typename IterType>
193  const TemplateLoopCounter<sizeof...(Axes)>&) {
194  // does nothing
195  }
196 
197 };
198 
199 } // end of namespace GridContainer
200 } // end of namespace Euclid
201 
202 #endif /* GRIDCONTAINER_GRIDCONSTRUCTIONHELPER_H */
203 
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)> &)