Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
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
29#include "TemplateLoopCounter.h"
30#include <map>
31#include <tuple>
32#include <type_traits>
33#include <vector>
34
35namespace Euclid {
36namespace GridContainer {
37
52template <typename... Axes>
54public:
67 template <int I>
71 result.push_back(std::get<I - 1>(axes).size());
72 return result;
73 }
74
80
93 template <int I>
97 result.push_back(std::get<I - 1>(axes).name());
98 return result;
99 }
100
106
121 template <int I>
123 return std::get<I>(axes).size() * getAxisIndexFactor(axes, TemplateLoopCounter<I - 1>{});
124 }
125
128 return 1;
129 }
130
147 template <int I>
154
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 */
Provides information related with an axis of a GridContainer.
Definition GridAxis.h:49
GridContainer construction helper class.
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< 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 >... > &, const TemplateLoopCounter<-1 > &)
Method which terminates the iteration when calculating the axis index factors.
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 >... > &axes, const TemplateLoopCounter< I > &)
Creates a vector which contains the index factors of the given axes.
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 void findAndFixAxis(std::tuple< GridAxis< Axes >... > &axes_tuple, size_t axis, size_t index, const TemplateLoopCounter< I > &)
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 fixIteratorAxes(IterType &iter, std::map< size_t, size_t > fix_indices, const TemplateLoopCounter< I > &)
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 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)