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; }
Specialization for run-time axes.
const T & next() const
Indexing operations along another axis than the one of the current object.
void init(const Array< T > &arr, const AxisN ax)
(Re-)initialization to start of array (i.e.
ArrayAccessor(Array< T > &arr, const AxisN ax=AxisN(0))
ArrayAccessor(const AxisN ax=AxisN(0))
Constructors.
bool operator==(const T *other) const
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
bool operator==(const ArrayAccessor< T, AxisN > &other) const
Comparisons.
~ArrayAccessor()
Destructor.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
ArrayAccessor(ArrayAccessor< T, AxisN > &other)
const T & index(const int ix, 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.
const T & prev(const AxisN ax) const
const T & next(const AxisN ax) const
T & index(const int ix, const AxisN(ax))
const T & index(const int ix) const
ArrayAccessor(ArrayAccessor< T, AxisN > &other, const AxisN ax)
void init(const AxisN ax)
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
T & index(const int ix, const AxisN ax)
bool operator!=(const ArrayAccessor< T, Axis< U > > &other) const
const T & next() const
Indexing operations along another axis than the one of the current object.
~ArrayAccessor()
Destructor.
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
Assign from run-time accessor along any axis.
ArrayAccessor(const ArrayAccessor< T, Axis< U > > &other)
Construct from an ArrayAccessor along same axis.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
Assign from other compile-time accessor along another axis.
void init(const Array< T > &arr)
(Re-)initialization to start of array (i.e.
ArrayAccessor(const ArrayAccessor< T, AxisN > &other)
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< U > > &other)
Assignment (copy semantics)
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.
const T & index(const int ix) const
Give the value indexed with respect to the current accessor value along the axis specified as either ...
const T & next(const AxisN ax) const
Get the next or previous along the specified run-time axis.
const T & prev() const
Get the value 'previous' along the specified axis (e.g.
ArrayAccessor(const ArrayAccessor< T, Axis< X > > &other)
Construct from accessor along another (or run-time) axis.
const T & prev(const AxisN ax) const
bool operator==(const ArrayAccessor< T, Axis< U > > &other) const
Comparison.
bool operator!=(const T *other) const
const T & index(const int ix, const AxisN ax) const
void initStep()
Initialize some internal values.
int initOff(int x, size_t ax)
Get proper offset.
ArrayAccessor()
Constructors.
Fast 1D accessor/iterator for nD array classes.
Axis independent base for the ArrayAccessor classes.
size_t axis_p
Current run-time axis.
void init(const size_t ax)
const T * rend(const int n)
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other, const size_t ax)
const Array< T > * arrayPtr_p
The pointer to belonging array.
const T * rend()
End when reverse indexing.
const T * rbegin(const int n)
void init(const Array< T > &arr, const size_t ax)
const T * end(const int n)
const T * begin()
Start of index on line.
void operator-=(const size_t ix)
void operator+=(const size_t ix)
Iterator-like operations.
ArrayBaseAccessor()
Default constructor (for use in e.g.
const T & operator[](const int ix) const
Index along current axis.
ArrayBaseAccessor(const Array< T > &arr, const size_t ax)
const T * begin_p
The start element of array.
const T * rbegin()
Begin when reverse indexing.
const T & operator*() const
Dereferencing.
const Array< T > & baseArray()
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 * begin(const int n)
ArrayBaseAccessor & operator=(const ArrayBaseAccessor< T > &other)
Assignment (copy semantics)
T & operator[](const int ix)
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other)
Copy constructor (copy semantics)
T * ptr_p
Current access pointer.
ArrayBaseAccessor(const Array< T > &arr)
Construct from an Array.
void init(const Array< T > &arr)
(Re-)initialize from Array
~ArrayBaseAccessor()
Destructor.
const T * end()
End of index on line.
T * data()
Get a pointer to the beginning of the array.
this file contains all the compiler specific defines