Alexandria  2.19
Please provide a description of the project.
GridContainer.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_GRIDCONTAINER_H
26 #define GRIDCONTAINER_GRIDCONTAINER_H
27 
31 #include <iterator>
32 #include <map>
33 #include <memory>
34 #include <tuple>
35 #include <type_traits>
36 
37 namespace Euclid {
38 namespace GridContainer {
39 
96 template <typename GridCellManager, typename... AxesTypes>
98 
99  // The following aliases are used to simplify the definitions inside the class
101 
102 public:
105 
108 
109  // The following is a shortcut to retrieve the type of each axis
110  template <int I>
111  using axis_type = typename std::tuple_element<I, std::tuple<AxesTypes...>>::type;
112 
113  // The iterator type of the GridContainer. See at the end of the file for its declaration
114  template <typename CellType>
115  class iter;
116 
119 
129 
138  explicit GridContainer(std::tuple<GridAxis<AxesTypes>...> axes_tuple);
139 
143 
144  // Do not allow copying of GridContainer objects. This is done because these
145  // objects will most of the time be very big and copying them will be a
146  // bottleneck. To avoid unvoluntary copy constructor calls, this constructor
147  // is deleted.
150 
152  virtual ~GridContainer() = default;
153 
155  static constexpr size_t axisNumber();
156 
162  template <int I>
164 
167 
170 
173 
176 
179 
182 
185 
187  size_t size() const;
188 
199  const cell_type& operator()(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
200 
203 
216  const cell_type& at(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
217 
219  cell_type& at(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices);
220 
239  template <int I>
240  GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index);
241 
274  template <int I>
275  const GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index) const;
276 
295  template <int I>
296  GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value);
297 
330  template <int I>
331  const GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value) const;
332 
333 private:
347 
358  GridContainer(const GridContainer<GridCellManager, AxesTypes...>& other, size_t axis, size_t index);
359 
363  template <int I>
365 
366 }; // end of class GridContainer
367 
381 template <typename GridCellManager, typename... AxesTypes>
382 template <typename CellType>
383 class GridContainer<GridCellManager, AxesTypes...>::iter : public std::iterator<std::forward_iterator_tag, CellType> {
384 public:
395 
397  iter(const iter<CellType>&) = default;
398 
400  iter(iter<CellType>&&) = default;
401 
403  iter& operator=(const iter& other);
404 
407 
409  CellType& operator*();
410 
413 
415  CellType* operator->();
416 
419 
422  bool operator==(const iter& other) const;
423 
426  bool operator!=(const iter& other) const;
427 
430  template <int I>
431  size_t axisIndex() const;
432 
435  template <int I>
436  const axis_type<I>& axisValue() const;
437 
451  template <int I>
452  iter& fixAxisByIndex(size_t index);
453 
471  template <int I>
473 
483  template <typename OtherIter>
484  iter& fixAllAxes(const OtherIter& other);
485 
486 private:
487  const GridContainer<GridCellManager, AxesTypes...>& m_owner;
490  void forwardToIndex(size_t axis, size_t fixed_index);
491 
492 }; // end of class iter
493 
494 } // end of namespace GridContainer
495 } // end of namespace Euclid
496 
499 
500 #endif /* GRIDCONTAINER_GRIDCONTAINER_H */
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
GridContainer construction helper class.
Class to iterate through the GridContainer cells.
iter & operator=(const iter &other)
Copy operator of the iterator.
iter(const iter< CellType > &)=default
Copy constructor.
CellType & operator*()
Returns a reference to the cell value.
const GridContainer< GridCellManager, AxesTypes... > & m_owner
std::map< size_t, size_t > m_fixed_indices
iter & fixAllAxes(const OtherIter &other)
const axis_type< I > & axisValue() const
bool operator!=(const iter &other) const
iter(iter< CellType > &&)=default
Move constructor.
iter & operator++()
Moves the iterator to the next grid cell.
CellType * operator->()
Returns a pointer to the cell value.
std::add_const< CellType >::type & operator*() const
Returns a reference to the cell value (const version)
iter & fixAxisByValue(const axis_type< I > &value)
std::add_const< CellType >::type * operator->() const
Returns a pointer to the cell value (const version)
iter(const GridContainer< GridCellManager, AxesTypes... > &owner, const cell_manager_iter_type &data_iter)
Constructs a new iterator for the given grid.
bool operator==(const iter &other) const
void forwardToIndex(size_t axis, size_t fixed_index)
Representation of a multi-dimensional grid which contains axis information.
Definition: GridContainer.h:97
const_iterator cend()
Returns a constant iterator to the cell after the last of the grid.
const GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index) const
const version of the fixAxisByIndex(size_t) method
std::shared_ptr< GridCellManager > m_cell_manager
A pointer to the data of the grid.
GridContainer(GridContainer< GridCellManager, AxesTypes... > &&)=default
Default move constructor and move assignment operator.
GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
std::tuple< GridAxis< AxesTypes >... > m_axes
A tuple containing the axes of the grid.
GridContainer(std::tuple< GridAxis< AxesTypes >... > axes_tuple)
Constructs a GridContainer with the given axes.
GridContainer(const GridContainer< GridCellManager, AxesTypes... > &other, size_t axis, size_t index)
Slice constructor.
virtual ~GridContainer()=default
Default destructor.
typename std::tuple_element< I, std::tuple< AxesTypes... > >::type axis_type
const GridAxis< axis_type< I > > & getAxis() const
GridContainer(const GridContainer< GridCellManager, AxesTypes... > &)=delete
cell_type & operator()(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices)
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const
const cell_type & at(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices) const
GridCellManagerTraits< GridCellManager >::iterator cell_manager_iter_type
const_iterator end() const
Returns an iterator to the cell after the last of the grid.
const cell_type & operator()(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices) const
iter< cell_type const > const_iterator
GridContainer & operator=(GridContainer< GridCellManager, AxesTypes... > &&)=default
std::tuple< GridAxis< AxesTypes >... > m_axes_fixed
a tuple containing the original axes of the full grid, if this grid is a slice
const_iterator cbegin()
Returns a constant iterator to the first cell of the grid.
iterator end()
Returns an iterator to the cell after the last of the grid.
size_t size() const
Returns the total number of cells of the grid.
const GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value) const
const version of the fixAxisByValue(const axis_type<I>&) method
GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
const_iterator begin() const
Returns an iterator to the first cell of the grid.
static constexpr size_t axisNumber()
Returns the number of axes of the grid (dimensionality)
std::tuple< GridAxis< AxesTypes >... > AxesTuple
The type of the tuple keeping the axes of the grid.
cell_type & at(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices)
GridContainer & operator=(const GridContainer< GridCellManager, AxesTypes... > &)=delete
GridContainer(GridAxis< AxesTypes >... axes)
Constructs a GridContainer with the given axes.
const GridAxis< axis_type< I > > & getOriginalAxis() const
std::map< size_t, size_t > m_fixed_indices
A map containing the axes which have been fixed, if this grid is a slice.
GridCellManagerTraits< GridCellManager >::data_type cell_type
The type of the values stored in the grid cells.
iterator begin()
Returns an iterator to the first cell of the grid.
GridIndexHelper< AxesTypes... > m_index_helper_fixed
a helper class for calculations of the original axes indices
GridIndexHelper< AxesTypes... > m_index_helper
A helper class used for calculations of the axes indices.
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
Helper class for converting multi-dimensional grid coordinates to the index of a long data array and ...
T declval(T... args)
GridCellManager::data_type data_type
The type of the data kept by the GridCellManager.
static std::unique_ptr< GridCellManager > factory(size_t size)