29 #ifndef CASA_ARRAYACCESSOR_H
30 #define CASA_ARRAYACCESSOR_H
47 template <uInt AX>
struct Axis {
56 explicit AxisN(
const uInt n) :
N(n) {}
69 template <
class T>
class ArrayBaseAccessor {
102 if (&other !=
this) {
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]); }
456 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
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 uInt 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; }
488 #define ArrayAccessor_RT ArrayAccessor
519 const AxisN ax=AxisN(0)) :
522 if (&other !=
this) {
529 initStep();
return *
this; }
546 void reset() { this->
ptr_p =
const_cast<T *
>(this->begin_p); }
547 void reset(
const T *p) { this->
ptr_p =
const_cast<T *
>(p); initStep(); }
556 {
return *(this->
ptr_p + this->arrayPtr_p->steps()[
X::N]); }
561 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[
X::N]); }
564 const T &
next(
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]); }
568 const T &
prev(
const AxisN ax)
const
569 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
571 {
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
574 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
577 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[
X::N]); }
578 const T &
index(
const Int ix,
const AxisN(ax))
const
579 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
581 {
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
597 uInt st = this->arrayPtr_p->steps()[ax];
598 return ((st) ? (ax == this->axis_p ? x/st : initOff(x%st, ax-1)) : 0); }
601 this->step_p = this->arrayPtr_p->steps()[this->axis_p];
602 this->begin_p = this->end_p = this->
ptr_p
603 - initOff(this->
ptr_p - this->arrayPtr_p->data(),
604 this->arrayPtr_p->ndim()-1)*this->step_p;
605 this->end_p += this->arrayPtr_p->shape()[this->axis_p]*this->step_p; }
609 #undef ArrayAccessor_RT
Int step_p
The increment to go from one point along an axis, to the next.
~ArrayBaseAccessor()
Destructor.
void reset()
Reset to start of dimension or to specified pointer.
const T & index(const Int ix, const AxisN ax) const
void reset()
Reset to start of dimension or to specified pointer.
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.
Bool operator!=(const T *other) const
Bool operator!=(const ArrayAccessor_RT< T, AxisN > &other) const
const T & next() const
Indexing operations along another axis than the one of the current object.
ArrayAccessor_RT(ArrayAccessor_RT< T, AxisN > &other)
ArrayAccessor(const ArrayAccessor< T, Axis< U > > &other)
Construct from an ArrayAccessor along same axis.
ArrayAccessor_RT & operator=(const ArrayAccessor_RT< T, Axis< X > > &other)
const T * rend()
End when reverse indexing.
const T * begin(const Int n)
ArrayAccessor & operator=(const ArrayAccessor< T, AxisN > &other)
Assign from run-time accessor along any axis.
const T * end()
End of index on line.
Bool operator!=(const T *other) const
void operator+=(const uInt ix)
Iterator-like operations.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< X > > &other)
Assign from other compile-time accessor along another axis.
const T * end_p
The one element beyond last on line.
const T & prev(const AxisN ax) const
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other, const uInt ax)
const Array< T > & baseArray()
const T & next(const AxisN ax) const
const T & operator[](const Int ix) const
Index along current axis.
ArrayBaseAccessor()
Default constructor (for use in e.g.
ArrayAccessor(const ArrayAccessor< T, AxisN > &other)
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 & prev(const AxisN ax) const
ArrayAccessor()
Constructors.
uInt axis_p
Current run-time axis.
const T * begin()
Start of index on line.
ArrayAccessor(const Array< T > &arr)
Construct an accessor from specified Array along the selected axis.
const T * rbegin(const Int n)
const T & index(const Int ix) const
const T & next(const AxisN ax) const
Get the next or previous along the specified run-time axis.
ArrayBaseAccessor(const Array< T > &arr)
Construct from an Array.
ArrayAccessor_RT(ArrayAccessor_RT< T, Axis< X > > &other, const AxisN ax=AxisN(0))
void initStep()
Initialize some internal values.
bool Bool
Define the standard types used by Casacore.
void initStep()
Initialize some internal values.
Bool operator!=(const ArrayAccessor< T, Axis< U > > &other) const
Bool operator==(const T *other) const
template <class T, class U> class vector;
const T & index(const Int ix, const AxisN(ax)) const
void operator-=(const uInt ix)
const T & next() const
Indexing operations along another axis than the one of the current object.
T * ptr_p
Current access pointer.
Bool operator==(const T *other) const
ArrayAccessor_RT(Array< T > &arr, const AxisN ax=AxisN(0))
const T * begin_p
The start element of array.
Bool operator==(const ArrayAccessor_RT< T, AxisN > &other) const
Comparisons.
ArrayAccessor & operator=(const ArrayAccessor< T, Axis< U > > &other)
Assignment (copy semantics)
ArrayAccessor_RT(ArrayAccessor_RT< T, AxisN > &other, const AxisN ax)
Int initOff(Int x, uInt ax)
Get proper offset.
~ArrayAccessor()
Destructor.
Specialization for run-time axes.
const T * rend(const Int n)
Bool operator==(const ArrayAccessor< T, Axis< U > > &other) const
Comparison.
void init(const Array< T > &arr, const AxisN ax)
(Re-)initialization to start of array (i.e.
T & index(const Int ix, const AxisN(ax))
ArrayAccessor_RT(const AxisN ax=AxisN(0))
Constructors.
T & operator[](const Int ix)
const Array< T > * arrayPtr_p
The pointer to belonging array.
ArrayBaseAccessor(const Array< T > &arr, const uInt ax)
Int initOff(Int x, uInt ax)
Get proper offset.
ArrayBaseAccessor(const ArrayBaseAccessor< T > &other)
Copy constructor (copy semantics)
const T & prev() const
Get the value 'previous' along the specified axis (e.g.
~ArrayAccessor_RT()
Destructor.
Axis independent base for the ArrayAccessor classes.
void init(const Array< T > &arr, const uInt ax)
ArrayAccessor_RT & operator=(const ArrayAccessor_RT< T, AxisN > &other)
T & index(const Int ix, const AxisN ax)
const T * end(const Int n)
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.
void init(const AxisN ax)