Alexandria 2.32.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
GridContainer.h
Go to the documentation of this file.
1
18
24
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
37namespace Euclid {
38namespace GridContainer {
39
96template <typename GridCellManager, typename... AxesTypes>
98public:
101
102private:
103 // The following aliases are used to simplify the definitions inside the class
105
106 template <typename GCM>
107 static cell_type* ptr_test(...);
108
109 template<typename GCM>
110 static typename GCM::pointer_type ptr_test(typename GCM::pointer_type*);
111
112 template<typename GCM>
113 static cell_type& ref_test(...);
114
115 template<typename GCM>
116 static typename GCM::reference_type ref_test(typename GCM::reference_type*);
117
118public:
123
126
127 // The following is a shortcut to retrieve the type of each axis
128 template <int I>
129 using axis_type = typename std::tuple_element<I, std::tuple<AxesTypes...>>::type;
130
131 // The iterator type of the GridContainer. See at the end of the file for its declaration
132 template <typename CellType, typename PointerType, typename ReferenceType>
133 class iter;
134
137
147
157
161 template <typename... Args>
162 GridContainer(std::tuple<GridAxis<AxesTypes>...> axes_tuple, Args&&... args);
163
167
168 // Do not allow copying of GridContainer objects. This is done because these
169 // objects will most of the time be very big and copying them will be a
170 // bottleneck. To avoid involuntary copy constructor calls, this constructor
171 // is deleted.
174
177
179 virtual ~GridContainer() = default;
180
182 static constexpr size_t axisNumber();
183
189 template <int I>
191
194
197
200
203
206
209
212
214 size_t size() const;
215
226 const reference_type operator()(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
227
230
243 const reference_type at(decltype(std::declval<GridAxis<AxesTypes>>().size())... indices) const;
244
247
253 std::tuple<decltype(std::declval<GridAxis<AxesTypes>>().size())...> infimum(const AxesTypes... coordinates) const;
254
256 std::tuple<decltype(std::declval<GridAxis<AxesTypes>>().size())...>
257 infimum(const std::tuple<AxesTypes...>& coordinates) const;
258
277 template <int I>
278 GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index);
279
312 template <int I>
313 const GridContainer<GridCellManager, AxesTypes...> fixAxisByIndex(size_t index) const;
314
333 template <int I>
334 GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value);
335
368 template <int I>
369 const GridContainer<GridCellManager, AxesTypes...> fixAxisByValue(const axis_type<I>& value) const;
370
371 GridCellManager& getCellManager() {
372 return *m_cell_manager;
373 }
374
375 const GridCellManager& getCellManager() const {
376 return *m_cell_manager;
377 }
378
379private:
392
397
408 GridContainer(const GridContainer<GridCellManager, AxesTypes...>& other, size_t axis, size_t index);
409
413 template <int I>
415
416}; // end of class GridContainer
417
431template <typename GridCellManager, typename... AxesTypes>
432template <typename CellType, typename PointerType, typename ReferenceType>
433class GridContainer<GridCellManager, AxesTypes...>::iter
434 : public std::iterator<std::forward_iterator_tag, CellType, std::ptrdiff_t, PointerType, ReferenceType> {
435public:
446
448 iter(const iter&) = default;
449
451 iter(iter&&) = default;
452
454 iter& operator=(const iter& other);
455
458
460 ReferenceType operator*();
461
464
466 PointerType operator->();
467
470
473 bool operator==(const iter& other) const;
474
477 bool operator!=(const iter& other) const;
478
481 template <int I>
482 size_t axisIndex() const;
483
486 template <int I>
487 const axis_type<I>& axisValue() const;
488
502 template <int I>
503 iter& fixAxisByIndex(size_t index);
504
522 template <int I>
524
534 template <typename OtherIter>
535 iter& fixAllAxes(const OtherIter& other);
536
537private:
538 const GridContainer<GridCellManager, AxesTypes...>& m_owner;
541 void forwardToIndex(size_t axis, size_t fixed_index);
542
543}; // end of class iter
544
545} // end of namespace GridContainer
546} // end of namespace Euclid
547
550
551#endif /* GRIDCONTAINER_GRIDCONTAINER_H */
Provides information related with an axis of a GridContainer.
Definition GridAxis.h:49
Class to iterate through the GridContainer cells.
const axis_type< I > & axisValue() const
void forwardToIndex(size_t axis, size_t fixed_index)
bool operator!=(const iter &other) const
iter & fixAllAxes(const OtherIter &other)
iter(const GridContainer< GridCellManager, AxesTypes... > &owner, const cell_manager_iter_type &data_iter)
Constructs a new iterator for the given grid.
std::add_const< PointerType >::type operator->() const
Returns a pointer to the cell value (const version).
PointerType operator->()
Returns a pointer to the cell value.
iter(iter &&)=default
Move constructor.
iter & operator=(const iter &other)
Copy operator of the iterator.
bool operator==(const iter &other) const
std::add_const< ReferenceType >::type operator*() const
Returns a reference to the cell value (const version).
ReferenceType operator*()
Returns a reference to the cell value.
iter & operator++()
Moves the iterator to the next grid cell.
iter(const iter &)=default
Copy constructor.
iter & fixAxisByValue(const axis_type< I > &value)
const_iterator cend()
Returns a constant iterator to the cell after the last of the grid.
GridContainer(GridContainer< GridCellManager, AxesTypes... > &&)=default
Default move constructor and move assignment operator.
GridContainer copy() const
But if needed be, allow explicit copies.
const GridAxis< axis_type< I > > & getOriginalAxis() const
GridContainer & operator=(const GridContainer< GridCellManager, AxesTypes... > &)=delete
reference_type operator()(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices)
(decltype(std::declval<GridAxis<AxesTypes>>().size())...) const
GridContainer< GridCellManager, AxesTypes... > fixAxisByValue(const axis_type< I > &value)
Returns a slice of the grid based on an axis value.
iter< cell_type const, pointer_type const, reference_type const > const_iterator
reference_type at(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices)
GridContainer(std::tuple< GridAxis< AxesTypes >... > axes_tuple, Args &&... args)
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > infimum(const AxesTypes... coordinates) const
Returns the grid indexes to the greatest knot less or equal to the given coordinates.
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.
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
const GridAxis< axis_type< I > > & getAxis() const
GridContainer & operator=(GridContainer< GridCellManager, AxesTypes... > &&)=default
GridContainer(const GridContainer< GridCellManager, AxesTypes... > &)=delete
decltype(ref_test< GridCellManagerTraits< GridCellManager > >(nullptr)) reference_type
Reference type.
GridCellManagerTraits< GridCellManager >::iterator cell_manager_iter_type
const_iterator end() const
Returns an iterator to the cell after the last of the grid.
const reference_type at(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const
static cell_type & ref_test(...)
static constexpr size_t axisNumber()
Returns the number of axes of the grid (dimensionality).
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
typename std::tuple_element< I, std::tuple< AxesTypes... > >::type axis_type
const_iterator cbegin()
Returns a constant iterator to the first cell of the grid.
const_iterator begin() const
Returns an iterator to the first cell of the grid.
iter< cell_type, pointer_type, reference_type > iterator
std::tuple< GridAxis< AxesTypes >... > AxesTuple
The type of the tuple keeping the axes of the grid.
std::tuple< decltype(std::declval< GridAxis< AxesTypes > >().size())... > infimum(const std::tuple< AxesTypes... > &coordinates) const
static cell_type * ptr_test(...)
GridContainer(GridAxis< AxesTypes >... axes)
Constructs a GridContainer with the given axes.
const GridCellManager & getCellManager() const
GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index)
Returns a slice of the grid based on an axis index.
GridCellManagerTraits< GridCellManager >::data_type cell_type
The type of the values stored in the grid cells.
const reference_type operator()(decltype(std::declval< GridAxis< AxesTypes > >().size())... indices) const
iterator begin()
Returns an iterator to the first cell of the grid.
static GCM::pointer_type ptr_test(typename GCM::pointer_type *)
const GridContainer< GridCellManager, AxesTypes... > fixAxisByIndex(size_t index) const
const version of the fixAxisByIndex(size_t) method
decltype(ptr_test< GridCellManagerTraits< GridCellManager > >(nullptr)) pointer_type
Pointer type.
static GCM::reference_type ref_test(typename GCM::reference_type *)
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.