|
STK++ 1.0
|
Templated two dimensional column (vertically) oriented Array. More...
#include <STK_Array2D.h>

Public Types | |
| typedef Array1D< TYPE > | _ContVeType |
| Column type. | |
| typedef ArrayHo< TYPE > | _ContHoType |
| Row type. | |
| typedef IArray2D< TYPE, Array2D< TYPE > > | _IArray2DType |
| Type for the Interface base Class. | |
Public Member Functions | |
| Array2D (Range const &I=Range(), Range const &J=Range()) | |
| Default constructor. | |
| Array2D (Range const &I, Range const &J, TYPE const &v) | |
| constructor with rbeg, rend, cbeg and cend specified, initialization with a constant. | |
| Array2D (const Array2D &T, bool ref=false) | |
| Copy constructor. | |
| Array2D (const Array2D &T, Range const &I, Range const &J) | |
| constructor by reference, ref_=1. | |
| Array2D (TYPE **q, Range const &I, Range const &J) | |
| Wrapper constructor Contruct a reference container. | |
| virtual | ~Array2D () |
| virtual destructor. | |
| Array2D | get2D (Range const &I, Range const &J) const |
| access to a sub-array. | |
| Range | compRangeVe (Integer const &icol) const |
| pseudo virtual method required by IArray2D. | |
| Array2D & | operator= (const Array2D &T) |
| operator = : overwrite the Array2D with T. | |
| Array2D & | operator= (TYPE const &v) |
| operator= : set the container to a constant value. | |
| void | swapRows (Integer const &pos1, Integer pos2) |
| Swapping the pos1 row and the pos2 row. | |
Templated two dimensional column (vertically) oriented Array.
A Array2D is a two-dimensional implementation of an IArray2D.
A column of an Array2D is (almost like) a Array1D and a Row of an Array2D is (almost like) a ArrayHo.
When accessing to a row or a column, the methods return the ArrayHo or Array1D as a reference-like and without copying the data.
The elements of the Array2D can be acceded with the operators () and [].
Definition at line 66 of file STK_Array2D.h.
| typedef Array1D<TYPE> STK::Array2D< TYPE >::_ContVeType |
Column type.
Definition at line 70 of file STK_Array2D.h.
| typedef ArrayHo<TYPE> STK::Array2D< TYPE >::_ContHoType |
Row type.
Definition at line 73 of file STK_Array2D.h.
| typedef IArray2D<TYPE, Array2D<TYPE> > STK::Array2D< TYPE >::_IArray2DType |
Type for the Interface base Class.
Definition at line 76 of file STK_Array2D.h.
| STK::Array2D< TYPE >::Array2D | ( | Range const & | I = Range(), |
| Range const & | J = Range() |
||
| ) | [inline] |
Default constructor.
| I | range of the Rows |
| J | range of the Cols |
Definition at line 82 of file STK_Array2D.h.
Referenced by STK::Array2D< Real >::get2D(), and STK::Array2D< Integer >::get2D().
: _IArray2DType(I, J) { // initialize vertically the container this->initializeCols(J); }
| STK::Array2D< TYPE >::Array2D | ( | Range const & | I, |
| Range const & | J, | ||
| TYPE const & | v | ||
| ) | [inline] |
constructor with rbeg, rend, cbeg and cend specified, initialization with a constant.
| I | range of the Rows |
| J | range of the Cols |
| v | initial value of the container |
Definition at line 95 of file STK_Array2D.h.
: _IArray2DType(I, J) { // initialize vertically the container this->initializeCols(J); // initialize with v for (Integer j=J.first(); j<=J.last(); j++) { TYPE* p(this->data(j)); for (Integer i=I.first(); i<=I.last(); i++) p[i]= v; } }
| STK::Array2D< TYPE >::Array2D | ( | const Array2D< TYPE > & | T, |
| bool | ref = false |
||
| ) | [inline] |
Copy constructor.
| T | the container to copy |
| ref | true if T is wrapped |
Definition at line 112 of file STK_Array2D.h.
| STK::Array2D< TYPE >::Array2D | ( | const Array2D< TYPE > & | T, |
| Range const & | I, | ||
| Range const & | J | ||
| ) | [inline] |
constructor by reference, ref_=1.
| T | the container to wrap |
| I | range of the Rows to wrap |
| J | range of the Cols to wrap |
Definition at line 134 of file STK_Array2D.h.
: _IArray2DType(T, I, J) { ;}
| STK::Array2D< TYPE >::Array2D | ( | TYPE ** | q, |
| Range const & | I, | ||
| Range const & | J | ||
| ) | [inline] |
Wrapper constructor Contruct a reference container.
| q | pointer on the data |
| I | range of the Rows to wrap |
| J | range of the Cols to wrap |
Definition at line 143 of file STK_Array2D.h.
: _IArray2DType(q, I, J) { ;}
| virtual STK::Array2D< TYPE >::~Array2D | ( | ) | [inline, virtual] |
| Array2D STK::Array2D< TYPE >::get2D | ( | Range const & | I, |
| Range const & | J | ||
| ) | const [inline] |
access to a sub-array.
| I | range of the rows |
| J | range of the columns |
Definition at line 155 of file STK_Array2D.h.
{ return Array2D(*this, I, J);}
| Range STK::Array2D< TYPE >::compRangeVe | ( | Integer const & | icol | ) | const [inline] |
pseudo virtual method required by IArray2D.
compute the range of the effectively stored elements in the column icol.
| icol | the index of the column we want to know the range |
Definition at line 162 of file STK_Array2D.h.
{ return this->rangeVe();}
| Array2D& STK::Array2D< TYPE >::operator= | ( | const Array2D< TYPE > & | T | ) | [inline] |
operator = : overwrite the Array2D with T.
We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.
| T | the container to copy |
Definition at line 171 of file STK_Array2D.h.
{
// Resize if necessary.
if ( (this->sizeVe() != T.sizeVe())
||(this->sizeHo() != T.sizeHo())
)
this->resize(T.rangeVe(), T.rangeHo());
// Copy without overlapping
if (T.firstRow()>=this->firstRow())
{
if (T.firstCol()>=this->firstCol())
{
for ( Integer jt=T.firstCol(), j=this->firstCol()
; jt<=T.lastCol()
; j++, jt++
)
{
TYPE *p =this->data(j), *pt =T.data(jt);
for ( Integer it=T.firstRow(), i=this->firstRow()
; it<=T.lastRow()
; i++, it++
)
p[i] = pt[it];
}
return *this;
}
// T.firstCol()<this->firstCol()
for ( Integer jt=T.lastCol(), j=this->lastCol()
; jt>=T.firstCol()
; j--, jt--
)
{
TYPE *p =this->data(j), *pt =T.data(jt);
for ( Integer it=T.firstRow(), i=this->firstRow()
; it<=T.lastRow()
; i++, it++
)
p[i] = pt[it];
}
return *this;
}
// T.firstRow()<this->firstRow()
if (T.firstCol()>=this->firstCol())
{
for ( Integer jt=T.firstCol(), j=this->firstCol()
; jt<=T.lastCol()
; j++, jt++
)
{
TYPE *p =this->data(j), *pt =T.data(jt);
for ( Integer it=T.lastRow(), i=this->lastRow()
; it>=T.firstRow()
; i--, it--
)
p[i] = pt[it] ;
}
return *this;
}
// T.firstCol()<this->firstCol()
for ( Integer jt=T.lastCol(), j=this->lastCol()
; jt>=T.firstCol()
; j--, jt--
)
{
TYPE *p =this->data(j), *pt =T.data(jt);
for ( Integer it=T.lastRow(), i=this->lastRow()
; it>=T.firstRow()
; i--, it--
)
p[i] = pt[it];
}
return *this;
}
| Array2D& STK::Array2D< TYPE >::operator= | ( | TYPE const & | v | ) | [inline] |
| void STK::Array2D< TYPE >::swapRows | ( | Integer const & | pos1, |
| Integer | pos2 | ||
| ) | [inline] |
Swapping the pos1 row and the pos2 row.
| pos1 | position of the first row |
| pos2 | position of the second row |
Definition at line 262 of file STK_Array2D.h.
{
#ifdef STK_BOUNDS_CHECK
// check conditions
if (this->firstRow() > pos1)
{ throw std::out_of_range("IArray2D::swapRows(pos1, pos2) "
"this->firstRow() > pos1");
}
if (this->lastRow() < pos1)
{ throw std::out_of_range("IArray2D::swapRows(pos1, pos2) "
"this->lastRow() < pos1");
}
if (this->firstRow() > pos2)
{ throw std::out_of_range("IArray2D::swapRows(pos1, pos2) "
"this->firstRow() > pos2");
}
if (this->lastRow() < pos2)
{ throw std::out_of_range("IArray2D::swapRows(pos1, pos2) "
"this->lastRow() < pos2");
}
#endif
// swap
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
{
TYPE aux(this->asLeaf().elt(pos1, j));
this->asLeaf().elt(pos1, j) = this->asLeaf().elt(pos2, j);
this->asLeaf().elt(pos2, j) = aux;
}
}