|
STK++ 1.0
|
Templated interface base class for two-dimensional arrays. More...
#include <STK_IArray2D.h>

Public Member Functions | |
| virtual | ~IArray2D () |
| Virtual destructor. | |
| TYPE & | elt (Integer const &i, Integer const &j) |
| access to one element. | |
| TYPE const & | elt (Integer const &i, Integer const &j) const |
| access to one element const. | |
| Array1D< TYPE > | col (Range const &I, Integer const &j) const |
| access to a part of a column. | |
| Array1D< TYPE > | col (Integer const &j) const |
| access to a column. | |
| ArrayHo< TYPE > | row (Integer const &i, Range const &J) const |
| access to a part of a row. | |
| ArrayHo< TYPE > | row (Integer const &i) const |
| access to a row. | |
| void | clear () |
| clear the object. | |
| void | shift (Integer const &rbeg=1, Integer const &cbeg=1) |
| New first indexes for the object. | |
| void | shiftVe (Integer const &rbeg=1) |
| New beginning index for the Rows of the object. | |
| void | pushBackRows (Integer const &n=1) |
| Add n Rows to the container. | |
| void | insertRows (Integer const &pos, Integer const &n=1) |
| Insert n Rows at the position pos of the container. | |
| void | popBackRows (Integer const &n=1) |
| Delete last Rows of the container. | |
| void | eraseRows (Integer const &pos, Integer const &n=1) |
| Delete n Rows at the pos index to the container. | |
| void | pushBackCols (Integer const &n=1) |
| Add n Cols to the container. | |
| void | insertCols (Integer const &pos, Integer const &n=1) |
| Insert n Columns at the index pos to the container. | |
| void | popBackCols (Integer const &n=1) |
| Delete last Cols of the container. | |
| void | eraseCols (Integer const &pos, Integer const &n=1) |
| Delete n Cols at the specified position of the container. | |
| void | update (Range const &J) |
| Update the cols of the container in the specified range. | |
| void | update (Integer const &pos) |
| Update the cols of the container in the specified position. | |
Protected Member Functions | |
| IArray2D (Range const &I=Range(), Range const &J=Range()) | |
| Default constructor. | |
| IArray2D (const IArray2D &T, bool ref=false) | |
| Copy constructor. | |
| IArray2D (const IArray2D &T, Range const &I, Range const &J) | |
| constructor by reference, ref_=1. | |
| IArray2D (TYPE **q, Range const &I, Range const &J) | |
| Wrapper constructor The Container is a ref. | |
| void | freeMem () |
| Memory deallocation. | |
| void | initialize (Range const &I, Range const &J) |
| Function for memory allocation and initialization. | |
| void | initializeCols (Range const &J) |
| Function for memory allocation and initialization. | |
| void | initializeCol (Integer const &pos, Range const &I) |
| internal method for initializing a column. | |
| void | freeCols (Range const &J) |
| vertical memory deallocation. | |
| void | freeCol (Integer const &pos) |
| Method for memory deallocation. | |
| void | shiftCol (Integer const &pos, Integer const &beg) |
| internal method for translating a column. | |
| void | resizeCol (Integer const &pos, Range const &I) |
| Internal method for resizing a column with a specified range. | |
| void | insertRowsToCol (Integer const &col, Integer const &pos, Integer const &n=1) |
| Internal method for inserting rows to a specified column. | |
| void | pushBackRowsToCol (Integer const &col, Integer const &n=1) |
| Internal method for appending rows to a specified column. | |
| void | eraseRowsToCol (Integer const &col, Integer const &pos, Integer const &n=1) |
| Internal method for deleting rows to a specified column. | |
| void | popBackRowsToCol (Integer const &col, Integer const &n=1) |
| Internal method for deleting last rows to a specified column. | |
Private Types | |
| typedef IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE > , Array1D< TYPE >, TArray2D > | _IArrayBaseType |
| type of the Base Container Class. | |
Templated interface base class for two-dimensional arrays.
A IArray2D is a specialized interface class for two-dimensional containers stored in columns. All derived class from IArray2D access to the column using a TYPE* ptr.
Template parameter description:
TYPE is the fundamental type of the data stored in the container.TArray2D is the name of the class implementing IArray2D.The derived class have to implement the following public method
Range compRangeVe( Integer const& icol) const
Definition at line 75 of file STK_IArray2D.h.
typedef IArray2DBase< TYPE, TYPE*, ArrayHo<TYPE>, Array1D<TYPE>, TArray2D> STK::IArray2D< TYPE, TArray2D >::_IArrayBaseType [private] |
type of the Base Container Class.
Reimplemented from STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >.
Reimplemented in STK::MatrixUpperTriangular.
Definition at line 84 of file STK_IArray2D.h.
| STK::IArray2D< TYPE, TArray2D >::IArray2D | ( | Range const & | I = Range(), |
| Range const & | J = Range() |
||
| ) | [inline, protected] |
Default constructor.
| I | range of the Rows |
| J | range of the Cols |
Definition at line 91 of file STK_IArray2D.h.
: _IArrayBaseType(I, J) { ;}
| STK::IArray2D< TYPE, TArray2D >::IArray2D | ( | const IArray2D< TYPE, TArray2D > & | T, |
| bool | ref = false |
||
| ) | [inline, protected] |
Copy constructor.
| T | the container to copy |
| ref | true if we wrap T |
Definition at line 99 of file STK_IArray2D.h.
: _IArrayBaseType(T, ref) { ;}
| STK::IArray2D< TYPE, TArray2D >::IArray2D | ( | const IArray2D< TYPE, TArray2D > & | T, |
| Range const & | I, | ||
| Range const & | J | ||
| ) | [inline, protected] |
constructor by reference, ref_=1.
| T | the container to copy |
| I | range of the Rows to wrap |
| J | range of the Col to wrap |
Definition at line 108 of file STK_IArray2D.h.
: _IArrayBaseType(T, I, J) { ;}
| STK::IArray2D< TYPE, TArray2D >::IArray2D | ( | TYPE ** | q, |
| Range const & | I, | ||
| Range const & | J | ||
| ) | [inline, protected] |
Wrapper constructor The Container is a ref.
| q | pointer on data |
| I | range of the Rows to wrap |
| J | range of the Cols to wrap |
Definition at line 117 of file STK_IArray2D.h.
: _IArrayBaseType(q, I, J) { ;}
| virtual STK::IArray2D< TYPE, TArray2D >::~IArray2D | ( | ) | [inline, virtual] |
Virtual destructor.
free the vertically allocated memory (the columns). The horizontally allocated memory is handled by the IArrayBase class.
Definition at line 126 of file STK_IArray2D.h.
| TYPE& STK::IArray2D< TYPE, TArray2D >::elt | ( | Integer const & | i, |
| Integer const & | j | ||
| ) | [inline] |
access to one element.
| i | index of the row |
| j | index of the col |
Definition at line 136 of file STK_IArray2D.h.
{ return this->data(j)[i];}
| TYPE const& STK::IArray2D< TYPE, TArray2D >::elt | ( | Integer const & | i, |
| Integer const & | j | ||
| ) | const [inline] |
access to one element const.
| i | index of the row |
| j | index of the col |
Definition at line 144 of file STK_IArray2D.h.
{ return this->data(j)[i];}
| Array1D<TYPE> STK::IArray2D< TYPE, TArray2D >::col | ( | Range const & | I, |
| Integer const & | j | ||
| ) | const [inline] |
access to a part of a column.
| I | range of the rows |
| j | index of the column |
Definition at line 152 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::eraseRowsToCol(), STK::IArray2D< Integer, Array2D< Integer > >::insertRowsToCol(), STK::IArray2D< Integer, Array2D< Integer > >::popBackRowsToCol(), and STK::IArray2D< Integer, Array2D< Integer > >::pushBackRowsToCol().
{ return Array1D<TYPE>(this->data(j), I, j);}
| Array1D<TYPE> STK::IArray2D< TYPE, TArray2D >::col | ( | Integer const & | j | ) | const [inline] |
access to a column.
| j | index of the column |
Definition at line 159 of file STK_IArray2D.h.
| ArrayHo<TYPE> STK::IArray2D< TYPE, TArray2D >::row | ( | Integer const & | i, |
| Range const & | J | ||
| ) | const [inline] |
access to a part of a row.
| i | index of the row |
| J | range of the columns |
Definition at line 167 of file STK_IArray2D.h.
{ return ArrayHo<TYPE>(*this, J, i);}
| ArrayHo<TYPE> STK::IArray2D< TYPE, TArray2D >::row | ( | Integer const & | i | ) | const [inline] |
access to a row.
| i | index of the row |
Reimplemented in STK::Array2D< Real >.
Definition at line 174 of file STK_IArray2D.h.
{ return ArrayHo<TYPE>(*this, this->rangeHo(), i);}
| void STK::IArray2D< TYPE, TArray2D >::clear | ( | ) | [inline] |
clear the object.
This will free all allocated memory and reset all range to 1:0.
Definition at line 181 of file STK_IArray2D.h.
Referenced by STK::Qr::clear(), STK::Svd::clearU(), STK::Svd::clearV(), and STK::IArray2D< Integer, Array2D< Integer > >::initialize().
| void STK::IArray2D< TYPE, TArray2D >::shift | ( | Integer const & | rbeg = 1, |
| Integer const & | cbeg = 1 |
||
| ) | [inline, virtual] |
New first indexes for the object.
| rbeg | the index of the first row to set |
| cbeg | the index of the first column to set |
Implements STK::IContainer2D.
Definition at line 193 of file STK_IArray2D.h.
Referenced by STK::Svd::init(), and STK::Qr::run().
| void STK::IArray2D< TYPE, TArray2D >::shiftVe | ( | Integer const & | rbeg = 1 | ) | [inline] |
New beginning index for the Rows of the object.
| rbeg | the index of the first row to set |
Definition at line 204 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::shift().
{
// compute increment
Integer rinc = rbeg - this->firstRow();
// if there is something to do
if (rinc != 0)
{
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::shiftVe(rbeg) "
"can't operate on references.");
}
// translate rangeVe_()
this->incRangeVe(rinc);
// For all cols, move begin
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
{
shiftCol(j, this->rangeCols_[j].first()+rinc);
}
}
}
| void STK::IArray2D< TYPE, TArray2D >::pushBackRows | ( | Integer const & | n = 1 | ) | [inline, virtual] |
Add n Rows to the container.
| n | number of Rows to add |
Implements STK::IContainer2D.
Definition at line 229 of file STK_IArray2D.h.
{
// if n<=0 nothing to do
if (n <= 0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::pushBackRows(n) "
"can't operate on references.");
}
// If the container have no rows : create its
if (this->sizeVe() <=0)
{
// update the range of the container
this->incLastVe(n);
// initialize the container
this->initializeCols(this->rangeHo());
}
else
{
// update the range of the rows
this->incLastVe(n);
// allocate new Rows for each Col
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
{
// compute range from the leaf
Range range(this->asLeaf().compRangeVe(j));
// if there is no column or the end is less than the container
// end
if ((range.size()>0)&&(range.last()>this->lastRow()-n))
{
// if the column is empty create it
if (this->rangeCols_[j].size()<=0)
{
this->initializeCol(j, range);
}
else
{
// compute position
Integer pos(this->lastRow()-n+1);
// add elts
insertRowsToCol(j, pos, range.last() - pos +1);
}
}
}
}
}
| void STK::IArray2D< TYPE, TArray2D >::insertRows | ( | Integer const & | pos, |
| Integer const & | n = 1 |
||
| ) | [inline] |
Insert n Rows at the position pos of the container.
If pos is outside the range of a column, then the method do nothing.
| pos | index where to insert Rows |
| n | number of elements to insert (default 1) |
Definition at line 282 of file STK_IArray2D.h.
{
// if n<=0 nothing to do
if (n <= 0) return;
#ifdef STK_BOUNDS_CHECK
// check indices
if (this->firstRow() > pos)
{ throw std::out_of_range("IArray2D::insertRows(pos, n) "
"this->firstRow() > pos");
}
if (this->lastRow()+1 < pos)
{ throw std::out_of_range("IArray2D::insertRows(pos, n) "
"this->lastRow()+1 < pos");
}
#endif
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::insertRows(pos, n) "
"can't operate on references.");
}
// update the range of the rows
this->incLastVe(n);
// allocate new Rows for each Col
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
{
// check position
if ( (pos >= this->rangeCols_[j].first())
||(pos <= this->rangeCols_[j].last()+1)
)
{
insertRowsToCol(j, pos, n);
}
}
}
| void STK::IArray2D< TYPE, TArray2D >::popBackRows | ( | Integer const & | n = 1 | ) | [inline, virtual] |
Delete last Rows of the container.
| n | number of Rows to delete |
Implements STK::IContainer2D.
Definition at line 320 of file STK_IArray2D.h.
{
// if n<=0 nothing to do
if (n <= 0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::popBackRows() "
"can't operate on references.");
}
#ifdef STK_BOUNDS_CHECK
// if there is Rows to erase
if (this->sizeVe()<n)
{ throw std::out_of_range("IArray2D::popBackRows(n) "
"this->sizeVe() < n");
}
#endif
// update range of the container
this->decLastVe(n);
// decrease range of each Col
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
eraseRowsToCol(j, this->lastRow()+1, n);
}
| void STK::IArray2D< TYPE, TArray2D >::eraseRows | ( | Integer const & | pos, |
| Integer const & | n = 1 |
||
| ) | [inline] |
Delete n Rows at the pos index to the container.
| pos | index where to delete elements |
| n | number of elements to delete (default 1) |
Definition at line 347 of file STK_IArray2D.h.
{
// if n==0 nothing to do
if (n<=0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::eraseRows(pos, n) "
"can't operate on references.");
}
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstRow() > pos)
{ throw std::out_of_range("IArray2D::eraseRows(pos, n) "
"this->firstRow() > pos");
}
if (this->lastRow() < pos)
{ throw std::out_of_range("IArray2D::eraseRows(pos, n)"
" this->lastRow() < pos");
}
if (this->lastRow() < pos+n-1)
{ throw std::out_of_range("IArray2D::eraseRows(pos, n)"
" this->lastRow() < pos+n-1");
}
#endif
// save posistion and size
Integer posRow = pos, nbRow = n;
// update dimensions
this->decLastVe(n);
// update each Col
for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
eraseRowsToCol(j, posRow, nbRow);
}
| void STK::IArray2D< TYPE, TArray2D >::pushBackCols | ( | Integer const & | n = 1 | ) | [inline, virtual] |
Add n Cols to the container.
| n | the number of Cols to add |
Implements STK::IContainer2D.
Definition at line 383 of file STK_IArray2D.h.
Referenced by STK::Qr::compQ(), and STK::Qr::pushBackCol().
{
// if n<=0 nothing to do
if (n <= 0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::pushBackCols(n) "
"can't operate on references.");
}
// If the container have no Cols : create its
if (this->sizeHo() <=0)
{
// update end col
this->incLastHo(n);
// initialize Horizontally the container
this->mallocHo(this->rangeHo());
// initialize Vertically the container
initializeCols( this->rangeHo());
}
else // else insert to the end of the container
insertCols(this->lastCol()+1, n);
}
| void STK::IArray2D< TYPE, TArray2D >::insertCols | ( | Integer const & | pos, |
| Integer const & | n = 1 |
||
| ) | [inline] |
Insert n Columns at the index pos to the container.
| pos | the position of the inserted Cols |
| n | the number of column to insert |
Definition at line 410 of file STK_IArray2D.h.
Referenced by STK::Qr::insertCol(), and STK::IArray2D< Integer, Array2D< Integer > >::pushBackCols().
{
// if n<=0 nothing to do
if (n <= 0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::insertCols(pos, n) "
"can't operate on references.");
}
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > pos)
{ throw std::out_of_range("IArray2D::insertCols(pos, n) "
"this->firstCol() > pos");
}
if (this->lastCol()+1 < pos)
{ throw std::out_of_range("IArray2D::insertCols(pos, n) "
"this->lastCol()+1 < pos");
}
#endif
// compute horizontal range of the container after insertion
Range range_ho(this->rangeHo());
range_ho.incLast(n);
// allocate, if necessary, the mem for the Cols
if (this->capacityHo() < range_ho.size()) // not enough space
{
// temporary empty container (the number of Rows is the same)
// but there is no Cols
TArray2D Taux(this->rangeVe(), Range());
// swap with Taux
this->swap(Taux);
// initialize columns of the container
try
{
this->mallocHo(range_ho);
}
catch (std::runtime_error & error) // if an error occur
{
this->swap(Taux); // restore container
throw error; // and send again the stdexcept
}
// set the range of the Columns
this->setRangeHo(range_ho);
// move first Columns from Taux to this
for (Integer k=this->firstCol(); k<pos; k++)
this->transferColumn(Taux, k, k);
// translate and copy last Cols from Taux to this
for (Integer k=Taux.lastCol(); k>=pos; k--)
this->transferColumn(Taux, k+n, k);
}
else // enough space -> shift the last Cols
{
Range addRange(this->lastCol()+1, this->lastCol()+n);
// insert capacity for the new Cols
this->capacityCols_.insert(addRange, 0);
// insert range for the new Cols
this->rangeCols_.insert(addRange, Range());
// update range_
this->incLastHo(n);
// translate data
for (Integer k=this->lastCol()-n; k>=pos; k--)
this->transferColumn( this->asLeaf(), k+n, k);
}
// initialize the rows for the Cols, this->capacityCols_, this->rangeCols_
// in the range pos:pos+n-1
this->initializeCols(Range(pos, pos+n-1));
}
| void STK::IArray2D< TYPE, TArray2D >::popBackCols | ( | Integer const & | n = 1 | ) | [inline, virtual] |
Delete last Cols of the container.
| n | the number of Cols to delete |
Implements STK::IContainer2D.
Definition at line 481 of file STK_IArray2D.h.
Referenced by STK::Qr::compQ(), and STK::Qr::popBackCols().
{
// if n<=0 nothing to do
if (n<=0) return;
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::popBackCols(n) "
"can't operate on references.");
}
#ifdef STK_BOUNDS_CHECK
// check range
if (this->sizeHo() < n)
{ throw std::out_of_range("IArray2D::popBackCols(n) "
"this->sizeHo() < n");
}
#endif
// delete each col
this->freeCols(Range(this->lastCol()-n+1, this->lastCol()));
// update this->capacityCols_
this->capacityCols_.popBack(n);
// update this->rangeCols_
this->rangeCols_.popBack(n);
// update rangeHo
this->decLastHo(n);
// if there is no more Cols
if (this->sizeHo() == 0) this->freeMem();
}
| void STK::IArray2D< TYPE, TArray2D >::eraseCols | ( | Integer const & | pos, |
| Integer const & | n = 1 |
||
| ) | [inline] |
Delete n Cols at the specified position of the container.
| pos | the position of the deleted Cols |
| n | the number of column to delete |
Definition at line 513 of file STK_IArray2D.h.
Referenced by STK::Qr::eraseCol().
{
if (n<=0) return; // if n<=0 nothing to do
#ifdef STK_BOUNDS_CHECK
// check range
if (this->firstCol() > pos)
{ throw std::out_of_range("IArray2D::eraseCols(pos, n) "
"this->firstCol() > pos");
}
if (this->lastCol() < pos)
{ throw std::out_of_range("IArray2D::eraseCols(pos, n) "
"this->lastCol() < pos");
}
if (this->lastCol() < pos+n-1)
{ throw std::out_of_range("IArray2D::eraseCols(pos, n) "
"this->lastCol() < pos+n-1");
}
#endif
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray2D::eraseCols(pos, n) "
"can't operate on references.");
}
// delete each col
this->freeCols(Range(pos, pos+n-1));
// update rangeHo_
this->decLastHo(n);
// shift Cols
for (Integer k=pos; k<=this->lastCol(); k++)
this->setData(k, this->data(k+n));
// update this->capacityCols_
this->capacityCols_.erase(pos, n);
// update this->rangeCols_
this->rangeCols_.erase(pos, n);
// if there is no more Cols
if (this->sizeHo() == 0) this->freeMem();
}
| void STK::IArray2D< TYPE, TArray2D >::update | ( | Range const & | J | ) | [inline] |
Update the cols of the container in the specified range.
| J | range of the column to udpate |
Definition at line 554 of file STK_IArray2D.h.
Referenced by STK::Qr::eraseCol(), and STK::Qr::insertCol().
{
#ifdef STK_BOUNDS_CHECK
// check range
if (this->firstCol() > J.first())
{ throw std::out_of_range("IArray2D::update(J) "
"this->firstCol() > J.first()");
}
if (this->lastCol() < J.last())
{ throw std::out_of_range("IArray2D::update(J) "
"this->lastCol() < J.last()");
}
#endif
Integer first_col(J.first());
Integer last_col(J.last());
for ( Integer icol = first_col; icol <= last_col ; ++icol)
{
if (this->asLeaf().compRangeVe(icol) != this->rangeCol(icol))
{ this->resizeCol(icol, this->asLeaf().compRangeVe(icol));}
}
}
| void STK::IArray2D< TYPE, TArray2D >::update | ( | Integer const & | pos | ) | [inline] |
Update the cols of the container in the specified position.
| pos | index of the column to update |
Definition at line 580 of file STK_IArray2D.h.
{
#ifdef STK_BOUNDS_CHECK
// check range
if (this->firstCol() > pos)
{ throw std::out_of_range("IArray2D::update(pos) "
"this->firstCol() > pos");
}
if (this->lastCol() < pos)
{ throw std::out_of_range("IArray2D::update(pos) "
"this->lastCol() < pos");
}
#endif
if (this->asLeaf().compRangeVe(pos) != this->rangeCol(pos))
{ this->resizeCol(pos, this->asLeaf().compRangeVe(pos));}
}
| void STK::IArray2D< TYPE, TArray2D >::freeMem | ( | ) | [inline, protected] |
Memory deallocation.
This method clear all allocated memory. The range of the Cols is set to (beginHo_:beginHo_-1). The range of the Rows remain unmodified.
Definition at line 603 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::clear(), STK::IArray2D< Integer, Array2D< Integer > >::eraseCols(), and STK::IArray2D< Integer, Array2D< Integer > >::popBackCols().
| void STK::IArray2D< TYPE, TArray2D >::initialize | ( | Range const & | I, |
| Range const & | J | ||
| ) | [inline, protected] |
Function for memory allocation and initialization.
This method will free all allocated memory owned by this container before initialization. If you don't want to free the allocatd memory, you should use resize(I, J)
| I | range of the Rows |
| J | range of the Cols |
Definition at line 620 of file STK_IArray2D.h.
{
// check if there is memory allocated
this->clear();
// if we initialize the memory the container is not a reference
this->setRef(false);
// create this->capacityCols_
this->capacityCols_.resize(J);
// create this->rangeCols_
this->rangeCols_.resize(J);
// set the Horizontal range of the container
this->setRangeHo(J);
// initialize Horizontally the container
this->mallocHo(J);
// set the vertical range of the container
this->setRangeVe(I);
// initialize Vertically the container
this->initializeCols(J);
}
| void STK::IArray2D< TYPE, TArray2D >::initializeCols | ( | Range const & | J | ) | [inline, protected] |
Function for memory allocation and initialization.
The capacity for the Rows have to be set before calling this method.
| J | vertical range of the Cols to initialize |
Definition at line 645 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::initialize(), STK::IArray2D< Integer, Array2D< Integer > >::insertCols(), STK::IArray2D< Integer, Array2D< Integer > >::pushBackCols(), and STK::IArray2D< Integer, Array2D< Integer > >::pushBackRows().
{
// for each col
for (Integer j=J.first(); j<=J.last(); j++)
{
// try to Allocate mem for the jth col
try
{
// initialize the cols with the computed range
// specific to the container
this->initializeCol(j, this->asLeaf().compRangeVe(j));
}
catch (std::runtime_error & error) // if an error occur
{
// free each column allocated
for (Integer k=J.first(); k<j; k++)
this->freeCol(k);
// put default for the other Cols
for (Integer k=j; k<=J.last(); k++) this->setData(k);
// and throw an stdexcept
throw error;
}
}
}
| void STK::IArray2D< TYPE, TArray2D >::initializeCol | ( | Integer const & | pos, |
| Range const & | I | ||
| ) | [inline, protected] |
internal method for initializing a column.
Method for the the allocation of memory of the col pos with the given range.
| pos | the index of the column to initialize |
| I | range of the Col |
Definition at line 677 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::initializeCols(), STK::IArray2D< Integer, Array2D< Integer > >::insertRowsToCol(), STK::IArray2D< Integer, Array2D< Integer > >::pushBackRows(), and STK::IArray2D< Integer, Array2D< Integer > >::pushBackRowsToCol().
{
if (I.size() <=0)
{
// set default for ptr
this->setData(pos, (TYPE*)NULL);
// set default value for this->capacityCols_[pos]
this->capacityCols_[pos] = 0;
// set default value for this->rangeCols_[pos]
this->rangeCols_[pos] = I;
// return
return;
}
// compute the size necessary (cannot be 0)
Integer size = this->evalCapacity(I.size());
// try to allocate memory
try
{
this->setData(pos, new TYPE[size]);
}
catch (std::bad_alloc & error) // if an alloc error occur
{
// set default for ptr
this->setData(pos, (TYPE*)NULL);
// set default value for this->capacityCols_[pos]
this->capacityCols_[pos] = 0;
// set default value for this->rangeCols_[pos]
this->rangeCols_[pos] = Range();
// and throw an stdexcept
throw std::runtime_error("IArray2D::initializeCol(pos, J) "
"memory allocation failed.");
}
// increment ptr of the column
this->data(pos) -= I.first();
// set size for this->capacityCols_[pos]
this->capacityCols_[pos] = size;
// set value for this->rangeCols_[pos]
this->rangeCols_[pos] = I;
}
| void STK::IArray2D< TYPE, TArray2D >::freeCols | ( | Range const & | J | ) | [inline, protected] |
vertical memory deallocation.
| J | the range of the Cols to liberate. |
Definition at line 720 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::eraseCols(), STK::IArray2D< Integer, Array2D< Integer > >::freeMem(), STK::IArray2D< Integer, Array2D< Integer > >::popBackCols(), and STK::IArray2D< Integer, Array2D< Integer > >::~IArray2D().
| void STK::IArray2D< TYPE, TArray2D >::freeCol | ( | Integer const & | pos | ) | [inline, protected] |
Method for memory deallocation.
| pos | the number of the column to free |
Definition at line 730 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::eraseRowsToCol(), STK::IArray2D< Integer, Array2D< Integer > >::freeCols(), STK::IArray2D< Integer, Array2D< Integer > >::initializeCols(), and STK::IArray2D< Integer, Array2D< Integer > >::popBackRowsToCol().
{
if (this->data(pos)) // if there is cols
{
// increment the ptr
this->data(pos) += this->rangeCols_[pos].first();
// delete allocated mem for the column pos
delete [] this->data(pos);
// set default value for ptr
this->setData(pos, (TYPE*)NULL);
// set default value for this->capacityCols_[pos]
this->capacityCols_[pos] = 0;
// set default value for this->rangeCols_[pos]
this->rangeCols_[pos] = Range();
}
}
| void STK::IArray2D< TYPE, TArray2D >::shiftCol | ( | Integer const & | pos, |
| Integer const & | beg | ||
| ) | [inline, protected] |
internal method for translating a column.
Method for the the allocation of memory of the col pos with the given range.
| pos | the index of the column to translate |
| beg | new begin ofthe col |
Definition at line 754 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::resizeCol(), and STK::IArray2D< Integer, Array2D< Integer > >::shiftVe().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > pos)
{ throw std::out_of_range("IArray2D::shiftCol(pos, n) "
"this->firstCol() > pos");
}
if (this->lastCol() < pos)
{ throw std::out_of_range("IArray2D::shiftCol(pos, n) "
"this->lastCol() < pos");
}
#endif
// compute increment
Integer rinc = beg - this->rangeCols_[pos].first();
// check if there is data
if (this->data(pos))
{
// transate ptr
this->data(pos) -= rinc;
}
// translate this->rangeCols_
this->rangeCols_[pos].inc(rinc);
}
| void STK::IArray2D< TYPE, TArray2D >::resizeCol | ( | Integer const & | pos, |
| Range const & | I | ||
| ) | [inline, protected] |
Internal method for resizing a column with a specified range.
This method resize the column pos to the desired range using:
shiftCol popBackRowsToCol or pushBackRowsToCol if needed. | pos | index of the column |
| I | range to set to the column |
Definition at line 789 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::update().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > pos)
{ throw std::out_of_range("IArray2D::resizeCol(pos, I) "
"this->firstCol() > pos");
}
if (this->lastCol() < pos)
{ throw std::out_of_range("IArray2D::resizeCol(pos, I) "
"this->lastCol() < pos");
}
#endif
// check if there is something to do
if (this->rangeCol(pos) == I) return;
// shift to the desired first index
shiftCol(pos, I.first());
// compute difference of size
Integer inc = this->rangeCol(pos).size() - I.size();
// nothing to do
if (inc == 0) return;
// add row
if (inc < 0)
{
pushBackRowsToCol(pos, -inc);
}
else // delete rows
{
popBackRowsToCol(pos, inc);
}
}
| void STK::IArray2D< TYPE, TArray2D >::insertRowsToCol | ( | Integer const & | col, |
| Integer const & | pos, | ||
| Integer const & | n = 1 |
||
| ) | [inline, protected] |
Internal method for inserting rows to a specified column.
Insert n Rows at the position pos to the column column of the container. No check is done about the index.
| col | column index |
| pos | index where to insert Rows |
| n | number of elements to insert (default 1) |
Definition at line 829 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::insertRows(), and STK::IArray2D< Integer, Array2D< Integer > >::pushBackRows().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > col)
{ throw std::out_of_range("IArray2D::insertRowsToCol(col, n) "
"this->firstCol() > col");
}
if (this->lastCol() < col)
{ throw std::out_of_range("IArray2D::insertRowsToCol(col, n) "
"this->lastCol() < col");
}
if (this->rangeCols_[col].first() > pos)
{ throw std::out_of_range("IArray2D::insertRowsToCol(col, pos, n) "
"this->rangeCols_[col].first() > pos");
}
if (this->rangeCols_[col].last()+1 < pos)
{ throw std::out_of_range("IArray2D::insertRowsToCol(col, pos, n) "
"this->rangeCols_[col].last()+1 < pos");
}
#endif
// wrap old Col
TYPE* ptr_old_col(this->data(col));
// get vertical range of the Col
Range range_ve(this->rangeCols_[col]);
// update range
this->rangeCols_[col].incLast(n);
// allocate if necessary the Col
if (this->capacityCols_[col] < this->rangeCols_[col].size())
{
// create new Col
this->initializeCol(col, this->rangeCols_[col]);
// if there was data, copy and liberate
if (ptr_old_col)
{
// get ptr on the new col
TYPE* ptr_new_col(this->data(col));
// copy first Elts
for (Integer k=range_ve.first(); k<pos; k++)
ptr_new_col[k] = ptr_old_col[k];
// translate and copy last Elts
for (Integer k=range_ve.last(); k>=pos; k--)
ptr_new_col[k+n] = ptr_old_col[k];
// increment ptr_col
ptr_old_col += range_ve.first();
// and free old col
delete [] ptr_old_col;
}
}
else // enough space
{
// translate last Elts
for (Integer k=range_ve.last(); k>=pos; k--)
ptr_old_col[k+n] = ptr_old_col[k];
}
}
| void STK::IArray2D< TYPE, TArray2D >::pushBackRowsToCol | ( | Integer const & | col, |
| Integer const & | n = 1 |
||
| ) | [inline, protected] |
Internal method for appending rows to a specified column.
Push back n Rows at the end of the column column of the container.
| col | column index |
| n | number of elements to append (default 1) |
Definition at line 896 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::resizeCol().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > col)
{ throw std::out_of_range("IArray2D::pushBackRowsToCol(col, n) "
"this->firstCol() > col");
}
if (this->lastCol() < col)
{ throw std::out_of_range("IArray2D::pushBackRowsToCol(col, n) "
"this->lastCol() < col");
}
#endif
// wrap old Col
TYPE* ptr_old_col(this->data(col));
// get vertical range of the Col
Range range_ve(this->rangeCol(col));
// compute vertical range of the Col after insertion
//range_ve.incLast(n);
this->rangeCols_[col].incLast(n);
// allocate if necessary the Col
if (this->capacityCols_[col] < range_ve.size())
{
// create new Col
this->initializeCol(col, this->rangeCols_[col]);
// ger ptr on the new col
TYPE* ptr_new_col(this->data(col));
// copy first Elts
for (Integer k=range_ve.first(); k<=range_ve.last(); k++)
ptr_new_col[k] = ptr_old_col[k];
// if there is data
if (ptr_old_col)
{
// increment ptr_col
ptr_old_col += range_ve.first();
// and free old col
delete [] ptr_old_col;
}
}
}
| void STK::IArray2D< TYPE, TArray2D >::eraseRowsToCol | ( | Integer const & | col, |
| Integer const & | pos, | ||
| Integer const & | n = 1 |
||
| ) | [inline, protected] |
Internal method for deleting rows to a specified column.
Delete n Rows at the position pos to the column col of the container. No check is done about indexes. It is possible to remove data outside the range of the column. In this case it is assumed that the data are known and there was no necessity to store them inside the container.
TODO save memory after deletion if capacity is really too large ?
| col | index of the Col |
| pos | index where to delete elements |
| n | number of elements to delete (default 1) |
Definition at line 954 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::eraseRows(), and STK::IArray2D< Integer, Array2D< Integer > >::popBackRows().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > col)
{ throw std::out_of_range("IArray2D::eraseRowsToCol(col, pos, n) "
"this->firstCol() > col");
}
if (this->lastCol() < col)
{ throw std::out_of_range("IArray2D::eraseRowsToCol(col, pos, n) "
"this->lastCol() < col");
}
#endif
// ptr on data
TYPE* p_col(this->data(col));
// range of the data (can be different from the range of the container)
Range rangeCol(this->rangeCols_[col]);
// number of rows to delete
Integer nRowsToDelete = n;
// position of the row to delete
Integer firstRowToDelete = pos;
// if pos is after the data there is nothing to delete
if (rangeCol.first()>rangeCol.last()) return;
// if pos is before the data
if (firstRowToDelete<rangeCol.first())
{
// remove the not existing data !
nRowsToDelete -= nRowsToDelete -rangeCol.first();
// if there is no more rows to delete return
if (nRowsToDelete<=0) return;
// else shift data
firstRowToDelete = rangeCol.first();
}
// if pos+n is after the data
if (firstRowToDelete+nRowsToDelete-1>rangeCol.last())
{
// remove the not existing data !
nRowsToDelete = rangeCol.last()-firstRowToDelete+1;
}
// update range
this->rangeCols_[col].decLast(nRowsToDelete);
rangeCol.decLast(nRowsToDelete);
// get range of the data to delete
const Integer last = rangeCol.last();
// translate remaining Rows
for ( Integer k=firstRowToDelete; k<=last; k++)
{ p_col[k] = p_col[k+nRowsToDelete];}
// free mem if necessary
if (this->rangeCols_[col].size()==0) freeCol(col);
}
| void STK::IArray2D< TYPE, TArray2D >::popBackRowsToCol | ( | Integer const & | col, |
| Integer const & | n = 1 |
||
| ) | [inline, protected] |
Internal method for deleting last rows to a specified column.
Delete n last Rows to the container. TODO save memory if capacity is really too large ?
| col | index of the Col |
| n | number of elements to delete (default 1) |
Definition at line 1016 of file STK_IArray2D.h.
Referenced by STK::IArray2D< Integer, Array2D< Integer > >::resizeCol().
{
#ifdef STK_BOUNDS_CHECK
// check bounds
if (this->firstCol() > col)
{ throw std::out_of_range("IArray2D::popBackRowsToCol(col, n) "
"this->firstCol() > col");
}
if (this->lastCol() < col)
{ throw std::out_of_range("IArray2D::popBackRowsToCol(col, n) "
"this->lastCol() < col");
}
#endif
// check if there is something to do
if (n <= 0) return;
// check argument error
if (n > this->rangeCol(col).size())
{
throw std::runtime_error("IArray2D::popBackRowsToCol(col, n) "
"n > rangeCol(col).size().");
}
// update range
this->rangeCols_[col].decLast(n);
// free mem if necessary
if (this->rangeCols_[col].size()==0)
freeCol(col);
}