26#ifndef CASA_ARRAYACCESSOR_2_H
27#define CASA_ARRAYACCESSOR_2_H
38 template <
size_t AX>
struct Axis {
47 explicit AxisN(
const size_t n) : N(n) {}
383 if (&other !=
this) {
385 this->
begin_p = other.begin_p; this->
end_p = other.end_p;
432 const T &
next(
const AxisN ax)
const
436 const T &
prev(
const AxisN ax)
const
452 const T &
index(
const int ix,
const AxisN ax)
const
454 T &
index(
const int ix,
const AxisN ax)
463 return this->
ptr_p == other.ptr_p; }
465 return this->
ptr_p != other.ptr_p; }
474 return ((st) ? (ax == Axis<U>::N ? x/st :
initOff(x%st, ax-1)) : 0); }
480 this->arrayPtr_p->ndim()-1)*this->
step_p;
512 const AxisN ax=AxisN(0)) :
515 if (&other !=
this) {
557 const T &
next(
const AxisN ax)
const
561 const T &
prev(
const AxisN ax)
const
571 const T &
index(
const int ix,
const AxisN(ax))
const
573 T &
index(
const int ix,
const AxisN(ax))
580 return this->
ptr_p == other.ptr_p; }
582 return this->
ptr_p != other.ptr_p; }
591 return ((st) ? (ax == this->
axis_p ? x/st :
initOff(x%st, ax-1)) : 0); }
597 this->arrayPtr_p->ndim()-1)*this->
step_p;
void init(const Array< T > &arr, const AxisN ax)
(Re-)initialization to start of array (i.e.
const T & next() const
Indexing operations along another axis than the one of the current object.
ArrayAccessor(Array< T > &arr, const AxisN ax=AxisN(0))
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
ArrayAccessor(const AxisN ax=AxisN(0))
Constructors.
const T & index(const int ix) const
bool operator==(const T *other) const
bool operator==(const ArrayAccessor< T, AxisN > &other) const
Comparisons.
~ArrayAccessor()
Destructor.
const T & index(const int ix, const AxisN(ax)) const
ArrayAccessor(ArrayAccessor< T, AxisN > &other)
const T & next(const AxisN ax) const
void reset()
Reset to start of dimension or to specified pointer.
int initOff(int x, size_t ax)
Get proper offset.
void initStep()
Initialize some internal values.
T & index(const int ix, const AxisN(ax))
const T & prev(const AxisN ax) const
ArrayAccessor(ArrayAccessor< T, AxisN > &other, const AxisN ax)
void init(const AxisN ax)
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
bool operator!=(const ArrayAccessor< T, AxisN > &other) const
ArrayAccessor(ArrayAccessor< T, Axis< X > > &other, const AxisN ax=AxisN(0))
bool operator!=(const T *other) const
bool operator==(const T *other) const
const T & prev() const
Get the value 'previous' along the specified axis (e.g.
T & index(const int ix, const AxisN ax)
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
Assign from run-time accessor along any axis.
bool operator!=(const ArrayAccessor< T, Axis< U > > &other) const
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
Assign from other compile-time accessor along another axis.
~ArrayAccessor()
Destructor.
ArrayAccessor(const ArrayAccessor< T, Axis< U > > &other)
Construct from an ArrayAccessor along same axis.
const T & next(const AxisN ax) const
Get the next or previous along the specified run-time axis.
const T & prev(const AxisN ax) const
void init(const Array< T > &arr)
(Re-)initialization to start of array (i.e.
ArrayAccessor(const ArrayAccessor< T, AxisN > &other)
ArrayAccessor(const Array< T > &arr)
Construct an accessor from specified Array along the selected axis.
void reset()
Reset to start of dimension or to specified pointer.
ArrayAccessor(const ArrayAccessor< T, Axis< X > > &other)
Construct from accessor along another (or run-time) axis.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< U > > &other)
Assignment (copy semantics).
bool operator==(const ArrayAccessor< T, Axis< U > > &other) const
Comparison.
const T & index(const int ix, const AxisN ax) const
bool operator!=(const T *other) const
const T & next() const
Indexing operations along another axis than the one of the current object.
void initStep()
Initialize some internal values.
int initOff(int x, size_t ax)
Get proper offset.
ArrayAccessor()
Constructors.
const T & index(const int ix) const
Give the value indexed with respect to the current accessor value along the axis specified as either ...
Fast 1D accessor/iterator for nD array classes.
size_t axis_p
Current run-time axis.
void init(const size_t ax)
const T * rbegin(const int n)
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other, const size_t ax)
const Array< T > * arrayPtr_p
The pointer to belonging array.
void init(const Array< T > &arr, const size_t ax)
const T * begin(const int n)
const T * end(const int n)
T & operator[](const int ix)
void operator-=(const size_t ix)
void operator+=(const size_t ix)
Iterator-like operations.
ArrayBaseAccessor()
Default constructor (for use in e.g.
ArrayBaseAccessor(const Array< T > &arr, const size_t ax)
const T & operator*() const
Dereferencing.
const T * rbegin()
Begin when reverse indexing.
const T * end()
End of index on line.
const T * begin_p
The start element of array.
const T * rend(const int n)
const T & operator[](const int ix) const
Index along current axis.
const T * end_p
The one element beyond last on line.
int step_p
The increment to go from one point along an axis, to the next.
const T * rend()
End when reverse indexing.
const Array< T > & baseArray()
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other)
Copy constructor (copy semantics).
T * ptr_p
Current access pointer.
const T * begin()
Start of index on line.
ArrayBaseAccessor(const Array< T > &arr)
Construct from an Array.
void init(const Array< T > &arr)
(Re-)initialize from Array
ArrayBaseAccessor & operator=(const ArrayBaseAccessor< T > &other)
Assignment (copy semantics).
~ArrayBaseAccessor()
Destructor.
this file contains all the compiler specific defines