STK++ 0.9.13
STK::IArray1D< Derived > Class Template Reference

template one dimensional Array. More...

#include <STK_IArray1D.h>

Inheritance diagram for STK::IArray1D< Derived >:
Inheritance graph

Public Types

enum  {
  structure_ = hidden::Traits< Derived >::structure_ , orient_ = hidden::Traits< Derived >::orient_ , sizeCols_ = hidden::Traits< Derived >::sizeCols_ , sizeRows_ = hidden::Traits< Derived >::sizeRows_ ,
  size_ = hidden::Traits< Derived >::size_ , storage_ = hidden::Traits< Derived >::storage_ , isFixedSize_ = (size_ != UnknownSize)
}
 
typedef ITContainer1D< Derived > Base
 
typedef hidden::Traits< Derived >::Allocator Allocator
 
typedef hidden::Traits< Derived >::Type Type
 
typedef hidden::Traits< Derived >::TypeConst TypeConst
 
typedef hidden::Traits< Derived >::RowRange RowRange
 
typedef hidden::Traits< Derived >::ColRange ColRange
 
typedef hidden::Traits< Derived >::Iterator Iterator
 
typedef hidden::Traits< Derived >::ConstIterator ConstIterator
 
typedef hidden::Traits< Derived >::ReverseIterator ReverseIterator
 
typedef hidden::Traits< Derived >::ConstReverseIterator ConstReverseIterator
 
- Public Types inherited from STK::ITContainer1D< Derived >
enum  { size_ = hidden::Traits<Derived>::size_ }
 
typedef hidden::Traits< Derived >::Type Type
 
typedef hidden::Traits< Derived >::TypeConst TypeConst
 
typedef hidden::Traits< Derived >::RowRange RowRange
 
typedef hidden::Traits< Derived >::ColRange ColRange
 
typedef hidden::Traits< Derived >::Row Row
 
typedef hidden::Traits< Derived >::Col Col
 
typedef hidden::Traits< Derived >::SubVector SubVector
 
typedef hidden::Traits< Derived >::Iterator Iterator
 
typedef hidden::Traits< Derived >::ConstIterator ConstIterator
 
typedef hidden::Traits< Derived >::ReverseIterator ReverseIterator
 
typedef hidden::Traits< Derived >::ConstReverseIterator ConstReverseIterator
 

Public Member Functions

bool isRef () const
 
void setRef (bool ref) const
 Modify the state of the container: this become a reference (if ref is true) or the owner of the data (if ref is false).
 
Allocator constallocator () const
 
RowRange constrows () const
 
int beginRows () const
 
int endRows () const
 
int sizeRows () const
 
ColRange cols () const
 
int beginCols () const
 
int endCols () const
 
int sizeCols () const
 
int lastIdxRows () const
 
int lastIdxCols () const
 
int capacity () const
 
Typeelt1Impl (int pos)
 access to an element
 
TypeConst elt1Impl (int pos) const
 access to a constant element
 
Derived & setValue (Type const &value)
 set a value to this container.
 
void setValue (int pos, TypeConst value)
 Write a value at a given position.
 
void shiftImpl (int beg=baseIdx)
 New beginning index for the object.
 
Derived & resizeImpl (Range const &I)
 Resize the container.
 
void reserve (int size)
 reserve internal memory for at least size elements.
 
void clear ()
 Clear the object.
 
void move (Derived const &T)
 move T to this.
 
Derived & pushBack (int n=1)
 Add n Elements to the end of the container.
 
Derived & popBack (int n=1)
 Delete last elts of the container.
 
Derived & erase (int pos, int n=1)
 Delete n elements at the pos index to the container.
 
Derived & insertElt (int pos, int n=1)
 Insert n elements at the position pos of the container.
 
Derived & insert (int pos, Type const &v)
 STL compatibility: Insert element v at position pos of the Array.
 
Derived & insert (Range const &I, Type const &v)
 STL compatibility: Insert element v in the range I of the Array.
 
Derived & push_front (Type const &v)
 STL compatibility: push front an element.
 
Derived & push_back (Type const &v)
 STL compatibility: append an element v.
 
void swap (int pos1, int pos2)
 Swapping the pos1 elt and the pos2 elt.
 
void exchange (IArray1D &T)
 exchange this Container with T.
 
Derived & assign (IArray1D const &src)
 overwrite this with src.
 
void memmove (int pos1, int pos2, int n)
 Copy n elements from pos2 to pos1, guaranteeing correct behavior for overlapping.
 
RowRange constrange () const
 
int begin () const
 
int end () const
 
int size () const
 
int lastIdx () const
 
void decLast (int n=1)
 decrement the end of the container.
 
void incLast (int n=1)
 increment the end of the container (can be negative).
 
void incRange (int n=1)
 increment the range of the container (can be negative).
 
void setRange (RowRange const &I=RowRange())
 Set range of the rows of the container.
 
Typeelt (int i)
 
TypeConst elt (int i) const
 
- Public Member Functions inherited from STK::ITContainer1D< Derived >
RowRange constrange () const
 
int begin () const
 
int end () const
 
int size () const
 
int lastIdx () const
 
Iterator beginIterator ()
 
Iterator endIterator ()
 
ConstIterator beginConstIterator () const
 
ConstIterator endConstIterator () const
 
ReverseIterator rbeginIterator ()
 
ReverseIterator rendIterator ()
 
ConstReverseIterator rbeginConstIterator () const
 
ConstReverseIterator rendConstIterator () const
 
bool empty () const
 Is there some data ?
 
Typeelt (int i)
 
TypeConst elt (int i) const
 
Typeoperator[] (int i)
 
TypeConst operator[] (int i) const
 
Typeat (int i)
 
TypeConst at (int i) const
 
SubVector sub (Range const &I) const
 Access to many elements.
 
Typefront ()
 
TypeConst front () const
 
Typeback ()
 
TypeConst back () const
 
void shift (int beg)
 
Derived & resize (Range const &I=RowRange())
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Protected Member Functions

 IArray1D ()
 Default constructor.
 
 IArray1D (Range const &I)
 constructor with a specified Range.
 
 IArray1D (Range const &I, Type const &v)
 Misc constructor with first and last, initialization with a constant.
 
 IArray1D (IArray1D const &T, bool ref)
 Copy constructor.
 
template<class OtherDerived >
 IArray1D (IArray1D< OtherDerived > const &T, bool ref)
 Copy constructor.
 
template<class OtherDerived >
 IArray1D (IArray1D< OtherDerived > const &T, RowRange const &I, bool ref)
 copy constructor.
 
 IArray1D (Allocator const &A, Range const &I, bool ref)
 Wrapper constructor.
 
 ~IArray1D ()
 destructor: allocated memory is liberated by MemAllocator class.
 
Allocatorallocator ()
 
void initialize (RowRange const &I)
 function for memory allocation and initialization.
 
void allocate (RowRange const &I)
 function for memory allocation.
 
void freeMem ()
 Method for memory deallocation.
 
- Protected Member Functions inherited from STK::ITContainer1D< Derived >
 ITContainer1D ()
 Default constructor.
 
 ITContainer1D (RowRange const &I)
 constructor with a specified range.
 
 ~ITContainer1D ()
 destructor.
 
void exchange (ITContainer1D &T)
 exchange this container with T
 
void setRange (RowRange const &I=RowRange())
 Set range of the rows of the container.
 
void incRange (int n=1)
 increment the range of the container (can be negative).
 
void incFirst (int n=1)
 increment the beginning of the container (can be negative).
 
void decFirst (int n=1)
 decrement the beginning of the container.
 
void incLast (int n=1)
 increment the end of the container (can be negative).
 
void decLast (int n=1)
 decrement the end of the container.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Private Attributes

Allocator allocator_
 

Detailed Description

template<class Derived>
class STK::IArray1D< Derived >

template one dimensional Array.

An IArray1D is a template one column container implementing the interface base class ITContainer1D.

Definition at line 94 of file STK_IArray1D.h.

Member Typedef Documentation

◆ Allocator

template<class Derived >
typedef hidden::Traits<Derived>::Allocator STK::IArray1D< Derived >::Allocator

Definition at line 99 of file STK_IArray1D.h.

◆ Base

template<class Derived >
typedef ITContainer1D< Derived > STK::IArray1D< Derived >::Base

Definition at line 98 of file STK_IArray1D.h.

◆ ColRange

template<class Derived >
typedef hidden::Traits<Derived>::ColRange STK::IArray1D< Derived >::ColRange

Definition at line 116 of file STK_IArray1D.h.

◆ ConstIterator

template<class Derived >
typedef hidden::Traits<Derived>::ConstIterator STK::IArray1D< Derived >::ConstIterator

Definition at line 119 of file STK_IArray1D.h.

◆ ConstReverseIterator

template<class Derived >
typedef hidden::Traits<Derived>::ConstReverseIterator STK::IArray1D< Derived >::ConstReverseIterator

Definition at line 121 of file STK_IArray1D.h.

◆ Iterator

template<class Derived >
typedef hidden::Traits<Derived>::Iterator STK::IArray1D< Derived >::Iterator

Definition at line 118 of file STK_IArray1D.h.

◆ ReverseIterator

template<class Derived >
typedef hidden::Traits<Derived>::ReverseIterator STK::IArray1D< Derived >::ReverseIterator

Definition at line 120 of file STK_IArray1D.h.

◆ RowRange

template<class Derived >
typedef hidden::Traits<Derived>::RowRange STK::IArray1D< Derived >::RowRange

Definition at line 115 of file STK_IArray1D.h.

◆ Type

template<class Derived >
typedef hidden::Traits<Derived>::Type STK::IArray1D< Derived >::Type

Definition at line 112 of file STK_IArray1D.h.

◆ TypeConst

template<class Derived >
typedef hidden::Traits<Derived>::TypeConst STK::IArray1D< Derived >::TypeConst

Definition at line 113 of file STK_IArray1D.h.

Member Enumeration Documentation

◆ anonymous enum

template<class Derived >
anonymous enum
Enumerator
structure_ 
orient_ 
sizeCols_ 
sizeRows_ 
size_ 
storage_ 
isFixedSize_ 

Definition at line 101 of file STK_IArray1D.h.

102 {
103 structure_ = hidden::Traits< Derived >::structure_,
104 orient_ = hidden::Traits< Derived >::orient_,
105 sizeCols_ = hidden::Traits< Derived >::sizeCols_,
106 sizeRows_ = hidden::Traits< Derived >::sizeRows_,
107 size_ = hidden::Traits< Derived >::size_,
108 storage_ = hidden::Traits< Derived >::storage_,
110 };
const int UnknownSize
This value means that an integer is not known at compile-time, and that instead the value is stored i...

Constructor & Destructor Documentation

◆ IArray1D() [1/7]

template<class Derived >
STK::IArray1D< Derived >::IArray1D ( )
protected

Default constructor.

Definition at line 339 of file STK_IArray1D.h.

Allocator allocator_
ITContainer1D< Derived > Base
RowRange const & range() const
TRange< Size_ > evalRangeCapacity(TRange< Size_ > const &I)

◆ IArray1D() [2/7]

template<class Derived >
STK::IArray1D< Derived >::IArray1D ( Range const I)
protected

constructor with a specified Range.

Parameters
Irange of the container

Definition at line 342 of file STK_IArray1D.h.

◆ IArray1D() [3/7]

template<class Derived >
STK::IArray1D< Derived >::IArray1D ( Range const I,
Type const v 
)
protected

Misc constructor with first and last, initialization with a constant.

Parameters
Irange of the container
vinitial value of the container

Definition at line 346 of file STK_IArray1D.h.

347 : Base(I)
349{ allocator_.assign(I,v);}

References STK::IArray1D< Derived >::allocator_.

◆ IArray1D() [4/7]

template<class Derived >
STK::IArray1D< Derived >::IArray1D ( IArray1D< Derived > const T,
bool  ref 
)
protected

Copy constructor.

Parameters
Tthe container to copy
reftrue if T is wrapped

Definition at line 356 of file STK_IArray1D.h.

357 : Base(T.range())
358 , allocator_(T.allocator(), ref)
359{}

◆ IArray1D() [5/7]

template<class Derived >
template<class OtherDerived >
STK::IArray1D< Derived >::IArray1D ( IArray1D< OtherDerived > const T,
bool  ref 
)
protected

Copy constructor.

Parameters
Tthe container to copy
reftrue if T is wrapped

Definition at line 366 of file STK_IArray1D.h.

367 : Base(T.range())
368 , allocator_(T.allocator(), ref)
369{}

◆ IArray1D() [6/7]

template<class Derived >
template<class OtherDerived >
STK::IArray1D< Derived >::IArray1D ( IArray1D< OtherDerived > const T,
RowRange const I,
bool  ref 
)
protected

copy constructor.

Parameters
T,Ithe container and the range of data to wrap
reftrue if T is wrapped (the default)

Definition at line 377 of file STK_IArray1D.h.

378 : Base(I)
379 , allocator_(T.allocator(), I, ref)
380{}

◆ IArray1D() [7/7]

template<class Derived >
STK::IArray1D< Derived >::IArray1D ( Allocator const A,
Range const I,
bool  ref 
)
protected

Wrapper constructor.

Parameters
A,Irange and allocator to wrap
reftrue if A is wrapped

Definition at line 387 of file STK_IArray1D.h.

388 : Base(I)
389 , allocator_(A, I, ref)
390{}

◆ ~IArray1D()

template<class Derived >
STK::IArray1D< Derived >::~IArray1D ( )
protected

destructor: allocated memory is liberated by MemAllocator class.

Definition at line 393 of file STK_IArray1D.h.

393{}

Member Function Documentation

◆ allocate()

template<class Derived >
void STK::IArray1D< Derived >::allocate ( RowRange const I)
protected

function for memory allocation.

The range is not set in this method. If a bad_alloc occur, we set the range of the container to default before throwing it.

Parameters
Irange of the container

Definition at line 655 of file STK_IArray1D.h.

656{
657 try
658 {
660 }
661 catch (Exception const& error)
662 {
663 setRange(); // if an error occur set default range
664 throw error;
665 }
666}
void setRange(RowRange const &I=RowRange())
Set range of the rows of the container.

References STK::IRunnerBase::error(), and STK::Arrays::evalRangeCapacity().

◆ allocator() [1/2]

template<class Derived >
Allocator & STK::IArray1D< Derived >::allocator ( )
inlineprotected
Returns
a reference on the allocator

Definition at line 316 of file STK_IArray1D.h.

316{ return allocator_;}

References STK::IArray1D< Derived >::allocator_.

◆ allocator() [2/2]

template<class Derived >
Allocator const & STK::IArray1D< Derived >::allocator ( ) const
inline
Returns
a constant reference on the allocator

Definition at line 184 of file STK_IArray1D.h.

184{ return allocator_;}

References STK::IArray1D< Derived >::allocator_.

◆ assign()

template<class Derived >
Derived & STK::IArray1D< Derived >::assign ( IArray1D< Derived > const src)

overwrite this with src.

Note
If the size match, this is not resized, and in this case, the method take care of the possibility of overlapping.
Parameters
srcthe container to assign

Definition at line 609 of file STK_IArray1D.h.

610{
611 // cannot assign same data
612 if (&allocator_ == &(src.allocator())) { return this->asDerived();}
613 // Resize if necessary.
614 if ( size() != src.size() ) { this->resize(src.range());}
615 allocator_.memcpy(begin(), src.allocator_, src.range());
616 return this->asDerived();
617}
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.
Derived & resize(Range const &I=RowRange())

◆ begin()

template<class Derived >
int STK::ITContainer1D< Derived >::begin ( ) const
inline
Returns
the index of the first element

Definition at line 113 of file STK_ITContainer1D.h.

113{ return range_.begin();}
RowRange range_
range of the array.

Referenced by STK::MemSAllocator< Type_, NzMax_, Size_ >::begin(), and STK::IArray1D< Derived >::beginRows().

◆ beginCols()

template<class Derived >
int STK::IArray1D< Derived >::beginCols ( ) const
inline
Returns
the index of the first column

Definition at line 198 of file STK_IArray1D.h.

198{ return baseIdx;}
const int baseIdx
base index of the containers created in STK++.

References STK::baseIdx.

◆ beginRows()

template<class Derived >
int STK::IArray1D< Derived >::beginRows ( ) const
inline
Returns
the index of the first element

Definition at line 189 of file STK_IArray1D.h.

189{ return begin();}

References STK::IArray1D< Derived >::begin().

◆ capacity()

template<class Derived >
int STK::IArray1D< Derived >::capacity ( ) const
inline
Returns
the maximum possible number of elements without reallocation

Definition at line 210 of file STK_IArray1D.h.

210{ return allocator_.size();}

References STK::IArray1D< Derived >::allocator_.

◆ clear()

template<class Derived >
void STK::IArray1D< Derived >::clear ( )

Clear the object.

Memory is liberated and the range of the Container is set to 0:-1 or 1:0 (

See also
baseIdx).

Definition at line 436 of file STK_IArray1D.h.

437{
438 if (isRef()) return; // Nothing to do for ref
439 freeMem(); // Free Mem
440}
bool isRef() const
void freeMem()
Method for memory deallocation.

◆ cols()

template<class Derived >
ColRange STK::IArray1D< Derived >::cols ( ) const
inline
Returns
the Horizontal range (1 column)

Definition at line 196 of file STK_IArray1D.h.

196{ return ColRange(1);}
hidden::Traits< Derived >::ColRange ColRange

◆ decLast()

template<class Derived >
void STK::ITContainer1D< Derived >::decLast ( int  n = 1)
inline

decrement the end of the container.

Parameters
ndecrement to apply to the end of the range

Definition at line 275 of file STK_ITContainer1D.h.

275{ range_.decLast(n);}

◆ elt() [1/2]

template<class Derived >
Type & STK::ITContainer1D< Derived >::elt ( int  i)
inline
Returns
the ith element for vector_, point_ and diagonal_ containers
Parameters
iindex of the element to get

Definition at line 150 of file STK_ITContainer1D.h.

151 {
152#ifdef STK_BOUNDS_CHECK
153 if (begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, begin() > i);}
154 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, end() <= i);}
155#endif
156 return this->asDerived().elt1Impl(i);
157 }
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93

◆ elt() [2/2]

template<class Derived >
TypeConst STK::ITContainer1D< Derived >::elt ( int  i) const
inline
Returns
a constant reference on the ith element for vector_, point_ and diagonal_ containers
Parameters
iindex of the element to get

Definition at line 161 of file STK_ITContainer1D.h.

162 {
163#ifdef STK_BOUNDS_CHECK
164 if (begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, begin() > i);}
165 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, end() <= i);}
166#endif
167 return this->asDerived().elt1Impl(i);
168 }

◆ elt1Impl() [1/2]

template<class Derived >
Type & STK::IArray1D< Derived >::elt1Impl ( int  pos)
inline

access to an element

Parameters
posindex of the element
Returns
a reference on the element to modify

Definition at line 216 of file STK_IArray1D.h.

216{ return allocator_.elt(pos);}

References STK::IArray1D< Derived >::allocator_.

◆ elt1Impl() [2/2]

template<class Derived >
TypeConst STK::IArray1D< Derived >::elt1Impl ( int  pos) const
inline

access to a constant element

Parameters
posindex of the const element
Returns
a constant reference on the element

Definition at line 221 of file STK_IArray1D.h.

221{ return allocator_.elt(pos);}

References STK::IArray1D< Derived >::allocator_.

◆ end()

template<class Derived >
int STK::ITContainer1D< Derived >::end ( ) const
inline
Returns
the ending index of the elements

Definition at line 115 of file STK_ITContainer1D.h.

115{ return range_.end();}

Referenced by STK::MemSAllocator< Type_, NzMax_, Size_ >::end(), STK::IArray1D< Array1D< Type_, Size_ > >::end(), and STK::IArray1D< Derived >::endRows().

◆ endCols()

template<class Derived >
int STK::IArray1D< Derived >::endCols ( ) const
inline
Returns
the index of the ending column

Definition at line 200 of file STK_IArray1D.h.

200{ return baseIdx+1;}

References STK::baseIdx.

◆ endRows()

template<class Derived >
int STK::IArray1D< Derived >::endRows ( ) const
inline
Returns
the ending index of the elements

Definition at line 191 of file STK_IArray1D.h.

191{ return end();}

References STK::IArray1D< Derived >::end().

◆ erase()

template<class Derived >
Derived & STK::IArray1D< Derived >::erase ( int  pos,
int  n = 1 
)

Delete n elements at the pos index to the container.

Parameters
posindex where to delete elements
nnumber of elements to delete (default 1)

Definition at line 479 of file STK_IArray1D.h.

480{
481#ifdef STK_DEBUG_ARRAY2D
482 stk_cout << _T("Entering IArray1D::erase\n");
483 stk_cout << _T("Deleting pos=") << pos <<_T(", n=") << n <<_T("\n");
484#endif
485
486// STK_STATIC_ASSERT_DENSE_ONLY(Derived)
487 // checks
488 if (n<=0) return this->asDerived();
489 if (isRef())
490 { STKRUNTIME_ERROR_2ARG(IArray1D::erase,pos, n,cannot operate on reference);}
491#ifdef STK_BOUNDS_CHECK
492 if (begin() > pos)
493 { STKOUT_OF_RANGE_2ARG(IArray1D::erase,pos, n,begin() > pos);}
494 if (end() <= pos)
495 { STKOUT_OF_RANGE_2ARG(IArray1D::erase,pos, n,end() <= pos);}
496 if (end() < pos+n)
497 { STKOUT_OF_RANGE_2ARG(IArray1D::erase,pos, n,end() < pos+n);}
498#endif
499
500 // translate remaining elements and update dimensions
501 allocator_.memmove(pos, _R(pos+n, end()-1));
502
503 decLast(n);
504 if (size() <= 0) this->freeMem(); // if empty release allocated memory
505 return this->asDerived();
506}
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:120
#define _R(first, last)
Utility macro that can be used in a similar way that first:last.
Definition STK_Range.h:53
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Derived & erase(int pos, int n=1)
Delete n elements at the pos index to the container.
void decLast(int n=1)
decrement the end of the container.

References _R, _T, STK::decLast(), STK::IArray1D< Derived >::erase(), stk_cout, STKOUT_OF_RANGE_2ARG, and STKRUNTIME_ERROR_2ARG.

Referenced by STK::IArray1D< Derived >::erase(), and STK::KernelHandler::removeKernel().

◆ exchange()

template<class Derived >
void STK::IArray1D< Derived >::exchange ( IArray1D< Derived > &  T)

exchange this Container with T.

Parameters
Tthe Array to exchange with this

Definition at line 602 of file STK_IArray1D.h.

603{
604 allocator_.exchange(T.allocator_);
606}
void exchange(ITContainer1D &T)
exchange this container with T

References STK::IArray1D< Derived >::allocator_.

◆ freeMem()

template<class Derived >
void STK::IArray1D< Derived >::freeMem ( )
protected

Method for memory deallocation.

Memory is liberated and the range of the Container is set to begin:begin-1.

Definition at line 669 of file STK_IArray1D.h.

670{
671 if (isRef()) return; // Nothing to do for ref
672 allocator_.free();
673 setRange(RowRange(begin(),0)); // set range to default (Base)
674}
hidden::Traits< Derived >::RowRange RowRange

◆ incLast()

template<class Derived >
void STK::ITContainer1D< Derived >::incLast ( int  n = 1)
inline

increment the end of the container (can be negative).

Parameters
nincrement to apply to the end of the range

Definition at line 271 of file STK_ITContainer1D.h.

271{ range_.incLast(n);}

◆ incRange()

template<class Derived >
void STK::ITContainer1D< Derived >::incRange ( int  n = 1)
inline

increment the range of the container (can be negative).

Parameters
nincrement to apply to the range

Definition at line 259 of file STK_ITContainer1D.h.

259{ range_.inc(n);}

◆ initialize()

template<class Derived >
void STK::IArray1D< Derived >::initialize ( RowRange const I)
protected

function for memory allocation and initialization.

This method will free all allocated memory owned by this container before initialization.

Parameters
Irange of the container

Definition at line 647 of file STK_IArray1D.h.

648{
649 allocate(I);
650 allocator_.setRef(false);
651 setRange(I);
652}
void allocate(RowRange const &I)
function for memory allocation.

◆ insert() [1/2]

template<class Derived >
Derived & STK::IArray1D< Derived >::insert ( int  pos,
Type const v 
)

STL compatibility: Insert element v at position pos of the Array.

Parameters
posposition to insert elements
vvalue to insert

Definition at line 559 of file STK_IArray1D.h.

560{
561 insertElt(pos, 1);
562 allocator_.setValue(pos,v);
563 return this->asDerived();
564}
Derived & insertElt(int pos, int n=1)
Insert n elements at the position pos of the container.

◆ insert() [2/2]

template<class Derived >
Derived & STK::IArray1D< Derived >::insert ( Range const I,
Type const v 
)

STL compatibility: Insert element v in the range I of the Array.

Parameters
Irange of the index where to insert elements
vvalue to insert

Definition at line 567 of file STK_IArray1D.h.

568{
569 insertElt(I.begin(), I.size());
570 for (int i=I.begin(); i<I.end(); i++) allocator_.setValue(i,v);
571 return this->asDerived();
572}

◆ insertElt()

template<class Derived >
Derived & STK::IArray1D< Derived >::insertElt ( int  pos,
int  n = 1 
)

Insert n elements at the position pos of the container.

Parameters
pos,nindex where to insert the n elements (default is 1)

Definition at line 509 of file STK_IArray1D.h.

510{
511 // checks
512 if (n <= 0 ) return this->asDerived();
513 if (isRef()) { STKRUNTIME_ERROR_2ARG(IArray1D::insertElt,pos,n,cannot operate on references);}
514#ifdef STK_BOUNDS_CHECK
515 if (begin() > pos)
517 if (end() < pos)
519#endif
520
521 // allocate, if necessary, memory for the elements
522 if ( (capacity() < size()+n) && !isFixedSize_ )
523 {
524 // temporary container
525 IArray1D Taux;
526 exchange(Taux);
527 // compute range of the container after insertion
528 RowRange range(Taux.range());
529 range.incLast(n);
530 // allocate
531 try { allocate(range);}
532 catch (Exception const& error) // if an error occur
533 {
534 exchange(Taux); // restore this
535 throw error; // and send again the Exception
536 }
537 // set range
538 setRange(Taux.range());
539 // copy original elements
540 allocator_.memcpy(Taux.begin(), Taux.allocator_, Range(Taux.begin(), pos - begin()) );
541 allocator_.memcpy(pos+n, Taux.allocator_, Range(pos, end()-pos) );
542 }
543 else // enough space -> shift the last elements
544 {
545 if (!isFixedSize_)
546 { allocator_.memmove(pos+n, Range(pos, end() - pos));}
547 else
548 { allocator_.memmove(pos+n, Range(pos, end() - pos - n));}
549 }
550 incLast(n);
551 return this->asDerived();
552}
int capacity() const
void exchange(IArray1D &T)
exchange this Container with T.
void incLast(int n=1)
increment the end of the container (can be negative).
IArray1D()
Default constructor.
TRange< UnknownSize > Range
Definition STK_Range.h:59

References STK::IRunnerBase::error(), STK::incLast(), STK::IArray1D< Derived >::insertElt(), STKOUT_OF_RANGE_2ARG, and STKRUNTIME_ERROR_2ARG.

Referenced by STK::IArray1D< Derived >::insertElt().

◆ isRef()

template<class Derived >
bool STK::IArray1D< Derived >::isRef ( ) const
inline
Returns
true if *this is reference container, false otherwise

Definition at line 175 of file STK_IArray1D.h.

175{ return allocator_.isRef();}

References STK::IArray1D< Derived >::allocator_.

◆ lastIdx()

template<class Derived >
int STK::ITContainer1D< Derived >::lastIdx ( ) const
inline
Returns
the index of the last element

Definition at line 120 of file STK_ITContainer1D.h.

120{ return range_.lastIdx();}

Referenced by STK::IArray1D< Derived >::lastIdxRows().

◆ lastIdxCols()

template<class Derived >
int STK::IArray1D< Derived >::lastIdxCols ( ) const
inline
Returns
the index of the last element

Definition at line 207 of file STK_IArray1D.h.

207{ return baseIdx;}

References STK::baseIdx.

◆ lastIdxRows()

template<class Derived >
int STK::IArray1D< Derived >::lastIdxRows ( ) const
inline
Returns
the index of the last element

Definition at line 205 of file STK_IArray1D.h.

205{ return this->lastIdx();}
int lastIdx() const

References STK::IArray1D< Derived >::lastIdx().

◆ memmove()

template<class Derived >
void STK::IArray1D< Derived >::memmove ( int  pos1,
int  pos2,
int  n 
)

Copy n elements from pos2 to pos1, guaranteeing correct behavior for overlapping.

Parameters
pos1,pos2positions of the elements to move
nnumber of elements to move

Definition at line 624 of file STK_IArray1D.h.

625{
626#ifdef STK_BOUNDS_CHECK
627 if (begin() > pos1) { STKOUT_OF_RANGE_2ARG(IArray1D::memmove,pos1,pos2,begin()>pos1);}
628 if (end() <= pos1) { STKOUT_OF_RANGE_2ARG(IArray1D::memmove,pos1,pos2,end()<=pos1);}
629 if (begin() > pos2) { STKOUT_OF_RANGE_2ARG(IArray1D::memmove,pos1,pos2,begin()>pos2);}
630 if (end() < pos2+n) { STKOUT_OF_RANGE_2ARG(IArray1D::memmove,pos1,pos2,end()<pos2+n);}
631#endif
632 allocator_.memmove(pos1, Range(pos2, n));
633}
void memmove(int pos1, int pos2, int n)
Copy n elements from pos2 to pos1, guaranteeing correct behavior for overlapping.

References STK::IArray1D< Derived >::memmove(), and STKOUT_OF_RANGE_2ARG.

Referenced by STK::IArray1D< Derived >::memmove().

◆ move()

template<class Derived >
void STK::IArray1D< Derived >::move ( Derived const T)

move T to this.

Note
: T is not modified but just set as a reference of the data it was owner.
Parameters
Tthe container to move to this.

Definition at line 443 of file STK_IArray1D.h.

444{
445 if (this->asPtrDerived() == &T) return; // avoid move on itself
446 if (!isRef()) { freeMem();}
447 allocator_.move(T.allocator_); // move Allocator part
448 setRange(T.range()); // Set ITContainer1D part
449}
Derived * asPtrDerived()
static cast : return a ptr on a Derived of this with a cast to the derived class.

◆ popBack()

template<class Derived >
Derived & STK::IArray1D< Derived >::popBack ( int  n = 1)

Delete last elts of the container.

Parameters
nnumber of elts to delete

Definition at line 467 of file STK_IArray1D.h.

468{
469 // checks
470 if (n <= 0 || isFixedSize_) return this->asDerived();
471 if (isRef())
472 { STKRUNTIME_ERROR_1ARG(IArray1D::popBack,n,cannot operate on reference);}
473 decLast(n);
474 if (size() <= 0) this->freeMem(); // release mem if there's no more elts
475 return this->asDerived();
476}
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
Derived & popBack(int n=1)
Delete last elts of the container.

References STK::decLast(), STK::IArray1D< Derived >::popBack(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::IArray1D< Derived >::popBack().

◆ push_back()

template<class Derived >
Derived & STK::IArray1D< Derived >::push_back ( Type const v)

STL compatibility: append an element v.

Parameters
vvalue to append

Definition at line 582 of file STK_IArray1D.h.

583{
584 pushBack();
585 allocator_.setValue(this->lastIdx(),v);
586 return this->asDerived();
587}
Derived & pushBack(int n=1)
Add n Elements to the end of the container.

Referenced by STK::KernelHandler::addKernel(), and STK::KernelHandler::addKernel().

◆ push_front()

template<class Derived >
Derived & STK::IArray1D< Derived >::push_front ( Type const v)

STL compatibility: push front an element.

Parameters
vvalue to append

Definition at line 575 of file STK_IArray1D.h.

576{
577 insert(Range(begin(), 1), v);
578 return this->asDerived();
579}
Derived & insert(int pos, Type const &v)
STL compatibility: Insert element v at position pos of the Array.

◆ pushBack()

template<class Derived >
Derived & STK::IArray1D< Derived >::pushBack ( int  n = 1)

Add n Elements to the end of the container.

Parameters
nnumber of elements to add

Definition at line 452 of file STK_IArray1D.h.

453{
454#ifdef STK_ARRAYS_VERY_VERBOSE
455 stk_cout << _T("Entering IArray1D<Derived>::pushBack(") << n << _T(")\n");
456#endif
457 // checks
458 if (n <= 0) return this->asDerived();
459 if (isRef()) { STKRUNTIME_ERROR_1ARG(IArray1D::pushBack,n,cannot operate on references);}
460 // If container is empty : create it, otherwise add element from end() position
461 if (this->empty()) { initialize(RowRange(begin(), n));}
462 else { insertElt(end(), n);}
463 return this->asDerived();
464}
void initialize(RowRange const &I)
function for memory allocation and initialization.
bool empty() const
Is there some data ?

References _T, STK::IArray1D< Derived >::pushBack(), stk_cout, and STKRUNTIME_ERROR_1ARG.

Referenced by STK::IArray1D< Derived >::pushBack().

◆ range()

template<class Derived >
RowRange const & STK::ITContainer1D< Derived >::range ( ) const
inline

◆ reserve()

template<class Derived >
void STK::IArray1D< Derived >::reserve ( int  size)

reserve internal memory for at least size elements.

Parameters
sizenumber of elements to reserve

Definition at line 426 of file STK_IArray1D.h.

427{
428 // nothing to do
429 if (size < this->capacity() || isFixedSize_) return;
430 // is this structure a ptr ?
431 if (isRef()) { STKRUNTIME_ERROR_1ARG(IArray1D::reserve,size,cannot operate on references);}
432 allocator_.realloc(Range(begin(), size));
433}
void reserve(int size)
reserve internal memory for at least size elements.

References STK::IArray1D< Derived >::reserve(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::IArray1D< Derived >::reserve().

◆ resizeImpl()

template<class Derived >
Derived & STK::IArray1D< Derived >::resizeImpl ( Range const I)

Resize the container.

  • call shift
  • call pushBack if there will be more elements
  • call popBack if three will be less elements
    Parameters
    Ithe range to set to the Array1D

Definition at line 410 of file STK_IArray1D.h.

411{
412 // check if there is something to do
413 if ( range() == I) return this->asDerived();
414 if (isRef()) { STKRUNTIME_ERROR_1ARG(IArray1D::resizeImpl,I,cannot operate on references);}
415 // translate
416 shiftImpl(I.begin());
417 // compute number of elements to delete or add
418 const int inc = I.end() - end();
419 // adjust size of the container
420 if (inc > 0) pushBack(inc); // more elements
421 else popBack(-inc); // less elements
422 return this->asDerived();
423}
Derived & resizeImpl(Range const &I)
Resize the container.
void shiftImpl(int beg=baseIdx)
New beginning index for the object.

References STK::IArray1D< Derived >::resizeImpl(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::IArray1D< Derived >::resizeImpl().

◆ rows()

template<class Derived >
RowRange const & STK::IArray1D< Derived >::rows ( ) const
inline
Returns
the range of the rows of the container

Definition at line 187 of file STK_IArray1D.h.

187{ return range();}

References STK::IArray1D< Derived >::range().

◆ setRange()

template<class Derived >
void STK::ITContainer1D< Derived >::setRange ( RowRange const I = RowRange())
inline

Set range of the rows of the container.

Parameters
Ithe range to set (default empty)

Definition at line 255 of file STK_ITContainer1D.h.

255{ range_ = I;}

◆ setRef()

template<class Derived >
void STK::IArray1D< Derived >::setRef ( bool  ref) const
inline

Modify the state of the container: this become a reference (if ref is true) or the owner of the data (if ref is false).

Note
To use with care in order to avoid memory leak
Parameters
ref: has top be false if this own its own data

Definition at line 181 of file STK_IArray1D.h.

181{ allocator_.setRef(ref);}

References STK::IArray1D< Derived >::allocator_.

◆ setValue() [1/2]

template<class Derived >
void STK::IArray1D< Derived >::setValue ( int  pos,
TypeConst  value 
)
inline

Write a value at a given position.

Parameters
pos,valueindex of the element
Returns
a reference on the element to modify

Definition at line 231 of file STK_IArray1D.h.

232 { allocator_.setValue(pos, value);}

References STK::IArray1D< Derived >::allocator_.

◆ setValue() [2/2]

template<class Derived >
Derived & STK::IArray1D< Derived >::setValue ( Type const value)

set a value to this container.

Parameters
valuethe value to set

Definition at line 640 of file STK_IArray1D.h.

641{
642 allocator_.assign(range(), value);
643 return this->asDerived();
644}

◆ shiftImpl()

template<class Derived >
void STK::IArray1D< Derived >::shiftImpl ( int  beg = baseIdx)

New beginning index for the object.

Parameters
begthe index of the first column to set

Definition at line 397 of file STK_IArray1D.h.

398{
399 // compute increment
400 int inc = beg - begin();
401 if (inc == 0) return;
402 if (isRef()) // is this structure just a pointer ?
403 { STKRUNTIME_ERROR_1ARG(IArray1D::shiftImpl,beg,cannot operate on references);}
404 // translate range and data
405 incRange(inc);
406 allocator_.shift(beg);
407}
void incRange(int n=1)
increment the range of the container (can be negative).

References STK::IArray1D< Derived >::shiftImpl(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::IArray1D< Derived >::shiftImpl().

◆ size()

template<class Derived >
int STK::ITContainer1D< Derived >::size ( ) const
inline
Returns
the size of the container

Definition at line 117 of file STK_ITContainer1D.h.

117{ return range_.size();}

Referenced by STK::MemSAllocator< Type_, NzMax_, Size_ >::size(), and STK::IArray1D< Derived >::sizeRows().

◆ sizeCols()

template<class Derived >
int STK::IArray1D< Derived >::sizeCols ( ) const
inline
Returns
the number of columns

Definition at line 202 of file STK_IArray1D.h.

202{ return 1;};

◆ sizeRows()

template<class Derived >
int STK::IArray1D< Derived >::sizeRows ( ) const
inline
Returns
the size of the container

Definition at line 193 of file STK_IArray1D.h.

193{ return size();}

References STK::IArray1D< Derived >::size().

◆ swap()

template<class Derived >
void STK::IArray1D< Derived >::swap ( int  pos1,
int  pos2 
)

Swapping the pos1 elt and the pos2 elt.

Parameters
pos1,pos2positions of the elements to swap

Definition at line 590 of file STK_IArray1D.h.

591{
592#ifdef STK_BOUNDS_CHECK
593 if (begin() > pos1) { STKOUT_OF_RANGE_2ARG(IArray1D::swap,pos1,pos2,begin()>pos1);}
594 if (end() <= pos1) { STKOUT_OF_RANGE_2ARG(IArray1D::swap,pos1,pos2,end()<=pos1);}
595 if (begin() > pos2) { STKOUT_OF_RANGE_2ARG(IArray1D::swap,pos1,pos2,begin()>pos2);}
596 if (end() <= pos2) { STKOUT_OF_RANGE_2ARG(IArray1D::swap,pos1,pos2,end()<=pos2);}
597#endif
598 std::swap(elt(pos1), elt(pos2));
599}
Type & elt(int i)
void swap(int pos1, int pos2)
Swapping the pos1 elt and the pos2 elt.

References STKOUT_OF_RANGE_2ARG, and STK::IArray1D< Derived >::swap().

Referenced by STK::IArray1D< Derived >::swap().

Member Data Documentation

◆ allocator_


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