STK++ 1.0

STK::IArray1DBase< TYPE, PTRELT, TArray1D > Class Template Reference

Templated Interface base class for uni-dimensional arrays. More...

#include <STK_IArray1DBase.h>

Inheritance diagram for STK::IArray1DBase< TYPE, PTRELT, TArray1D >:

List of all members.

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).

Detailed Description

template<class TYPE, class PTRELT, class TArray1D>
class STK::IArray1DBase< TYPE, PTRELT, TArray1D >

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.


Member Typedef Documentation

template<class TYPE, class PTRELT, class TArray1D>
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.


Constructor & Destructor Documentation

template<class TYPE, class PTRELT, class TArray1D>
STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase ( Range const &  I = Range()) [inline, protected]

Default constructor : beg_ =1 and end_ =0.

Parameters:
Irange of the container

Definition at line 95 of file STK_IArray1DBase.h.

template<class TYPE, class PTRELT, class TArray1D>
STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase ( const IArray1DBase< TYPE, PTRELT, TArray1D > &  T,
bool  ref = false 
) [inline, protected]

Copy constructor.

Parameters:
Tthe container to copy
reftrue 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());
    }
template<class TYPE, class PTRELT, class TArray1D>
STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase ( const IArray1DBase< TYPE, PTRELT, TArray1D > &  T,
Range const &  I 
) [inline, protected]

constructor by reference, ref_=1.

Parameters:
Tthe container to copy
Irange 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
    }
template<class TYPE, class PTRELT, class TArray1D>
STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase ( const _IArrayBaseType T,
Range const &  I,
Integer const &  index 
) [inline, protected]

constructor by reference, ref_=1.

Parameters:
Tthe container to copy
Irange of the data to wrap
indexindex (row or col) of the container

Definition at line 143 of file STK_IArray1DBase.h.

                : _ITContainer1DType(I)
                , _IArrayBaseType(T, true)
                , capacity_(0)
                , index_(index)
    { ;}
template<class TYPE, class PTRELT, class TArray1D>
STK::IArray1DBase< TYPE, PTRELT, TArray1D >::IArray1DBase ( PTRELT *  q,
Range const &  I,
Integer const &  index = 0 
) [inline, protected]

Wrapper constructor.

Parameters:
qpointer on data
Irange of the data
indexindex (row or col) of the data

Definition at line 158 of file STK_IArray1DBase.h.

           : _ITContainer1DType(I)
           , _IArrayBaseType(q, I)
           , capacity_(0)
           , index_(index)
    { ;}
template<class TYPE, class PTRELT, class TArray1D>
virtual STK::IArray1DBase< TYPE, PTRELT, TArray1D >::~IArray1DBase ( ) [inline, virtual]

Virtual destructor.

Definition at line 167 of file STK_IArray1DBase.h.

{ ;}

Member Function Documentation

template<class TYPE, class PTRELT, class TArray1D>
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_;}
template<class TYPE, class PTRELT, class TArray1D>
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_;}
template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::reserve ( Integer const &  size) [inline]

reserve internal memory for at least size elements.

Parameters:
sizenumber 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());
      }
    }
template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::swap ( IArray1DBase< TYPE, PTRELT, TArray1D > &  T) [inline]

swap this Container with T.

Parameters:
Tthe 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().

    {
      // swap IArrayBase part
      this->IArrayBase<PTRELT>::swap(T);
 
      // swap IArray1DBase part
      STK::swap(capacity_, T.capacity_);
      STK::swap(index_, T.index_);

      // swap ITContainer1D part
      Range auxRange(this->range());
      this->setRange(T.range());
      T.setRange(auxRange);
    }
template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::shift ( Integer const &  beg = 1) [inline, virtual]

New beginning index for the object.

Parameters:
begthe 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);
      }
    }
template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::swap ( Integer const &  pos1,
Integer const &  pos2 
) [inline]

Swapping the pos1 elt and the pos2 elt.

Parameters:
pos1position of the first elt
pos2position 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);
    }
template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::setCapacity ( Integer const &  capacity = 0) [inline, protected]

Set the maximum possible number of elements without reallocation.

Parameters:
capacitycapacity 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().

template<class TYPE, class PTRELT, class TArray1D>
void STK::IArray1DBase< TYPE, PTRELT, TArray1D >::setIndex ( Integer const &  index = 0) [inline, protected]

Set the index (row or col) of the container.

Parameters:
indexindex of the container

Definition at line 294 of file STK_IArray1DBase.h.

    { index_ = index;}
template<class TYPE, class PTRELT, class TArray1D>
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.

Parameters:
Irange 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);
    }
template<class TYPE, class PTRELT, class TArray1D>
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));
    }
template<class TYPE, class PTRELT, class TArray1D>
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.

Parameters:
pos1the column to initialize
Tthe container with the column to move
pos2the column in the container T to move in this

Definition at line 347 of file STK_IArray1DBase.h.

    {
      // copy column pos2 of T in pos1 of this
      this->setData(pos1, T.data(pos2));
      // set column of T to default
      T.setData(pos2);
    }

Member Data Documentation

template<class TYPE, class PTRELT, class TArray1D>
Integer STK::IArray1DBase< TYPE, PTRELT, TArray1D >::capacity_ [private]
template<class TYPE, class PTRELT, class TArray1D>
Integer STK::IArray1DBase< TYPE, PTRELT, TArray1D >::index_ [private]

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