|
STK++ 1.0
|
Templated Interface base class for uni-dimensional arrays. More...
#include <STK_IArray1DBase.h>

Public Types | |
| typedef IArrayBase< PTRELT > | _IArrayBaseType |
| Type for the Interface Array Class. | |
| typedef ITContainer1D< TYPE, TArray1D > | _ITContainer1DType |
| Type for the Interface Array Class. | |
Public Member Functions | |
| virtual | ~IArray1DBase () |
| Virtual destructor. | |
| Integer const & | capacity () const |
| return the maximum possible number of elements without reallocation. | |
| Integer const & | getIndex () const |
| Get the index of the oriented container. | |
| void | reserve (Integer const &size) |
| reserve internal memory for at least size elements. | |
| void | swap (IArray1DBase &T) |
| swap this Container with T. | |
| void | shift (Integer const &beg=1) |
| New beginning index for the object. | |
| void | swap (Integer const &pos1, Integer const &pos2) |
| Swapping the pos1 elt and the pos2 elt. | |
Protected Member Functions | |
| IArray1DBase (Range const &I=Range()) | |
| Default constructor : beg_ =1 and end_ =0. | |
| IArray1DBase (const IArray1DBase &T, bool ref=false) | |
| Copy constructor. | |
| IArray1DBase (const IArray1DBase &T, Range const &I) | |
| constructor by reference, ref_=1. | |
| IArray1DBase (const _IArrayBaseType &T, Range const &I, Integer const &index) | |
| constructor by reference, ref_=1. | |
| IArray1DBase (PTRELT *q, Range const &I, Integer const &index=0) | |
| Wrapper constructor. | |
| void | setCapacity (Integer const &capacity=0) |
| Set the maximum possible number of elements without reallocation. | |
| void | setIndex (Integer const &index=0) |
| Set the index (row or col) of the container. | |
| void | init1D (Range const &I) |
| function for memory allocation and initialization. | |
| void | free1D () |
| Method for memory deallocation. | |
| void | moveElt (Integer const &pos1, IArray1DBase &T, Integer const &pos2) |
| Move the column pos2 from the container T to the column pos1 of this. | |
Private Attributes | |
| Integer | capacity_ |
| true size of the array. | |
| Integer | index_ |
| row or column of the container (if any). | |
Templated Interface base class for uni-dimensional arrays.
AIArray1DBase is an abstract non-oriented uni-dimensional container. It inherits of all pseudo virtual methods defined in ITContainer1D and IContainer1D Interfaces.
Description of the template parameters :
TYPE is the type of the data stored in the container.PTRELT allow to use indirection when accessing to the data.TArray1D is the type of the class which derives from IArray1DBase. For exemple : template<class TYPE> class TArray1D : public IArray1DBase<TYPE, PTRELT, TArray1D<TYPE> > {...} Definition at line 74 of file STK_IArray1DBase.h.
| typedef IArrayBase<PTRELT> STK::IArray1DBase< TYPE, PTRELT, TArray1D >::_IArrayBaseType |
Type for the Interface Array Class.
Reimplemented in STK::ArrayHo< Real >, STK::Array1D< Real >, STK::Variable< TYPE >, STK::Array1D< TYPE >, STK::ArrayHo< TYPE >, STK::RecursiveArray1D< TYPE, Container1D >, STK::Variable< String >, STK::Array1D< std::string >, STK::Array1D< Range >, STK::Array1D< Integer >, STK::Array1D< Variable< String > >, STK::RecursiveArray1D< Variable< String >, Array1D< Variable< String > > >, STK::RecursiveArray1D< Real, Array1D< Real > >, STK::RecursiveArray1D< TYPE, Variable< TYPE > >, STK::RecursiveArray1D< TYPE, Array1D< TYPE > >, STK::RecursiveArray1D< Range, Array1D< Range > >, STK::RecursiveArray1D< std::string, Array1D< std::string > >, STK::RecursiveArray1D< String, Variable< String > >, and STK::RecursiveArray1D< Integer, Array1D< Integer > >.
Definition at line 86 of file STK_IArray1DBase.h.
| typedef ITContainer1D<TYPE, TArray1D> STK::IArray1DBase< TYPE, PTRELT, TArray1D >::_ITContainer1DType |
Type for the Interface Array Class.
Definition at line 89 of file STK_IArray1DBase.h.
| STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase | ( | Range const & | I = Range() | ) | [inline, protected] |
Default constructor : beg_ =1 and end_ =0.
| I | range of the container |
Definition at line 95 of file STK_IArray1DBase.h.
: _ITContainer1DType(I) , _IArrayBaseType() , capacity_(0) , index_(0) { init1D(I);}
| STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase | ( | const IArray1DBase< TYPE, PTRELT, TArray1D > & | T, |
| bool | ref = false |
||
| ) | [inline, protected] |
Copy constructor.
| T | the container to copy |
| ref | true if T is wrapped |
Definition at line 106 of file STK_IArray1DBase.h.
: _ITContainer1DType(T) , _IArrayBaseType(T, ref) , capacity_(0) , index_(T.index_) { if (!ref) init1D(T.range()); }
| STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase | ( | const IArray1DBase< TYPE, PTRELT, TArray1D > & | T, |
| Range const & | I | ||
| ) | [inline, protected] |
constructor by reference, ref_=1.
| T | the container to copy |
| I | range of the data to wrap |
Definition at line 120 of file STK_IArray1DBase.h.
: _ITContainer1DType(I) , _IArrayBaseType(T, true) , capacity_(0) , index_(T.index_) { #ifdef STK_BOUNDS_CHECK if (I.first() < T.first()) { throw std::out_of_range("IArray1DBase::IArray1DBase(T, I) " "I.first() < T.first()"); } if (I.last() > T.last()) { throw std::out_of_range("IArray1DBase::IArray1DBase(T, I) " "I.last() > T.last()"); } #endif }
| STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase | ( | const _IArrayBaseType & | T, |
| Range const & | I, | ||
| Integer const & | index | ||
| ) | [inline, protected] |
constructor by reference, ref_=1.
| T | the container to copy |
| I | range of the data to wrap |
| index | index (row or col) of the container |
Definition at line 143 of file STK_IArray1DBase.h.
: _ITContainer1DType(I) , _IArrayBaseType(T, true) , capacity_(0) , index_(index) { ;}
| STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase | ( | PTRELT * | q, |
| Range const & | I, | ||
| Integer const & | index = 0 |
||
| ) | [inline, protected] |
Wrapper constructor.
| q | pointer on data |
| I | range of the data |
| index | index (row or col) of the data |
Definition at line 158 of file STK_IArray1DBase.h.
: _ITContainer1DType(I) , _IArrayBaseType(q, I) , capacity_(0) , index_(index) { ;}
| virtual STK::IArray1DBase< TYPE, PTRELT, TArray1D >::~IArray1DBase | ( | ) | [inline, virtual] |
| Integer const& STK::IArray1DBase< TYPE, PTRELT, TArray1D >::capacity | ( | ) | const [inline] |
return the maximum possible number of elements without reallocation.
Definition at line 171 of file STK_IArray1DBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::reserve(), and STK::IArray1DBase< Range, Range, Array1D< Range > >::setCapacity().
{ return capacity_;}
| Integer const& STK::IArray1DBase< TYPE, PTRELT, TArray1D >::getIndex | ( | ) | const [inline] |
Get the index of the oriented container.
Definition at line 174 of file STK_IArray1DBase.h.
Referenced by STK::ArrayHo< Real >::ArrayHo(), and STK::ArrayHo< TYPE >::ArrayHo().
{ return index_;}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::reserve | ( | Integer const & | size | ) | [inline] |
reserve internal memory for at least size elements.
| size | number of elements to reserve |
Definition at line 179 of file STK_IArray1DBase.h.
Referenced by STK::Funct::betaRatio_se(), and STK::ReadWriteCsv::push_back().
{
// nothing to do
if (size < this->capacity()) return;
// is this structure a ptr ?
if (this->isRef())
{ throw std::runtime_error("Array1D::reserve(size) "
"can't operate on references.");
}
// reserve
TArray1D Taux; // auxiliary empty container
this->swap(Taux); // save old elts in Taux
try
{
this->mallocPtrData(size, Taux.first());
}
catch (std::runtime_error & error) // if an alloc error occur
{
// go back
this->swap(Taux);
// and send the exception
throw error;
}
// if no alloc error
this->setCapacity(size); // update size
this->setRange(Taux.range()); // set range
// copy elts
for (Integer j=this->first(); j<=this->last(); j++)
{
this->setData(j, Taux.data(j));
Taux.setData(j, PTRELT());
}
}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::swap | ( | IArray1DBase< TYPE, PTRELT, TArray1D > & | T | ) | [inline] |
swap this Container with T.
| T | the Array to swap with T |
Definition at line 216 of file STK_IArray1DBase.h.
Referenced by STK::EigenvaluesSymmetric::diagonalize(), STK::IArray1DBase< Range, Range, Array1D< Range > >::reserve(), STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::swap(), and STK::IArray1DBase< Range, Range, Array1D< Range > >::swap().
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::shift | ( | Integer const & | beg = 1 | ) | [inline, virtual] |
New beginning index for the object.
| beg | the index of the first column to set |
Implements STK::IContainer1D.
Definition at line 234 of file STK_IArray1DBase.h.
Referenced by STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::shiftHo().
{
// compute increment
Integer inc = beg - this->first();
// if there is something to do
if (inc != 0)
{
// is this structure just a pointer?
if (this->isRef())
{ throw std::runtime_error("IArray1DBase::shift(beg) "
"can't operate on references.");
}
// translate rangeHo_
this->incRange(inc);
// translate data
this->shiftPtrData(beg);
}
}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::swap | ( | Integer const & | pos1, |
| Integer const & | pos2 | ||
| ) | [inline] |
Swapping the pos1 elt and the pos2 elt.
| pos1 | position of the first elt |
| pos2 | position of the second elt |
Reimplemented from STK::ITContainer1D< TYPE, TArray1D >.
Definition at line 257 of file STK_IArray1DBase.h.
{
#ifdef STK_BOUNDS_CHECK
if (this->first() > pos1)
{ throw std::out_of_range("IArray1DBase::swap(pos1, pos2) "
"this->first() >pos1");
}
if (this->last() < pos1)
{ throw std::out_of_range("IArray1DBase::swap(pos1, pos2) "
"this->last() <pos1");
}
if (this->first() > pos2)
{ throw std::out_of_range("IArray1DBase::swap(pos1, pos2) "
"this->first() >pos2");
}
if (this->last() < pos2)
{ throw std::out_of_range("IArray1DBase::swap(pos1, pos2) "
"this->last() <pos2");
}
#endif
// swap
PTRELT qaux(this->data(pos1));
this->setData(pos1, this->data(pos2));
this->setData(pos2, qaux);
}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::setCapacity | ( | Integer const & | capacity = 0 | ) | [inline, protected] |
Set the maximum possible number of elements without reallocation.
| capacity | capacity of the container |
Definition at line 288 of file STK_IArray1DBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::free1D(), STK::IArray1DBase< Range, Range, Array1D< Range > >::init1D(), and STK::IArray1DBase< Range, Range, Array1D< Range > >::reserve().
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::setIndex | ( | Integer const & | index = 0 | ) | [inline, protected] |
Set the index (row or col) of the container.
| index | index of the container |
Definition at line 294 of file STK_IArray1DBase.h.
{ index_ = index;}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::init1D | ( | Range const & | I | ) | [inline, protected] |
function for memory allocation and initialization.
The range is not set in this method. If an error occur, we set the range of the container to default.
| I | range of the container |
Definition at line 302 of file STK_IArray1DBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::IArray1DBase().
{
// compute the size necessary (can be 0)
Integer size = _IArrayBaseType::evalCapacity(I.size());
// try to allocate memory
try
{
// initialize Elts
this->mallocPtrData(size, I.first());
}
catch (std::runtime_error & error) // if an error occur
{
// set default capacity (0)
setCapacity();
// set default range
this->setRange();
// throw the error
throw error;
}
// set new capacity if no error occur
setCapacity(size);
}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::free1D | ( | ) | [inline, protected] |
Method for memory deallocation.
If the derived class use indirection, we have to free the mem if necessary prior to this method. The beginning of the Container is not modified
Definition at line 329 of file STK_IArray1DBase.h.
{
// Nothing to do for ref
if (this->isRef()) return;
// free allocated memory
this->freePtrData();
// set capacity to default
this->setCapacity();
// set range of the Cols to default
this->setRange(Range(this->first(), this->first()-1));
}
| void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::moveElt | ( | Integer const & | pos1, |
| IArray1DBase< TYPE, PTRELT, TArray1D > & | T, | ||
| Integer const & | pos2 | ||
| ) | [inline, protected] |
Move the column pos2 from the container T to the column pos1 of this.
set the column pos2 in T to default value.
| pos1 | the column to initialize |
| T | the container with the column to move |
| pos2 | the column in the container T to move in this |
Definition at line 347 of file STK_IArray1DBase.h.
Integer STK::IArray1DBase< TYPE, PTRELT, TArray1D >::capacity_ [private] |
true size of the array.
Definition at line 79 of file STK_IArray1DBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::capacity(), STK::IArray1DBase< Range, Range, Array1D< Range > >::setCapacity(), and STK::IArray1DBase< Range, Range, Array1D< Range > >::swap().
Integer STK::IArray1DBase< TYPE, PTRELT, TArray1D >::index_ [private] |
row or column of the container (if any).
Definition at line 82 of file STK_IArray1DBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::getIndex(), STK::IArray1DBase< Range, Range, Array1D< Range > >::setIndex(), and STK::IArray1DBase< Range, Range, Array1D< Range > >::swap().