29 #ifndef CASA_ARRAYACCESSOR_2_H
30 #define CASA_ARRAYACCESSOR_2_H
41 template <
size_t AX>
struct Axis {
50 explicit AxisN(
const size_t n) :
N(n) {}
386 if (&other !=
this) {
388 this->begin_p = other.begin_p; this->end_p = other.end_p;
406 void reset() { this->
ptr_p =
const_cast<T *
>(this->begin_p); }
407 void reset(
const T * p) { this->
ptr_p =
const_cast<T *
>(p); initStep(); }
419 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[
X::N]); }
428 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[
X::N]); }
435 const T &
next(
const AxisN ax)
const
436 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
438 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
439 const T &
prev(
const AxisN ax)
const
440 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
442 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
451 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
454 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
455 const T &
index(
const int ix,
const AxisN ax)
const
456 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
457 T &
index(
const int ix,
const AxisN ax)
458 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
466 return this->
ptr_p == other.ptr_p; }
468 return this->
ptr_p != other.ptr_p; }
476 size_t st = this->arrayPtr_p->steps()[ax];
477 return ((st) ? (ax ==
Axis<U>::N ? x/st : initOff(x%st, ax-1)) : 0); }
480 this->step_p = this->arrayPtr_p->steps()[
Axis<U>::N];
481 this->begin_p = this->end_p = this->
ptr_p
482 - initOff(this->
ptr_p - this->arrayPtr_p->data(),
483 this->arrayPtr_p->ndim()-1)*this->step_p;
484 this->end_p += this->arrayPtr_p->shape()[
Axis<U>::N]*this->step_p; }
515 const AxisN ax=AxisN(0)) :
518 if (&other !=
this) {
525 initStep();
return *
this; }
542 void reset() { this->
ptr_p =
const_cast<T *
>(this->begin_p); }
543 void reset(
const T *p) { this->
ptr_p =
const_cast<T *
>(p); initStep(); }
552 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[
X::N]); }
557 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[
X::N]); }
560 const T &
next(
const AxisN ax)
const
561 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
563 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
564 const T &
prev(
const AxisN ax)
const
565 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
567 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
570 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
573 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
574 const T &
index(
const int ix,
const AxisN(ax))
const
575 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
576 T &
index(
const int ix,
const AxisN(ax))
577 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
593 size_t st = this->arrayPtr_p->steps()[ax];
594 return ((st) ? (ax == this->axis_p ? x/st : initOff(x%st, ax-1)) : 0); }
597 this->step_p = this->arrayPtr_p->steps()[this->axis_p];
598 this->begin_p = this->end_p = this->
ptr_p
599 - initOff(this->
ptr_p - this->arrayPtr_p->data(),
600 this->arrayPtr_p->ndim()-1)*this->step_p;
601 this->end_p += this->arrayPtr_p->shape()[this->axis_p]*this->step_p; }
~ArrayBaseAccessor()
Destructor.
bool operator!=(const ArrayAccessor< T, AxisN > &other) const
int step_p
The increment to go from one point along an axis, to the next.
void reset()
Reset to start of dimension or to specified pointer.
Fast 1D accessor/iterator for nD array classes.
bool operator==(const ArrayAccessor< T, Axis< U > > &other) const
Comparison.
ArrayBaseAccessor & operator=(const ArrayBaseAccessor< T > &other)
Assignment (copy semantics)
void init(const Array< T > &arr)
(Re-)initialization to start of array (i.e.
const T & operator*() const
Dereferencing.
const T * rbegin()
Begin when reverse indexing.
void init(const Array< T > &arr)
(Re-)initialize from Array
ArrayAccessor(const ArrayAccessor< T, Axis< X > > &other)
Construct from accessor along another (or run-time) axis.
ArrayAccessor(Array< T > &arr, const AxisN ax=AxisN(0))
bool operator==(const ArrayAccessor< T, AxisN > &other) const
Comparisons.
bool operator!=(const T *other) const
const T & next() const
Indexing operations along another axis than the one of the current object.
ArrayAccessor(const ArrayAccessor< T, Axis< U > > &other)
Construct from an ArrayAccessor along same axis.
const T & prev(const AxisN ax) const
bool operator==(const T *other) const
const T * end(const int n)
const T * rend()
End when reverse indexing.
void operator+=(const size_t ix)
Iterator-like operations.
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
Assign from run-time accessor along any axis.
const T & index(const int ix) const
const T * end()
End of index on line.
ArrayAccessor(const AxisN ax=AxisN(0))
Constructors.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
Assign from other compile-time accessor along another axis.
const T * rend(const int n)
const T * end_p
The one element beyond last on line.
const Array< T > & baseArray()
void init(const Array< T > &arr, const AxisN ax)
(Re-)initialization to start of array (i.e.
ArrayBaseAccessor()
Default constructor (for use in e.g.
bool operator!=(const T *other) const
ArrayAccessor(ArrayAccessor< T, Axis< X > > &other, const AxisN ax=AxisN(0))
const T & next() const
Indexing operations along another axis than the one of the current object.
ArrayAccessor(ArrayAccessor< T, AxisN > &other, const AxisN ax)
ArrayAccessor(ArrayAccessor< T, AxisN > &other)
ArrayAccessor(const ArrayAccessor< T, AxisN > &other)
bool operator==(const T *other) const
const T & prev(const AxisN ax) const
ArrayAccessor()
Constructors.
const T * begin()
Start of index on line.
ArrayAccessor(const Array< T > &arr)
Construct an accessor from specified Array along the selected axis.
size_t axis_p
Current run-time axis.
const T & next(const AxisN ax) const
Get the next or previous along the specified run-time axis.
int initOff(int x, size_t ax)
Get proper offset.
ArrayBaseAccessor(const Array< T > &arr)
Construct from an Array.
Specialization for run-time axes.
void initStep()
Initialize some internal values.
void init(const Array< T > &arr, const size_t ax)
ArrayBaseAccessor(const Array< T > &arr, const size_t ax)
void initStep()
Initialize some internal values.
const T * begin(const int n)
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
T * ptr_p
Current access pointer.
void init(const AxisN ax)
const T * begin_p
The start element of array.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< U > > &other)
Assignment (copy semantics)
~ArrayAccessor()
Destructor.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
T & operator[](const int ix)
bool operator!=(const ArrayAccessor< T, Axis< U > > &other) const
void init(const size_t ax)
const Array< T > * arrayPtr_p
The pointer to belonging array.
const T & index(const int ix, const AxisN(ax)) const
T & index(const int ix, const AxisN(ax))
~ArrayAccessor()
Destructor.
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other, const size_t ax)
T & index(const int ix, const AxisN ax)
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other)
Copy constructor (copy semantics)
const T & prev() const
Get the value 'previous' along the specified axis (e.g.
Axis independent base for the ArrayAccessor classes.
const T & next(const AxisN ax) const
const T * rbegin(const int n)
const T & index(const int ix) const
Give the value indexed with respect to the current accessor value along the axis specified as either ...
T * data()
Get a pointer to the beginning of the array.
const T & operator[](const int ix) const
Index along current axis.
void reset()
Reset to start of dimension or to specified pointer.
void operator-=(const size_t ix)
int initOff(int x, size_t ax)
Get proper offset.
const T & index(const int ix, const AxisN ax) const