30 namespace GridContainer {
32 template <
typename GridCellManager,
typename... AxesTypes>
33 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
36 : m_owner(owner), m_data_iter{data_iter} {}
38 template <
typename GridCellManager,
typename... AxesTypes>
39 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
47 template <
typename GridCellManager,
typename... AxesTypes>
48 template <
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;
67 template <
typename GridCellManager,
typename... AxesTypes>
68 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
74 template <
typename GridCellManager,
typename... AxesTypes>
75 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
77 typename std::add_const<ReferenceType>::type {
81 template <
typename GridCellManager,
typename... AxesTypes>
82 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
85 return m_data_iter.operator->();
88 template <
typename GridCellManager,
typename... AxesTypes>
89 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
91 typename std::add_const<PointerType>::type {
92 return m_data_iter.operator->();
95 template <
typename GridCellManager,
typename... AxesTypes>
96 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
98 const iter& other)
const {
102 template <
typename GridCellManager,
typename... AxesTypes>
103 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
105 const iter& other)
const {
109 template <
typename GridCellManager,
typename... AxesTypes>
110 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
114 return m_owner.m_index_helper.axisIndex(I, index);
117 template <
typename GridCellManager,
typename... AxesTypes>
118 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
122 size_t index = axisIndex<I>();
123 return std::get<I>(m_owner.m_axes)[index];
126 template <
typename GridCellManager,
typename... AxesTypes>
127 template <
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);
144 template <
typename GridCellManager,
typename... AxesTypes>
145 template <
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();
156 return fixAxisByIndex<I>(index);
159 template <
typename GridCellManager,
typename... AxesTypes>
160 template <
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;
174 template <
typename IterFrom,
typename IterTo,
int I>
176 to.template fixAxisByValue<I>(from.template axisValue<I>());
180 template <
typename IterFrom,
typename IterTo>
183 template <
typename GridCellManager,
typename... AxesTypes>
184 template <
typename CellType,
typename Po
interType,
typename ReferenceType>
185 template <
typename OtherIter>
187 const OtherIter& other) ->
iter& {
size_t size() const
Returns the total number of cells of the grid.
std::map< size_t, size_t > m_fixed_indices
A map containing the axes which have been fixed, if this grid is a slice.
Class to iterate through the GridContainer cells.
GridContainer & operator=(GridContainer< GridCellManager, AxesTypes...> &&)=default
static iterator end(GridCellManager &cell_manager)
cell_manager_iter_type m_data_iter
bool operator!=(const Euclid::SourceCatalog::Source::id_type &a, const Euclid::SourceCatalog::Source::id_type &b)
boost::variant specifies an equality operator (==), but, in older boost versions, not an inequality o...
Representation of a multi-dimensional grid which contains axis information.
GridCellManagerTraits< GridCellManager >::iterator cell_manager_iter_type
static iterator begin(GridCellManager &cell_manager)
GridContainer< GridCellManager, AxesTypes...> fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
GridContainer< GridCellManager, AxesTypes...> fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
typename std::tuple_element< I, std::tuple< AxesTypes...>>::type axis_type
static void fixSameAxes(IterFrom &from, IterTo &to, const TemplateLoopCounter< I > &)