27 #ifndef SCHNEK_GRID_GRIDSTORAGE_SINGLESTORAGEBASE_HPP_ 28 #define SCHNEK_GRID_GRIDSTORAGE_SINGLESTORAGEBASE_HPP_ 30 #include "../array.hpp" 41 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
68 SCHNEK_INLINE
const IndexType &
getLo()
const {
return this->range.getLo(); }
71 SCHNEK_INLINE
const IndexType &
getHi()
const {
return this->range.getHi(); }
74 SCHNEK_INLINE
const RangeType &
getRange()
const {
return this->range; }
77 SCHNEK_INLINE
const IndexType &
getDims()
const {
return this->dims; }
80 SCHNEK_INLINE
int getLo(
int k)
const {
return this->range.getLo(k); }
83 SCHNEK_INLINE
int getHi(
int k)
const {
return this->range.getHi(k); }
86 SCHNEK_INLINE
int getDims(
int k)
const {
return this->dims[k]; }
89 SCHNEK_INLINE
int getSize()
const {
return this->size; }
91 typedef T* storage_iterator;
92 typedef const T* const_storage_iterator;
94 SCHNEK_INLINE storage_iterator begin() {
return this->data->ptr; }
95 SCHNEK_INLINE storage_iterator end() {
return this->data->ptr + this->size; }
97 SCHNEK_INLINE const_storage_iterator cbegin()
const {
return this->data->ptr; }
98 SCHNEK_INLINE const_storage_iterator cend()
const {
return this->data->ptr + this->size; }
109 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
159 SCHNEK_INLINE T &
get(
const IndexType &index);
167 SCHNEK_INLINE
const T &
get(
const IndexType &index)
const;
173 void resize(
const IndexType &low,
const IndexType &high);
179 void resize(
const RangeType range);
184 ptrdiff_t stride(
size_t dim)
const;
196 void updateDataFast();
208 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
258 SCHNEK_INLINE T &
get(
const IndexType &index);
266 SCHNEK_INLINE
const T &
get(
const IndexType &index)
const;
272 void resize(
const IndexType &low,
const IndexType &high);
278 void resize(
const RangeType range);
283 ptrdiff_t stride(
size_t dim)
const;
285 void updateDataFast();
292 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
294 : AllocationPolicy<T, rank>()
302 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
306 this->onUpdate([
this](){ updateDataFast(); });
309 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
311 :
BaseType(other), data_fast(other.data_fast)
313 this->onUpdate([
this](){ updateDataFast(); });
316 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
322 this->onUpdate([
this](){ updateDataFast(); });
326 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
331 this->onUpdate([
this](){ updateDataFast(); });
335 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
338 size_t pos = index[0];
339 for (
size_t i = 1; i < rank; ++i)
341 pos = index[i] + this->dims[i] * pos;
343 return this->data_fast[pos];
346 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
349 size_t pos = index[0];
350 for (
size_t i = 1; i < rank; ++i)
352 pos = index[i] + this->dims[i] * pos;
354 return this->data_fast[pos];
357 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
360 this->resizeImpl(lo, hi);
370 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
376 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
380 for (
size_t i = rank - 1; i > dim; --i)
382 stride *= this->dims[i];
387 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
390 ptrdiff_t p = -this->range.
getLo(0);
392 for (
size_t d = 1; d < rank; ++d)
394 p = p * this->dims[d] - this->
getLo(d);
396 data_fast = this->data->ptr + p;
403 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
407 this->onUpdate([
this](){ updateDataFast(); });
410 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
412 :
BaseType(other), data_fast(other.data_fast)
414 this->onUpdate([
this](){ updateDataFast(); });
417 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
423 this->onUpdate([
this](){ updateDataFast(); });
427 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
432 this->onUpdate([
this](){ updateDataFast(); });
436 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
439 size_t pos = index[rank - 1];
440 for (ptrdiff_t i = ptrdiff_t(rank) - 2; i >= 0; --i)
442 pos = index[i] + this->dims[i] * pos;
444 return this->data_fast[pos];
447 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
450 size_t pos = index[rank - 1];
451 for (ptrdiff_t i = ptrdiff_t(rank) - 2; i >= 0; --i)
453 pos = index[i] + this->dims[i] * pos;
455 return this->data_fast[pos];
458 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
461 this->resizeImpl(lo, hi);
464 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
470 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
474 for (
size_t i = 0; i < dim; ++i)
476 stride *= this->dims[i];
481 template <
typename T,
size_t rank,
template <
typename,
size_t>
class AllocationPolicy>
484 size_t p = -this->
getLo(rank - 1);
486 for (ptrdiff_t d = ptrdiff_t(rank) - 2; d >= 0; --d)
488 p = p * this->dims[d] - this->
getLo(d);
490 data_fast = this->data->ptr + p;
495 #endif // SCHNEK_GRID_GRIDSTORAGE_SINGLESTORAGEBASE_HPP_ SCHNEK_INLINE const IndexType & getLo() const
Get the lowest coordinate in the grid (inclusive)
Definition: single-array-storage-base.hpp:68
SingleArrayGridStorageBase< T, rank, AllocationPolicy > BaseType
Base class type.
Definition: single-array-storage-base.hpp:216
SingleArrayGridStorageBase< T, rank, AllocationPolicy > BaseType
Base class type.
Definition: single-array-storage-base.hpp:117
BaseType::IndexType IndexType
The grid index type.
Definition: single-array-storage-base.hpp:120
BaseType::RangeType RangeType
The grid index type.
Definition: single-array-storage-base.hpp:222
SingleArrayGridStorageBase< T, rank, AllocationPolicy > & operator=(const SingleArrayGridStorageBase< T, rank, AllocationPolicy > &)=default
Assignment operator.
SCHNEK_INLINE T & get(const IndexType &index)
Get the lvalue at a given grid index.
Definition: single-array-storage-base.hpp:437
SCHNEK_INLINE const IndexType & getHi() const
Get the highest coordinate in the grid (inclusive)
Definition: single-array-storage-base.hpp:71
Array< int, rank > IndexType
The grid index type.
Definition: single-array-storage-base.hpp:46
void resize(const IndexType &low, const IndexType &high)
resizes to grid with lower indices lo[0],...,lo[rank-1] and upper indices hi[0],...,hi[rank-1]
Definition: single-array-storage-base.hpp:358
BaseType::IndexType IndexType
The grid index type.
Definition: single-array-storage-base.hpp:219
SCHNEK_INLINE int getDims(int k) const
Get k-th component of the dimensions of the grid dims = high - low + 1
Definition: single-array-storage-base.hpp:86
SingleArrayGridStorageBase()
Default constructor.
Definition: single-array-storage-base.hpp:293
T * getRawData() const
Access to the underlying raw data.
Definition: single-array-storage-base.hpp:65
SCHNEK_INLINE const LimitType & getLo() const
Return rectangle minimum.
Definition: range.hpp:74
SingleArrayGridFortranOrderStorageBase()
Default constructor.
Definition: single-array-storage-base.hpp:404
Extends from SingleArrayGridStorageBase to provide C-order indexing over the 1-dimensional data array...
Definition: single-array-storage-base.hpp:110
void resize(const IndexType &low, const IndexType &high)
resizes to grid with lower indices low[0],...,low[rank-1] and upper indices high[0],...,high[rank-1]
Definition: single-array-storage-base.hpp:459
SCHNEK_INLINE int getHi(int k) const
Get k-th component of the highest coordinate in the grid (inclusive)
Definition: single-array-storage-base.hpp:83
SCHNEK_INLINE int getLo(int k) const
Get k-th component of the lowest coordinate in the grid (inclusive)
Definition: single-array-storage-base.hpp:80
ptrdiff_t stride(size_t dim) const
returns the stride of the specified dimension
Definition: single-array-storage-base.hpp:377
BaseType::RangeType RangeType
The grid index type.
Definition: single-array-storage-base.hpp:123
SCHNEK_INLINE T & get(const IndexType &index)
Get the lvalue at a given grid index.
Definition: single-array-storage-base.hpp:336
SCHNEK_INLINE const RangeType & getRange() const
Get the lowest coordinate in the grid (inclusive)
Definition: single-array-storage-base.hpp:74
SingleArrayGridCOrderStorageBase()
Default constructor.
Definition: single-array-storage-base.hpp:303
Range< int, rank > RangeType
The grid range type.
Definition: single-array-storage-base.hpp:49
The storage base extends from an allocation policy and adds some accessor methods.
Definition: single-array-storage-base.hpp:42
SCHNEK_INLINE const IndexType & getDims() const
Get the dimensions of the grid dims = high - low + 1
Definition: single-array-storage-base.hpp:77
SCHNEK_INLINE int getSize() const
Get the length of the allocated array.
Definition: single-array-storage-base.hpp:89
Extends from SingleArrayGridStorageBase to provide Fortran-order indexing over the 1-dimensional data...
Definition: single-array-storage-base.hpp:209
ptrdiff_t stride(size_t dim) const
returns the stride of the specified dimension
Definition: single-array-storage-base.hpp:471
SCHNEK_INLINE const LimitType & getHi() const
Return rectangle maximum.
Definition: range.hpp:76