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;
 
 
  403  void reset() { this->
ptr_p = 
const_cast<T *
>(this->begin_p); }
 
  404  void reset(
const T * p) { this->
ptr_p = 
const_cast<T *
>(p); initStep(); }
 
  416    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[X::N]); }
 
 
  418    T &
next() { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[X::N]); }
 
  425    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[X::N]); }
 
 
  427    T &
prev() { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[X::N]); }
 
  432  const T &
next(
const AxisN ax)
 const 
  433    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
 
 
  435    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
 
 
  436  const T &
prev(
const AxisN ax)
 const 
  437    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
 
 
  439    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
 
 
  448    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[X::N]); }
 
 
  451    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[X::N]); }
 
 
  452  const T &
index(
const int ix, 
const AxisN ax)
 const  
  453    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
 
 
  454  T &
index(
const int ix, 
const AxisN ax)
 
  455    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
 
 
  463    return this->
ptr_p == other.ptr_p; }
 
 
  465    return this->
ptr_p != other.ptr_p; }
 
 
  473    size_t st = this->arrayPtr_p->steps()[ax];
 
  474    return ((st) ? (ax == Axis<U>::N ? x/st : initOff(x%st, ax-1)) : 0); }
 
 
  477    this->step_p = this->arrayPtr_p->steps()[Axis<U>::N];
 
  478    this->begin_p = this->end_p = this->
ptr_p 
  479                    - initOff(this->
ptr_p - this->arrayPtr_p->data(),
 
  480                  this->arrayPtr_p->ndim()-1)*this->step_p;
 
  481    this->end_p += this->arrayPtr_p->shape()[Axis<U>::N]*this->step_p; }
 
 
 
  512                  const AxisN ax=AxisN(0)) :
 
 
  515    if (&other != 
this) {
 
 
  522    initStep(); 
return *
this; }
 
 
  539  void reset() { this->
ptr_p = 
const_cast<T *
>(this->begin_p); }
 
  540  void reset(
const T *p) { this->
ptr_p = 
const_cast<T *
>(p); initStep(); }
 
  549    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[X::N]); }
 
 
  551    T &
next() { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[X::N]); }
 
  554    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[X::N]); }
 
 
  556    T &
prev() { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[X::N]); }
 
  557  const T &
next(
const AxisN ax)
 const 
  558    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
 
 
  560    { 
return *(this->
ptr_p + this->arrayPtr_p->steps()[ax.N]); }
 
 
  561  const T &
prev(
const AxisN ax)
 const 
  562    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
 
 
  564    { 
return *(this->
ptr_p - this->arrayPtr_p->steps()[ax.N]); }
 
 
  567    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[X::N]); }
 
 
  570    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[X::N]); }
 
 
  571  const T &
index(
const int ix, 
const AxisN(ax))
 const  
  572    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
 
 
  573  T &
index(
const int ix, 
const AxisN(ax))
 
  574    { 
return *(this->
ptr_p + ix*this->arrayPtr_p->steps()[ax.N]); }
 
 
  580    return this->
ptr_p == other.ptr_p; }
 
 
  582    return this->
ptr_p != other.ptr_p; }
 
 
  590    size_t st = this->arrayPtr_p->steps()[ax];
 
  591    return ((st) ? (ax == this->axis_p ? x/st : initOff(x%st, ax-1)) : 0); }
 
 
  594    this->step_p = this->arrayPtr_p->steps()[this->axis_p];
 
  595    this->begin_p = this->end_p = this->
ptr_p 
  596                    - initOff(this->
ptr_p - this->arrayPtr_p->data(),
 
  597                  this->arrayPtr_p->ndim()-1)*this->step_p;
 
  598    this->end_p += this->arrayPtr_p->shape()[this->axis_p]*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.
Axis independent base for the ArrayAccessor 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