25#include "ElementsKernel/Exception.h"
30namespace GridContainer {
32template <
typename GridCellManager,
typename... AxesTypes>
33template <
typename CellType,
typename Po
interType,
typename ReferenceType>
36 : m_owner(owner), m_data_iter{data_iter} {}
38template <
typename GridCellManager,
typename... AxesTypes>
39template <
typename CellType,
typename Po
interType,
typename ReferenceType>
47template <
typename GridCellManager,
typename... AxesTypes>
48template <
typename CellType,
typename Po
interType,
typename ReferenceType>
53 size_t axis = fixed_index_pair.first;
54 size_t fixed_index = fixed_index_pair.second;
55 forwardToIndex(axis, fixed_index);
60 if (m_data_iter > end_iter) {
61 m_data_iter = end_iter;
67template <
typename GridCellManager,
typename... AxesTypes>
68template <
typename CellType,
typename Po
interType,
typename ReferenceType>
74template <
typename GridCellManager,
typename... AxesTypes>
75template <
typename CellType,
typename Po
interType,
typename ReferenceType>
77 typename
std::add_const<ReferenceType>::type {
81template <
typename GridCellManager,
typename... AxesTypes>
82template <
typename CellType,
typename Po
interType,
typename ReferenceType>
85 return m_data_iter.operator->();
88template <
typename GridCellManager,
typename... AxesTypes>
89template <
typename CellType,
typename Po
interType,
typename ReferenceType>
91 typename
std::add_const<PointerType>::type {
92 return m_data_iter.operator->();
95template <
typename GridCellManager,
typename... AxesTypes>
96template <
typename CellType,
typename Po
interType,
typename ReferenceType>
98 const iter& other)
const {
102template <
typename GridCellManager,
typename... AxesTypes>
103template <
typename CellType,
typename Po
interType,
typename ReferenceType>
105 const iter& other)
const {
109template <
typename GridCellManager,
typename... AxesTypes>
110template <
typename CellType,
typename Po
interType,
typename ReferenceType>
114 return m_owner.m_index_helper.axisIndex(I, index);
117template <
typename GridCellManager,
typename... AxesTypes>
118template <
typename CellType,
typename Po
interType,
typename ReferenceType>
122 size_t index = axisIndex<I>();
123 return std::get<I>(m_owner.m_axes)[index];
126template <
typename GridCellManager,
typename... AxesTypes>
127template <
typename CellType,
typename Po
interType,
typename ReferenceType>
130 size_t index) ->
iter& {
133 throw Elements::Exception() <<
"Axis " << m_owner.getOriginalAxis<I>().name() <<
" is already fixed";
135 if (index >= m_owner.getOriginalAxis<I>().size()) {
136 throw Elements::Exception() <<
"Index (" << index <<
") out of axis " << m_owner.getOriginalAxis<I>().name()
137 <<
" size (" << m_owner.getOriginalAxis<I>().
size() <<
")";
140 forwardToIndex(I, index);
144template <
typename GridCellManager,
typename... AxesTypes>
145template <
typename CellType,
typename Po
interType,
typename ReferenceType>
149 auto& axis = m_owner.getOriginalAxis<I>();
150 auto found_axis =
std::find(axis.begin(), axis.end(), value);
151 if (found_axis == axis.end()) {
152 throw Elements::Exception() <<
"Failed to fix axis " << m_owner.getOriginalAxis<I>().name()
153 <<
" (given value not found)";
155 size_t index = found_axis - axis.begin();
159template <
typename GridCellManager,
typename... AxesTypes>
160template <
typename CellType,
typename Po
interType,
typename ReferenceType>
162 size_t axis,
size_t fixed_index) {
164 size_t current_index = m_owner.m_index_helper.axisIndex(axis, current_size);
165 if (fixed_index != current_index) {
166 size_t axis_factor = m_owner.m_index_helper.m_axes_index_factors[axis];
167 size_t distance = (fixed_index > current_index)
168 ? fixed_index - current_index
169 : m_owner.m_index_helper.m_axes_sizes[axis] + fixed_index - current_index;
170 m_data_iter += distance * axis_factor;
174template <
typename IterFrom,
typename IterTo,
int I>
180template <
typename IterFrom,
typename IterTo>
183template <
typename GridCellManager,
typename... AxesTypes>
184template <
typename CellType,
typename Po
interType,
typename ReferenceType>
185template <
typename OtherIter>
187 const OtherIter& other) ->
iter& {
Class to iterate through the GridContainer cells.
cell_manager_iter_type m_data_iter
Representation of a multi-dimensional grid which contains axis information.
GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
GridContainer & operator=(GridContainer< GridCellManager, AxesTypes... > &&)=default
GridCellManagerTraits< GridCellManager >::iterator cell_manager_iter_type
size_t size() const
Returns the total number of cells of the grid.
typename std::tuple_element< I, std::tuple< AxesTypes... > >::type axis_type
std::map< size_t, size_t > m_fixed_indices
A map containing the axes which have been fixed, if this grid is a slice.
GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
static void fixSameAxes(IterFrom &from, IterTo &to, const TemplateLoopCounter< I > &)
static iterator end(GridCellManager &cell_manager)
static iterator begin(GridCellManager &cell_manager)