40 Helper(T* array,
const int n[3],
const int pad[6]);
53 T&
at(
int i,
int j,
int k)
const;
60 std::size_t
size()
const;
78 Helper<T> slice(
int is,
int ie,
int js,
int je,
int ks,
int ke)
const;
90 using iterator_category = std::forward_iterator_tag;
92 using difference_type = long;
126 return ptr == other.ptr;
129 bool operator!=(
const Iterator& other)
const
131 return ptr != other.ptr;
229 constexpr std::ptrdiff_t getIndex(
int i,
int j,
int k)
const;
258 Owner(T* array,
const int n[3],
const int pad[6]) =
delete;
277constexpr std::size_t
getLength(
const int n[3],
const int pad[6])
279 return (n[0] + pad[0] + pad[1]) * (n[1] + pad[2] + pad[3]) * (n[2] + pad[4] + pad[5]);
284 : basePtr{array}, n{n[0], n[1], n[2]}, pad{pad[0], pad[1], pad[2], pad[3], pad[4], pad[5]}
291 return *(basePtr + getIndex(i, j, k));
297 return n[0] * n[1] * n[2];
303 int n_new[3] = {ie - is, je - js, ke - ks};
305 pad[0] + is, pad[1] + (n[0] - ie), pad[2] + js,
306 pad[3] + (n[1] - je), pad[4] + ks, pad[5] + (n[2] - ke),
315 std::ptrdiff_t
bounds[3] = {
319 return ((k +
pad[4]) * bounds[1] + (j +
pad[2])) * bounds[0] + i +
pad[0];
321 return ((i +
pad[0]) * bounds[1] + (j +
pad[2])) * bounds[2] + k +
pad[4];
354 ++Iterator::index[0];
356 if (Iterator::index[0] == Iterator::n[0]) {
357 Iterator::index[0] = 0;
359 Iterator::ptr += Iterator::jump[0];
360 ++Iterator::index[1];
362 if (Iterator::index[1] == Iterator::n[1]) {
363 Iterator::index[1] = 0;
365 Iterator::ptr += Iterator::jump[1];
375 if (Iterator::index[0] == 0) {
376 Iterator::index[0] = Iterator::n[0];
378 if (Iterator::index[1] == 0) {
379 Iterator::index[1] = Iterator::n[1];
381 Iterator::ptr -= Iterator::jump[1];
383 Iterator::ptr -= Iterator::jump[0];
384 --Iterator::index[1];
388 --Iterator::index[0];
A helper class to wrap pointers to padded 3D cartesian data.
Definition fields.h:27
reverse_Iterator rend() const
Reverse Iterator end.
Definition fields.h:206
std::size_t size() const
Return the number of (not pad) cells.
Definition fields.h:295
forward_Iterator end() const
Iterator to the end of the data.
Definition fields.h:186
int const pad[6]
Definition fields.h:226
forward_Iterator begin() const
Iterator to the start (0,0,0) of the data.
Definition fields.h:176
Helper< T > slice(int is, int ie, int js, int je, int ks, int ke) const
Create a slice of the array.
Definition fields.h:301
int const n[3]
Definition fields.h:220
T & at(int i, int j, int k) const
Get the element at (i,j,k)
Definition fields.h:289
reverse_Iterator rbegin() const
Reverse Iterator to the end (ni-1,nj-1,nk-1) of the data.
Definition fields.h:196
Helper(T *array, const int n[3], const int pad[6])
Construct a new Array Helper object pointing to array.
Definition fields.h:283
T *const basePtr
Pointer to start of underlying data.
Definition fields.h:216
An extension of Helper<T> which owns the array.
Definition fields.h:244
Owner(const int n[3], const int pad[6])
Definition fields.h:394
Template to wrap pointer to padded 3D cartesian data.
Definition fields.h:19
constexpr std::size_t getLength(const int n[3], const int pad[6])
Get the total number of elements (including padding)
Definition fields.h:277
An iterator for all data (excluding padding) in Helper<T>.
Definition fields.h:88
T * operator->()
Get pointer.
Definition fields.h:112
T & operator*() const
Get reference.
Definition fields.h:106
const T * operator->() const
Get pointer to const.
Definition fields.h:118
bool operator==(const Iterator &other) const
Comparison.
Definition fields.h:124
forward_Iterator operator++(int)
Postfix forward increment.
Definition fields.h:148
forward_Iterator & operator++()
Prefix forward increment.
Definition fields.h:351
reverse_Iterator operator++(int)
Postfix forward increment.
Definition fields.h:163
reverse_Iterator & operator++()
Prefix forward increment.
Definition fields.h:373