Alexandria  2.14.1
Please provide a description of the project.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
GridIndexHelper.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_GRIDINDEXHELPER_H
26 #define GRIDCONTAINER_GRIDINDEXHELPER_H
27 
28 #include <vector>
29 #include <tuple>
30 #include "GridContainer/GridAxis.h"
32 
33 namespace Euclid {
34 namespace GridContainer {
35 
53 template<typename... AxesTypes>
55 
56 public:
57 
65  GridIndexHelper(const std::tuple<GridAxis<AxesTypes>...>& axes_tuple);
66 
70 
72  virtual ~GridIndexHelper() = default;
73 
83  size_t axisIndex(size_t axis, size_t array_index) const;
84 
92  size_t totalIndex(decltype(std::declval<GridAxis<AxesTypes>>().size())... coords) const;
93 
103  size_t totalIndexChecked(decltype(std::declval<GridAxis<AxesTypes>>().size())... coords) const;
104 
106  template <typename Coord>
107  void checkAllFixedAreZero(const std::map<size_t, size_t>& fixed_indices, Coord coord) const;
108 
110  template <typename Coord, typename... RestCoords>
111  void checkAllFixedAreZero(const std::map<size_t, size_t>& fixed_indices,
112  Coord coord, RestCoords... rest_coords) const;
113 
117 };
118 
128 template<typename... AxesTypes>
130  return GridIndexHelper<AxesTypes...>(axes_tuple);
131 }
132 
133 } // end of namespace GridContainer
134 } // end of namespace Euclid
135 
137 
138 #endif /* GRIDCONTAINER_GRIDINDEXHELPER_H */
139 
std::vector< size_t > m_axes_index_factors
size_t totalIndex(decltype(std::declval< GridAxis< AxesTypes >>().size())...coords) const
GridIndexHelper(const std::tuple< GridAxis< AxesTypes >...> &axes_tuple)
Helper class for converting multi-dimensional grid coordinates to the index of a long data array and ...
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
std::vector< std::string > m_axes_names
T declval(T...args)
virtual ~GridIndexHelper()=default
Default destructor.
GridIndexHelper & operator=(GridIndexHelper< AxesTypes...> &&)=default
void checkAllFixedAreZero(const std::map< size_t, size_t > &fixed_indices, Coord coord) const
Checks if any of the given coordinates is fixed and not zero.
size_t totalIndexChecked(decltype(std::declval< GridAxis< AxesTypes >>().size())...coords) const
GridIndexHelper< AxesTypes...> makeGridIndexHelper(const std::tuple< GridAxis< AxesTypes >...> &axes_tuple)
size_t axisIndex(size_t axis, size_t array_index) const