STK++ 1.0

STK::Array2D< TYPE > Class Template Reference

Templated two dimensional column (vertically) oriented Array. More...

#include <STK_Array2D.h>

Inheritance diagram for STK::Array2D< TYPE >:

List of all members.

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.
Array2Doperator= (const Array2D &T)
 operator = : overwrite the Array2D with T.
Array2Doperator= (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.

Detailed Description

template<class TYPE>
class STK::Array2D< TYPE >

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 [].

  • T(2,3) allow to access the third element of the second row of T
  • T(3,Range(1,2)) allow to access to the first two members of the third row of T
  • T(Range(2,3),2) allow to access to the second and third element of the second column of T.
  • T(Range(2,3),Range(1,2)) allow to access to the specified sub-matrix in T.
  • T[2] allow to access to the second column of T.
  • T(3) allow to access to the third row of T.

Definition at line 66 of file STK_Array2D.h.


Member Typedef Documentation

template<class TYPE>
typedef Array1D<TYPE> STK::Array2D< TYPE >::_ContVeType

Column type.

Definition at line 70 of file STK_Array2D.h.

template<class TYPE>
typedef ArrayHo<TYPE> STK::Array2D< TYPE >::_ContHoType

Row type.

Definition at line 73 of file STK_Array2D.h.

template<class TYPE>
typedef IArray2D<TYPE, Array2D<TYPE> > STK::Array2D< TYPE >::_IArray2DType

Type for the Interface base Class.

Definition at line 76 of file STK_Array2D.h.


Constructor & Destructor Documentation

template<class TYPE>
STK::Array2D< TYPE >::Array2D ( Range const &  I = Range(),
Range const &  J = Range() 
) [inline]

Default constructor.

Parameters:
Irange of the Rows
Jrange 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);
    }
template<class TYPE>
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.

Parameters:
Irange of the Rows
Jrange of the Cols
vinitial 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;
      }
    }
template<class TYPE>
STK::Array2D< TYPE >::Array2D ( const Array2D< TYPE > &  T,
bool  ref = false 
) [inline]

Copy constructor.

Parameters:
Tthe container to copy
reftrue if T is wrapped

Definition at line 112 of file STK_Array2D.h.

           : _IArray2DType(T, ref)
    {
      if (!ref)
      {
        // initialize the Cols and Rows
        this->initializeCols(T.rangeHo());
        for (Integer j=T.firstCol(); j<=T.lastCol(); j++)
        {
          // ptr on the rows
          TYPE* p = this->data(j);
          TYPE* pt= T.data(j);
          for (Integer i=T.firstRow(); i<=T.lastRow(); i++) p[i]=pt[i];
        }
      }
    }
template<class TYPE>
STK::Array2D< TYPE >::Array2D ( const Array2D< TYPE > &  T,
Range const &  I,
Range const &  J 
) [inline]

constructor by reference, ref_=1.

Parameters:
Tthe container to wrap
Irange of the Rows to wrap
Jrange of the Cols to wrap

Definition at line 134 of file STK_Array2D.h.

           : _IArray2DType(T, I, J)
    { ;}
template<class TYPE>
STK::Array2D< TYPE >::Array2D ( TYPE **  q,
Range const &  I,
Range const &  J 
) [inline]

Wrapper constructor Contruct a reference container.

Parameters:
qpointer on the data
Irange of the Rows to wrap
Jrange of the Cols to wrap

Definition at line 143 of file STK_Array2D.h.

           : _IArray2DType(q, I, J)
    { ;}
template<class TYPE>
virtual STK::Array2D< TYPE >::~Array2D ( ) [inline, virtual]

virtual destructor.

Definition at line 148 of file STK_Array2D.h.

    { ;}

Member Function Documentation

template<class TYPE>
Array2D STK::Array2D< TYPE >::get2D ( Range const &  I,
Range const &  J 
) const [inline]

access to a sub-array.

Parameters:
Irange of the rows
Jrange of the columns

Definition at line 155 of file STK_Array2D.h.

    { return Array2D(*this, I, J);}
template<class TYPE>
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.

Parameters:
icolthe index of the column we want to know the range

Definition at line 162 of file STK_Array2D.h.

    { return this->rangeVe();}
template<class TYPE>
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.

Parameters:
Tthe 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;
    }
template<class TYPE>
Array2D& STK::Array2D< TYPE >::operator= ( TYPE const &  v) [inline]

operator= : set the container to a constant value.

Parameters:
vthe value to set

Definition at line 248 of file STK_Array2D.h.

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { TYPE *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] = v;
      }
      return *this;
    }
template<class TYPE>
void STK::Array2D< TYPE >::swapRows ( Integer const &  pos1,
Integer  pos2 
) [inline]

Swapping the pos1 row and the pos2 row.

Parameters:
pos1position of the first row
pos2position 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;
      }
    }

The documentation for this class was generated from the following file: