|
STK++ 1.0
|
Templated Interface base class for all Arrays classes. More...
#include <STK_IArrayBase.h>

Public Member Functions | |
| virtual | ~IArrayBase () |
| Virtual destructor. | |
| Integer const & | firstData () const |
| Get the first index of the data. | |
| Integer const & | lastData () const |
| Get the last index of the data. | |
| Integer const & | sizeData () const |
| Get the size of the data. | |
| Range const & | rangeData () const |
| Get the range of the data. | |
| DATA const *const | ptrData () const |
| Get the main ptr on the data. | |
| DATA const & | data (Integer const &pos) const |
| Get the const element number pos. | |
Static Public Member Functions | |
| static Integer | evalCapacity (Integer const &m) |
| Return n+m, where n is the first number such that m < 2^n. | |
Protected Member Functions | |
| IArrayBase (Range const &I=Range()) | |
| Default constructor. | |
| IArrayBase (const IArrayBase &T, bool ref=false) | |
| Copy constructor. | |
| IArrayBase (DATA *q, Range const &I) | |
| Wrapper constructor. | |
| DATA * | ptrData () |
| Get the main ptr on the data. | |
| DATA & | data (Integer const &pos) |
| Get the element number pos. | |
| void | setData (Integer const &pos, DATA const &data=DATA()) |
| Set the element number pos : this method is not destined to the end-user. | |
| void | swap (IArrayBase &T) |
| swap this with T. | |
| void | shiftPtrData (Integer const &first) |
| shift the first index of the data to first. | |
| void | mallocPtrData (Integer const &size, Integer const &inc=0) |
| protected function for main ptr memory allocation. | |
| void | reallocPtrData (Integer const &size, Integer const &inc=0) |
| protected function for main ptr memory reallocation. | |
| void | freePtrData () |
| protected function for main ptr memory deallocation. | |
| void | setPtrData (DATA *p_data=0) |
| Set the address of the data : this method is not destined to the end-user. | |
| void | setRangeData (Range const &rangeData=Range()) |
| Set the index of the first data : this method is not destined to the end-user. | |
Private Member Functions | |
| void | incPtrData (Integer const &inc) |
| Increment the address of the data : this method is not destined to the end-user. | |
| void | decPtrData (Integer const &dec) |
| Decrement the address of the data : this method is not destined to the end-user. | |
| void | setDefault () |
| Set array members to default values. | |
Private Attributes | |
| DATA * | p_data_ |
| Main pointer on the data. | |
| Range | rangeData_ |
| Range of the data. | |
Templated Interface base class for all Arrays classes.
The IArrayBase class is the interface base class of all arrays stored in memory : it manages the main pointer on the data. It derive from the IContainerRef class as an array stored in memory can always be wrapped in some way or be a wrapper of data stored in memory.
The class DATA can be any type of data that can be stored in memory.
Definition at line 58 of file STK_IArrayBase.h.
| STK::IArrayBase< DATA >::IArrayBase | ( | Range const & | I = Range() | ) | [inline, protected] |
Default constructor.
| I | range of the data |
Definition at line 64 of file STK_IArrayBase.h.
: IContainerRef(false) , p_data_(0) , rangeData_(I) { mallocPtrData( I.size(), I.first());}
| STK::IArrayBase< DATA >::IArrayBase | ( | const IArrayBase< DATA > & | T, |
| bool | ref = false |
||
| ) | [inline, protected] |
Copy constructor.
| T | : the array to copy |
| ref | : is this a wrapper of T ? |
Definition at line 73 of file STK_IArrayBase.h.
: IContainerRef(ref) { if (ref) // set T data { p_data_ = T.p_data_; rangeData_ = T.rangeData_; } else // Allocate memory in base class { setDefault(); } }
| STK::IArrayBase< DATA >::IArrayBase | ( | DATA * | q, |
| Range const & | I | ||
| ) | [inline, protected] |
Wrapper constructor.
| q | ptr to the data to wrap |
| I | range of the data wrapped |
Definition at line 91 of file STK_IArrayBase.h.
: IContainerRef(true) , p_data_(q) , rangeData_(I) { ;}
| virtual STK::IArrayBase< DATA >::~IArrayBase | ( | ) | [inline, virtual] |
Virtual destructor.
Definition at line 98 of file STK_IArrayBase.h.
{ if (!this->isRef()) this->freePtrData(); }
| Integer const& STK::IArrayBase< DATA >::firstData | ( | ) | const [inline] |
Get the first index of the data.
Definition at line 104 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::data(), STK::IArrayBase< TYPE * >::freePtrData(), STK::IArrayBase< TYPE * >::reallocPtrData(), STK::IArrayBase< TYPE * >::setData(), and STK::IArrayBase< TYPE * >::shiftPtrData().
{ return rangeData_.first();}
| Integer const& STK::IArrayBase< DATA >::lastData | ( | ) | const [inline] |
Get the last index of the data.
Definition at line 108 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::data(), and STK::IArrayBase< TYPE * >::setData().
{ return rangeData_.last();}
| Integer const& STK::IArrayBase< DATA >::sizeData | ( | ) | const [inline] |
Get the size of the data.
Definition at line 112 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::reallocPtrData().
{ return rangeData_.size();}
| Range const& STK::IArrayBase< DATA >::rangeData | ( | ) | const [inline] |
Get the range of the data.
Definition at line 116 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::setRangeData().
{ return rangeData_;}
| DATA const* const STK::IArrayBase< DATA >::ptrData | ( | ) | const [inline] |
Get the main ptr on the data.
a pointer on the data set
Definition at line 120 of file STK_IArrayBase.h.
{ return p_data_;}
| DATA const& STK::IArrayBase< DATA >::data | ( | Integer const & | pos | ) | const [inline] |
Get the const element number pos.
| pos | the position of the element we get |
Definition at line 125 of file STK_IArrayBase.h.
Referenced by STK::Array1D< Real >::Array1D(), STK::Array2D< Real >::Array2D(), STK::Array2D< Integer >::Array2D(), STK::ArrayHo< Real >::ArrayHo(), STK::ArrayHo< TYPE >::ArrayHo(), STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::copyColumn(), STK::RecursiveArray1D< Integer, Array1D< Integer > >::insertElt(), STK::MatrixLowerTriangular::MatrixLowerTriangular(), STK::MatrixUpperTriangular::MatrixUpperTriangular(), STK::IArray1DBase< Range, Range, Array1D< Range > >::moveElt(), STK::Array1D< Real >::operator=(), STK::Variable< String >::operator=(), STK::RecursiveArray2D< TYPE, Container2D >::operator=(), STK::MatrixUpperTriangular::operator=(), STK::MatrixLowerTriangular::operator=(), STK::Array2D< Real >::operator=(), STK::Array2D< Integer >::operator=(), STK::RecursiveArray1D< Integer, Array1D< Integer > >::RecursiveArray1D(), STK::RecursiveArray2D< TYPE, Container2D >::RecursiveArray2D(), STK::IArrayBase< TYPE * >::setData(), and STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::transferColumn().
| static Integer STK::IArrayBase< DATA >::evalCapacity | ( | Integer const & | m | ) | [inline, static] |
Return n+m, where n is the first number such that m < 2^n.
if m <=0 return 0
| m | the size of the container |
Definition at line 144 of file STK_IArrayBase.h.
| DATA* STK::IArrayBase< DATA >::ptrData | ( | ) | [inline, protected] |
| DATA& STK::IArrayBase< DATA >::data | ( | Integer const & | pos | ) | [inline, protected] |
Get the element number pos.
| pos | the position of the element we get |
Definition at line 160 of file STK_IArrayBase.h.
| void STK::IArrayBase< DATA >::setData | ( | Integer const & | pos, |
| DATA const & | data = DATA() |
||
| ) | [inline, protected] |
Set the element number pos : this method is not destined to the end-user.
No check about the given address is performed in this interface class.
| pos | the position of the element we set |
| data | the value we set |
Definition at line 181 of file STK_IArrayBase.h.
Referenced by STK::IArray1DBase< Range, Range, Array1D< Range > >::moveElt().
| void STK::IArrayBase< DATA >::swap | ( | IArrayBase< DATA > & | T | ) | [inline, protected] |
swap this with T.
| T | the container to swap |
Definition at line 199 of file STK_IArrayBase.h.
{
// copy main ptr data and range of this
DATA* auxMainPtr(p_data_);
Range auxRange(rangeData_);
bool auxRef(this->isRef());
// overwrite main ptr data of this
this->setPtrData(T.p_data_);
this->setRangeData(T.rangeData_);
this->setRef(T.isRef());
// overwrite main PTRCOL of T
T.setPtrData(auxMainPtr);
T.setRangeData(auxRange);
T.setRef(auxRef);
}
| void STK::IArrayBase< DATA >::shiftPtrData | ( | Integer const & | first | ) | [inline, protected] |
shift the first index of the data to first.
| first | the index of the first data to set |
Definition at line 220 of file STK_IArrayBase.h.
{
// check if there is something to do
if (first == firstData()) return;
// check for reference
if (this->isRef())
{ throw std::runtime_error("In IArrayBase::shiftPtrData(first)"
" can't operate on reference.");
}
// compute increment
Integer inc = first - firstData();
// translate data
decPtrData(inc);
}
| void STK::IArrayBase< DATA >::mallocPtrData | ( | Integer const & | size, |
| Integer const & | inc = 0 |
||
| ) | [inline, protected] |
protected function for main ptr memory allocation.
| size | the size to reserve in memory |
| inc | the increment to apply to p_data_ after allocation |
Definition at line 238 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::IArrayBase(), and STK::IArrayBase< TYPE * >::reallocPtrData().
{
// check for reference
if (this->isRef())
{ throw std::runtime_error("In IArrayBase::mallocPtrData(first)"
" can't operate on reference.");
}
// delete any memory allocated
freePtrData();
// check size
if (size <= 0)
{
// set initial values
setRangeData(Range(0,size-1));
// first index is 0
return;
}
// allocate memory
try
{
setPtrData(new DATA[size]);
}
catch (std::bad_alloc & error) // if an alloc error occur
{
// initialize to default
setDefault();
// and throw an exception
throw std::runtime_error("IArrayBase::mallocPtrData(size, inc) "
"memory allocation failed.");
}
// set initial values
setRangeData(Range(0,size-1)); // first index is 0
// apply increment
decPtrData(inc);
}
| void STK::IArrayBase< DATA >::reallocPtrData | ( | Integer const & | size, |
| Integer const & | inc = 0 |
||
| ) | [inline, protected] |
protected function for main ptr memory reallocation.
If the size requested is greater than the allocated size, the DATA stored are saved and copied using the operator=. the DATA class have to provide this operator.
If the size requested is lesser than the allocated size, only the first elements fitting in the container are copied.
| size | the size to reserve in memory |
| inc | the increment to apply to p_data_ after allocation |
Definition at line 286 of file STK_IArrayBase.h.
{
// check for reference
if (this->isRef())
{ throw std::runtime_error("In IArrayBase::reallocPtrData(first)"
" can't operate on reference.");
}
// if there is no memory allocated, we use mallocPtrData
if (!p_data_)
{
mallocPtrData(size, inc);
return;
}
// if the new size is empty we can safely remove existing data
if (size <= 0)
{
freePtrData();
return;
}
// reset to zero increment and get data adress
incPtrData(firstData());
DATA* p_data = p_data_;
// allocate memory
try
{
setPtrData(new DATA[size]);
}
catch (std::bad_alloc & error) // if an alloc error occur
{
// delete existing data
delete [] p_data;
// initialize members to default
setDefault();
// and throw an exception
throw std::runtime_error("IArrayBase::reallocPtrData(size, inc) "
"memory allocation failed.");
}
// copy existing data
Integer nbData = min(size, sizeData());
for (Integer i=0; i< nbData; i++)
{ p_data_[i] = p_data[i];}
// delete previous allocated data
// delete existing data
delete [] p_data;
// set initial values
setRangeData(Range(0,size-1)); // first index is 0
// apply increment
decPtrData(inc);
}
| void STK::IArrayBase< DATA >::freePtrData | ( | ) | [inline, protected] |
protected function for main ptr memory deallocation.
Definition at line 337 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::mallocPtrData(), STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::pushBackByTransfer(), STK::IArrayBase< TYPE * >::reallocPtrData(), and STK::IArrayBase< TYPE * >::~IArrayBase().
{
// nothing to do for ref
if (this->isRef()) return;
// if there is elts
if (p_data_)
{
incPtrData(firstData()); // translate
delete [] p_data_; // erase
setPtrData(); // set default values
}
}
| void STK::IArrayBase< DATA >::setPtrData | ( | DATA * | p_data = 0 | ) | [inline, protected] |
Set the address of the data : this method is not destined to the end-user.
| p_data | the address to set |
Definition at line 354 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::freePtrData(), STK::IArrayBase< TYPE * >::mallocPtrData(), STK::IArray2DBase< TYPE, TYPE *, ArrayHo< TYPE >, Array1D< TYPE >, Container2D >::pushBackByTransfer(), STK::IArrayBase< TYPE * >::reallocPtrData(), STK::IArrayBase< TYPE * >::setDefault(), and STK::IArrayBase< TYPE * >::swap().
{ p_data_ = p_data;}
| void STK::IArrayBase< DATA >::setRangeData | ( | Range const & | rangeData = Range() | ) | [inline, protected] |
Set the index of the first data : this method is not destined to the end-user.
| rangeData | the range of the data to set |
Definition at line 361 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::mallocPtrData(), STK::IArrayBase< TYPE * >::reallocPtrData(), STK::IArrayBase< TYPE * >::setDefault(), and STK::IArrayBase< TYPE * >::swap().
{ rangeData_ = rangeData;}
| void STK::IArrayBase< DATA >::incPtrData | ( | Integer const & | inc | ) | [inline, private] |
Increment the address of the data : this method is not destined to the end-user.
| inc | the increment to apply |
Definition at line 369 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::freePtrData(), and STK::IArrayBase< TYPE * >::reallocPtrData().
{
// translate p_data_ only if there exists data
if (this->p_data_) { p_data_ += inc;}
rangeData_.dec(inc);
}
| void STK::IArrayBase< DATA >::decPtrData | ( | Integer const & | dec | ) | [inline, private] |
Decrement the address of the data : this method is not destined to the end-user.
| dec | the increment to apply |
Definition at line 380 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::mallocPtrData(), STK::IArrayBase< TYPE * >::reallocPtrData(), and STK::IArrayBase< TYPE * >::shiftPtrData().
{
// translate p_data_ only if there exists data
if (this->p_data_) { p_data_ -= dec;}
rangeData_.inc(dec);
}
| void STK::IArrayBase< DATA >::setDefault | ( | ) | [inline, private] |
Set array members to default values.
Definition at line 388 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::IArrayBase(), STK::IArrayBase< TYPE * >::mallocPtrData(), and STK::IArrayBase< TYPE * >::reallocPtrData().
{
setPtrData();
setRangeData();
}
DATA* STK::IArrayBase< DATA >::p_data_ [private] |
Main pointer on the data.
Definition at line 396 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::data(), STK::IArrayBase< TYPE * >::decPtrData(), STK::IArrayBase< TYPE * >::freePtrData(), STK::IArrayBase< TYPE * >::IArrayBase(), STK::IArrayBase< TYPE * >::incPtrData(), STK::IArrayBase< TYPE * >::ptrData(), STK::IArrayBase< TYPE * >::reallocPtrData(), STK::IArrayBase< TYPE * >::setData(), STK::IArrayBase< TYPE * >::setPtrData(), and STK::IArrayBase< TYPE * >::swap().
Range STK::IArrayBase< DATA >::rangeData_ [private] |
Range of the data.
Definition at line 398 of file STK_IArrayBase.h.
Referenced by STK::IArrayBase< TYPE * >::decPtrData(), STK::IArrayBase< TYPE * >::firstData(), STK::IArrayBase< TYPE * >::IArrayBase(), STK::IArrayBase< TYPE * >::incPtrData(), STK::IArrayBase< TYPE * >::lastData(), STK::IArrayBase< TYPE * >::rangeData(), STK::IArrayBase< TYPE * >::setRangeData(), STK::IArrayBase< TYPE * >::sizeData(), and STK::IArrayBase< TYPE * >::swap().