Alexandria  2.16
Please provide a description of the project.
GridContainer.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_GRIDCONTAINER_H
26 #define GRIDCONTAINER_GRIDCONTAINER_H
27 
28 #include <memory>
29 #include <tuple>
30 #include <iterator>
31 #include <map>
32 #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:
103 
106 
109 
110  // The following is a shortcut to retrieve the type of each axis
111  template<int I>
112  using axis_type = typename std::tuple_element<I, std::tuple<AxesTypes...>>::type;
113 
114  // The iterator type of the GridContainer. See at the end of the file for its declaration
115  template<typename CellType>
116  class iter;
117 
118  typedef iter<cell_type> iterator;
119  typedef iter<cell_type const> const_iterator;
120 
130 
139  explicit GridContainer(std::tuple<GridAxis<AxesTypes>...> axes_tuple);
140 
144 
145 
146  // Do not allow copying of GridContainer objects. This is done because these
147  // objects will most of the time be very big and copying them will be a
148  // bottleneck. To avoid unvoluntary copy constructor calls, this constructor
149  // is deleted.
152 
154  virtual ~GridContainer() = default;
155 
157  static constexpr size_t axisNumber();
158 
164  template<int I>
166 
169 
172 
175 
178 
181 
184 
187 
189  size_t size() const;
190 
201  const cell_type& operator()(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
202 
205 
218  const cell_type& at(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
219 
221  cell_type& at(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices);
222 
241  template <int I>
242  GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index);
243 
276  template <int I>
277  const GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index) const;
278 
297  template <int I>
298  GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value);
299 
332  template <int I>
333  const GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value) const;
334 
335 private:
336 
351  m_axes, TemplateLoopCounter<sizeof...(AxesTypes)-1>{}))
352  };
353 
364  GridContainer(const GridContainer<GridCellManager, AxesTypes...>& other, size_t axis, size_t index);
365 
369  template<int I>
371 
372 }; // end of class GridContainer
373 
374 
388 template<typename GridCellManager, typename... AxesTypes>
389 template<typename CellType>
390 class GridContainer<GridCellManager, AxesTypes...>::iter : public std::iterator<std::forward_iterator_tag, CellType> {
391 public:
392 
403  const cell_manager_iter_type& data_iter);
404 
406  iter(const iter<CellType>&) = default;
407 
409  iter(iter<CellType>&&) = default;
410 
412  iter& operator=(const iter& other);
413 
416 
418  CellType& operator*();
419 
422 
424  CellType* operator->();
425 
428 
431  bool operator==(const iter& other) const;
432 
435  bool operator!=(const iter& other) const;
436 
439  template<int I>
440  size_t axisIndex() const;
441 
444  template<int I>
445  const axis_type<I>& axisValue() const;
446 
460  template<int I>
461  iter& fixAxisByIndex(size_t index);
462 
480  template<int I>
482 
492  template<typename OtherIter>
493  iter& fixAllAxes(const OtherIter& other);
494 
495 private:
496 
497  const GridContainer<GridCellManager, AxesTypes...>& m_owner;
500  void forwardToIndex(size_t axis, size_t fixed_index);
501 
502 }; // end of class iter
503 
504 } // end of namespace GridContainer
505 } // end of namespace Euclid
506 
509 
510 #endif /* GRIDCONTAINER_GRIDCONTAINER_H */
511 
Euclid::GridContainer::GridContainer::GridContainer
GridContainer(std::tuple< GridAxis< AxesTypes >... > axes_tuple)
Constructs a GridContainer with the given axes.
Euclid::GridContainer::GridContainer::iter::operator==
bool operator==(const iter &other) const
Euclid::GridContainer::GridContainer::operator()
cell_type & operator()(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices)
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const
Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes... >::axis_type
typename std::tuple_element< I, std::tuple< AxesTypes... > >::type axis_type
Definition: GridContainer.h:112
Euclid::GridContainer::GridContainer::m_axes_fixed
std::tuple< GridAxis< AxesTypes >... > m_axes_fixed
a tuple containing the original axes of the full grid, if this grid is a slice
Definition: GridContainer.h:342
Euclid::GridContainer::GridContainer::iter::iter
iter(const GridContainer< GridCellManager, AxesTypes... > &owner, const cell_manager_iter_type &data_iter)
Constructs a new iterator for the given grid.
Euclid::GridContainer::GridContainer::m_index_helper_fixed
GridIndexHelper< AxesTypes... > m_index_helper_fixed
a helper class for calculations of the original axes indices
Definition: GridContainer.h:344
Euclid::GridContainer::GridCellManagerTraits::factory
static std::unique_ptr< GridCellManager > factory(size_t size)
GridContainer.icpp
Euclid::GridContainer::GridAxis
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
std::shared_ptr< GridCellManager >
Euclid::GridContainer::GridContainer::iter::iter
iter(iter< CellType > &&)=default
Move constructor.
Euclid::GridContainer::GridContainer::operator()
const cell_type & operator()(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices) const
Euclid::GridContainer::GridContainer::GridContainer
GridContainer(GridContainer< GridCellManager, AxesTypes... > &&)=default
Default move constructor and move assignment operator.
Euclid::GridContainer::GridContainer
Representation of a multi-dimensional grid which contains axis information.
Definition: GridContainer.h:97
Euclid::GridContainer::GridContainer::end
const_iterator end() const
Returns an iterator to the cell after the last of the grid.
Euclid::GridContainer::GridContainer::iter::forwardToIndex
void forwardToIndex(size_t axis, size_t fixed_index)
Euclid::GridContainer::GridContainer::iter
Class to iterate through the GridContainer cells.
Definition: GridContainer.h:116
Euclid::GridContainer::TemplateLoopCounter
Definition: TemplateLoopCounter.h:34
Euclid::GridContainer::GridConstructionHelper
GridContainer construction helper class.
Definition: GridConstructionHelper.h:53
Euclid::GridContainer::GridIndexHelper
Helper class for converting multi-dimensional grid coordinates to the index of a long data array and ...
Definition: GridIndexHelper.h:54
std::iterator
Euclid::GridContainer::GridContainer::iter::operator*
CellType & operator*()
Returns a reference to the cell value.
std::tuple
Euclid::GridContainer::GridCellManagerTraits::iterator
GridCellManager::iterator iterator
Definition: GridCellManagerTraits.h:57
Euclid::GridContainer::GridContainer::GridContainer
GridContainer(const GridContainer< GridCellManager, AxesTypes... > &other, size_t axis, size_t index)
Slice constructor.
GridIndexHelper.h
Euclid::GridContainer::GridContainer::iter::axisValue
const axis_type< I > & axisValue() const
Euclid::GridContainer::GridContainer::cell_type
GridCellManagerTraits< GridCellManager >::data_type cell_type
The type of the values stored in the grid cells.
Definition: GridContainer.h:105
Euclid::GridContainer::GridContainer::iter::axisIndex
size_t axisIndex() const
GridIterator.icpp
Euclid::GridContainer::GridContainer::end
iterator end()
Returns an iterator to the cell after the last of the grid.
Euclid::GridContainer::GridContainer::~GridContainer
virtual ~GridContainer()=default
Default destructor.
Euclid::GridContainer::GridContainer::begin
iterator begin()
Returns an iterator to the first cell of the grid.
Euclid::GridContainer::GridContainer::m_index_helper
GridIndexHelper< AxesTypes... > m_index_helper
A helper class used for calculations of the axes indices.
Definition: GridContainer.h:340
Euclid::GridContainer::GridContainer::axisNumber
static constexpr size_t axisNumber()
Returns the number of axes of the grid (dimensionality)
Euclid::GridContainer::GridContainer::GridContainer
GridContainer(const GridContainer< GridCellManager, AxesTypes... > &)=delete
Euclid::GridContainer::GridContainer::iter::operator*
std::add_const< CellType >::type & operator*() const
Returns a reference to the cell value (const version)
Euclid::GridContainer::GridContainer::fixAxisByValue
const GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value) const
const version of the fixAxisByValue(const axis_type<I>&) method
Euclid::GridContainer::GridContainer::iter::fixAllAxes
iter & fixAllAxes(const OtherIter &other)
Euclid::GridContainer::GridContainer::getOriginalAxis
const GridAxis< axis_type< I > > & getOriginalAxis() const
Euclid::GridContainer::GridContainer::iter::operator!=
bool operator!=(const iter &other) const
Euclid::GridContainer::GridContainer::iter::fixAxisByIndex
iter & fixAxisByIndex(size_t index)
Euclid::GridContainer::GridContainer::m_axes
std::tuple< GridAxis< AxesTypes >... > m_axes
A tuple containing the axes of the grid.
Definition: GridContainer.h:338
Euclid::GridContainer::GridContainer::m_fixed_indices
std::map< size_t, size_t > m_fixed_indices
A map containing the axes which have been fixed, if this grid is a slice.
Definition: GridContainer.h:346
Euclid::GridContainer::GridContainer::getAxesTuple
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
Euclid::GridContainer::GridContainer::iter::iter
iter(const iter< CellType > &)=default
Copy constructor.
Euclid::GridContainer::GridContainer::begin
const_iterator begin() const
Returns an iterator to the first cell of the grid.
std::map< size_t, size_t >
Euclid::GridContainer::GridContainer::at
cell_type & at(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices)
Euclid::GridContainer::GridContainer::fixAxisByValue
GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
Euclid::GridContainer::GridContainer::fixAxisByIndex
const GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index) const
const version of the fixAxisByIndex(size_t) method
Euclid::GridContainer::GridContainer::AxesTuple
std::tuple< GridAxis< AxesTypes >... > AxesTuple
The type of the tuple keeping the axes of the grid.
Definition: GridContainer.h:108
Euclid::GridContainer::GridContainer::iter::fixAxisByValue
iter & fixAxisByValue(const axis_type< I > &value)
Euclid::GridContainer::GridContainer::const_iterator
iter< cell_type const > const_iterator
Definition: GridContainer.h:119
Euclid::GridContainer::GridContainer::iter::operator->
std::add_const< CellType >::type * operator->() const
Returns a pointer to the cell value (const version)
Euclid::GridContainer::GridContainer::iter::m_data_iter
cell_manager_iter_type m_data_iter
Definition: GridContainer.h:498
Euclid::GridContainer::GridContainer::iterator
iter< cell_type > iterator
Definition: GridContainer.h:116
Euclid::GridContainer::GridContainer::iter::operator=
iter & operator=(const iter &other)
Copy operator of the iterator.
Euclid::GridContainer::GridContainer::iter::operator->
CellType * operator->()
Returns a pointer to the cell value.
Euclid::GridContainer::GridContainer::getAxis
const GridAxis< axis_type< I > > & getAxis() const
Euclid::GridContainer::GridContainer::size
size_t size() const
Returns the total number of cells of the grid.
Euclid::GridContainer::GridContainer::cbegin
const_iterator cbegin()
Returns a constant iterator to the first cell of the grid.
Euclid::GridContainer::GridContainer::cend
const_iterator cend()
Returns a constant iterator to the cell after the last of the grid.
Euclid::GridContainer::GridContainer::iter::m_fixed_indices
std::map< size_t, size_t > m_fixed_indices
Definition: GridContainer.h:499
Euclid::GridContainer::GridContainer::operator=
GridContainer & operator=(GridContainer< GridCellManager, AxesTypes... > &&)=default
Euclid::GridContainer::GridContainer::iter::m_owner
const GridContainer< GridCellManager, AxesTypes... > & m_owner
Definition: GridContainer.h:497
Euclid::GridContainer::GridContainer::fixAxisByIndex
GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
Euclid::GridContainer::GridContainer::cell_manager_iter_type
GridCellManagerTraits< GridCellManager >::iterator cell_manager_iter_type
Definition: GridContainer.h:100
Euclid::GridContainer::GridContainer::m_cell_manager
std::shared_ptr< GridCellManager > m_cell_manager
A pointer to the data of the grid.
Definition: GridContainer.h:348
GridCellManagerTraits.h
GridConstructionHelper.h
Euclid
Definition: InstOrRefHolder.h:29
Euclid::GridContainer::GridContainer::operator=
GridContainer & operator=(const GridContainer< GridCellManager, AxesTypes... > &)=delete
Euclid::GridContainer::GridContainer::at
const cell_type & at(decltype(std::declval< GridAxis< AxesTypes >>().size())... indices) const
Euclid::GridContainer::GridContainer::iter::operator++
iter & operator++()
Moves the iterator to the next grid cell.
std::add_const
std::declval
T declval(T... args)
Euclid::GridContainer::GridCellManagerTraits::data_type
GridCellManager::data_type data_type
The type of the data kept by the GridCellManager.
Definition: GridCellManagerTraits.h:53
Euclid::GridContainer::GridContainer::GridContainer
GridContainer(GridAxis< AxesTypes >... axes)
Constructs a GridContainer with the given axes.