STK++ 0.9.13
STK::List1D< Type_ > Class Template Reference

template One dimensional Horizontal List. More...

#include <STK_List1D.h>

Inheritance diagram for STK::List1D< Type_ >:
Inheritance graph

Public Types

enum  {
  structure_ = hidden::Traits< List1D <Type_> >::structure_ , orient_ = hidden::Traits< List1D <Type_> >::orient_ , sizeRows_ = hidden::Traits< List1D <Type_> >::sizeRows_ , sizeCols_ = hidden::Traits< List1D <Type_> >::sizeCols_ ,
  storage_ = hidden::Traits< List1D <Type_> >::storage_
}
 
typedef hidden::Traits< List1D< Type_ > >::Type Type
 
typedef hidden::Traits< List1D< Type_ > >::TypeConst TypeConst
 
typedef hidden::Traits< List1D< Type_ > >::RowRange RowRange
 
typedef hidden::Traits< List1D< Type_ > >::ColRange ColRange
 
typedef ITContainer1D< List1D< Type > > Base
 
typedef CellHo< TypeCell
 
typedef hidden::Traits< List1D< Type_ > >::Iterator Iterator
 
typedef hidden::Traits< List1D< Type_ > >::ConstIterator ConstIterator
 
typedef hidden::Traits< List1D< Type_ > >::ReverseIterator ReverseIterator
 
typedef hidden::Traits< List1D< Type_ > >::ConstReverseIterator ConstReverseIterator
 
typedef Iterator iterator
 
typedef ConstIterator const_iterator
 
typedef ReverseIterator reverse_iterator
 
typedef ConstReverseIterator const_reverse_iterator
 
- Public Types inherited from STK::ITContainer1D< List1D< Type_ > >
enum  
 
typedef hidden::Traits< List1D< Type_ > >::Type Type
 
typedef hidden::Traits< List1D< Type_ > >::TypeConst TypeConst
 
typedef hidden::Traits< List1D< Type_ > >::RowRange RowRange
 
typedef hidden::Traits< List1D< Type_ > >::ColRange ColRange
 
typedef hidden::Traits< List1D< Type_ > >::Row Row
 
typedef hidden::Traits< List1D< Type_ > >::Col Col
 
typedef hidden::Traits< List1D< Type_ > >::SubVector SubVector
 
typedef hidden::Traits< List1D< Type_ > >::Iterator Iterator
 
typedef hidden::Traits< List1D< Type_ > >::ConstIterator ConstIterator
 
typedef hidden::Traits< List1D< Type_ > >::ReverseIterator ReverseIterator
 
typedef hidden::Traits< List1D< Type_ > >::ConstReverseIterator ConstReverseIterator
 

Public Member Functions

 List1D ()
 Default constructor : empty List.
 
 List1D (Range const &I)
 constructor with specified Range.
 
 List1D (Range const &I, Type const &v)
 Misc constructor, initialization with a constant.
 
 List1D (List1D< Type > const &T)
 Copy constructor.
 
 List1D (List1D< Type > const &T, Range const &J, bool ref=true)
 access to many elements.
 
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
 
 ~List1D ()
 destructor.
 
Cell const *const p_begin () const
 
Cell const *const p_lastIdx () const
 
Typeelt1Impl (int pos)
 access to one element.
 
Type constelt1Impl (int pos) const
 access to one element const.
 
List1D subImpl (Range const &J) const
 access to many elements.
 
void shiftImpl (int const &beg)
 New first index for the object.
 
void clear ()
 Clear the object.
 
void pushBack (int const &n=1)
 Add n Elts to the container.
 
void insert (Range const &I, Type const &v)
 Insert element v in the range I of the List1D.
 
void merge (List1D const &other)
 merge this with other.
 
void insertElt (int pos, int const &n=1)
 Insert n elts at the position pos of the container.
 
void popBack (int const &n=1)
 Delete n last elements of the container.
 
void erase (int pos, int const &n=1)
 Delete n elts at the pos index to the container.
 
void swap (int const &j1, int const &j2)
 Swapping the j1th column and the j2th column.
 
List1Doperator= (const List1D &T)
 operator = : overwrite the List1D with T.
 
List1D< Type > & resizeImpl (Range const &I)
 Resize the container.
 
List1D< Type > & operator= (Type const &v)
 operator= : set the container to a constant value.
 
int begin () const
 
int end () const
 
int size () const
 
int lastIdx () const
 
- Public Member Functions inherited from STK::ITContainer1D< List1D< Type_ > >
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)
 
List1D< Type_ > & 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.
 
- Public Member Functions inherited from STK::TRef<-1 >
bool isRef () const
 
bool ref () const
 
void exchange (TRef const &T)
 swap this with the container T.
 
void setRef (bool ref) const
 Modify the container : can become a reference or the owner of the data.
 

Protected Member Functions

 List1D (Cell *const &p_first, Cell *const &p_last, Range const &J)
 constructor by reference, ref_=1.
 
void initialize (Range const &I)
 Protected function for initialization.
 
void freeMem ()
 Protected function for deallocation.
 
- Protected Member Functions inherited from STK::ITContainer1D< List1D< Type_ > >
 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.
 
- Protected Member Functions inherited from STK::TRef<-1 >
 TRef (bool ref)
 Default constructor We have to specify the member ref_.
 
 ~TRef ()
 destructor.
 

Protected Attributes

Cellp_begin_
 First Element of the List.
 
Cellp_last_
 Last Element of the List.
 

Private Member Functions

void setDefault ()
 set members values to default.
 
void moveCurrentPositionLeft () const
 Move CurrentPositionent position to left.
 
void moveCurrentPositionRight () const
 move CurrentPositionent position to right
 
void moveCurrentPosition (int pos) const
 Move the current position to pos.
 

Private Attributes

int currentPosition_
 Current position of pointer p_current_ in the List1D.
 
Cellp_current_
 Current position pointed in the List1D.
 

Detailed Description

template<class Type_>
class STK::List1D< Type_ >

template One dimensional Horizontal List.

A List1D is an implementation of the Interface ITContainer1D for list of homogeneous objects.

Definition at line 112 of file STK_List1D.h.

Member Typedef Documentation

◆ Base

template<class Type_ >
typedef ITContainer1D< List1D<Type> > STK::List1D< Type_ >::Base

Definition at line 129 of file STK_List1D.h.

◆ Cell

template<class Type_ >
typedef CellHo<Type> STK::List1D< Type_ >::Cell

Definition at line 130 of file STK_List1D.h.

◆ ColRange

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::ColRange STK::List1D< Type_ >::ColRange

Definition at line 128 of file STK_List1D.h.

◆ const_iterator

template<class Type_ >
typedef ConstIterator STK::List1D< Type_ >::const_iterator

Definition at line 139 of file STK_List1D.h.

◆ const_reverse_iterator

template<class Type_ >
typedef ConstReverseIterator STK::List1D< Type_ >::const_reverse_iterator

Definition at line 141 of file STK_List1D.h.

◆ ConstIterator

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::ConstIterator STK::List1D< Type_ >::ConstIterator

Definition at line 133 of file STK_List1D.h.

◆ ConstReverseIterator

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::ConstReverseIterator STK::List1D< Type_ >::ConstReverseIterator

Definition at line 135 of file STK_List1D.h.

◆ Iterator

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::Iterator STK::List1D< Type_ >::Iterator

Definition at line 132 of file STK_List1D.h.

◆ iterator

template<class Type_ >
typedef Iterator STK::List1D< Type_ >::iterator

Definition at line 138 of file STK_List1D.h.

◆ reverse_iterator

template<class Type_ >
typedef ReverseIterator STK::List1D< Type_ >::reverse_iterator

Definition at line 140 of file STK_List1D.h.

◆ ReverseIterator

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::ReverseIterator STK::List1D< Type_ >::ReverseIterator

Definition at line 134 of file STK_List1D.h.

◆ RowRange

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::RowRange STK::List1D< Type_ >::RowRange

Definition at line 127 of file STK_List1D.h.

◆ Type

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::Type STK::List1D< Type_ >::Type

Definition at line 115 of file STK_List1D.h.

◆ TypeConst

template<class Type_ >
typedef hidden::Traits<List1D<Type_>>::TypeConst STK::List1D< Type_ >::TypeConst

Definition at line 116 of file STK_List1D.h.

Member Enumeration Documentation

◆ anonymous enum

template<class Type_ >
anonymous enum
Enumerator
structure_ 
orient_ 
sizeRows_ 
sizeCols_ 
storage_ 

Definition at line 118 of file STK_List1D.h.

119 {
120 structure_ = hidden::Traits< List1D <Type_> >::structure_,
121 orient_ = hidden::Traits< List1D <Type_> >::orient_,
122 sizeRows_ = hidden::Traits< List1D <Type_> >::sizeRows_,
123 sizeCols_ = hidden::Traits< List1D <Type_> >::sizeCols_,
124 storage_ = hidden::Traits< List1D <Type_> >::storage_
125 };

Constructor & Destructor Documentation

◆ List1D() [1/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( )
inline

Default constructor : empty List.

Definition at line 149 of file STK_List1D.h.

149: Base(), IContainerRef(false) { initialize(Range()); }
void initialize(Range const &I)
Protected function for initialization.
Definition STK_List1D.h:611
ITContainer1D< List1D< Type > > Base
Definition STK_List1D.h:129
TRef<-1 > IContainerRef
TRange< UnknownSize > Range
Definition STK_Range.h:59

References STK::List1D< Type_ >::initialize().

Referenced by STK::List1D< Type_ >::List1D(), and STK::List1D< Type_ >::subImpl().

◆ List1D() [2/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( Range const I)
inline

constructor with specified Range.

Parameters
Irange of the container

Definition at line 153 of file STK_List1D.h.

153 : Base(I), IContainerRef(false)
154 { initialize(I); }

References STK::List1D< Type_ >::initialize().

◆ List1D() [3/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( Range const I,
Type const v 
)
inline

Misc constructor, initialization with a constant.

Parameters
Irange of the container
vinitial value of the container

Definition at line 159 of file STK_List1D.h.

160 : ITContainer1D<List1D >(I), IContainerRef(false)
161 { initialize(I);
162 Cell* p1 = p_begin_;
163 for ( int j=begin(); j<end(); j++)
164 { (*p1) = v; // overwrite the value of the current cell
165 p1 = p1->getRight(); // Goto Right place
166 }
167 }
int end() const
CellHo< Type > Cell
Definition STK_List1D.h:130
Cell * p_begin_
First Element of the List.
Definition STK_List1D.h:608
int begin() const

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::end(), STK::List1D< Type_ >::initialize(), and STK::List1D< Type_ >::p_begin_.

◆ List1D() [4/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( List1D< Type > const T)
inline

Copy constructor.

Parameters
Tthe list to copy

Definition at line 171 of file STK_List1D.h.

171 : Base(T), IContainerRef(false)
173 {
174 // initialize container
175 initialize(T.range());
176 // copy the container
177 Cell* p1 = p_begin_;
178 Cell* pt1 = T.p_begin_;
179 for (int j=T.begin(); j<T.end(); j++)
180 { (*p1) = pt1->data(); // write the value of the current cell
181 p1 = p1->getRight(); // Goto Right
182 pt1 = pt1->getRight(); // Goto Right
183 }
184 }
Cell * p_current_
Current position pointed in the List1D.
Definition STK_List1D.h:668
Cell * p_last_
Last Element of the List.
Definition STK_List1D.h:609
int currentPosition_
Current position of pointer p_current_ in the List1D.
Definition STK_List1D.h:666

References STK::List1D< Type_ >::initialize(), and STK::List1D< Type_ >::p_begin_.

◆ List1D() [5/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( List1D< Type > const T,
Range const J,
bool  ref = true 
)
inline

access to many elements.

Parameters
Tthe list to reference
Jthe range of the elements
refis this a reference of T ?
Returns
a list with a reference to the elements in the given range

Definition at line 191 of file STK_List1D.h.

192 : Base(J), IContainerRef(ref)
193 {
194#ifdef STK_BOUNDS_CHECK
195 if ((J.begin()<T.begin()))
196 { STKOUT_OF_RANGE_1ARG(List1D::List1D,J,J.begin()<T.begin());}
197 if ((J.lastIdx()>T.lastIdx()))
198 { STKOUT_OF_RANGE_1ARG(List1D::List1D,J,J.lastIdx()>T.lastIdx());}
199#endif
200 if (!ref)
201 {
202 initialize(J);
203 (*this) = T;
204 }
205 else
206 {
207 T.moveCurrentPosition(J.begin());
208 p_begin_ = T.p_current_;
209 moveCurrentPosition(J.lastIdx());
210 p_last_ = T.p_current_;
213 }
214 }
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93
void moveCurrentPosition(int pos) const
Move the current position to pos.
Definition STK_List1D.h:693
List1D()
Default constructor : empty List.
Definition STK_List1D.h:149

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::List1D< Type_ >::initialize(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::moveCurrentPosition(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_current_, STK::List1D< Type_ >::p_last_, STK::TRef<-1 >::ref(), and STKOUT_OF_RANGE_1ARG.

◆ List1D() [6/6]

template<class Type_ >
STK::List1D< Type_ >::List1D ( Cell *const p_first,
Cell *const p_last,
Range const J 
)
inlineprotected

constructor by reference, ref_=1.

This constructor does not copy physically the elements contained in the Container. The List1D is wrapped by a reference List1D reduced to the range J.

Parameters
p_firstthe first cell of the container to wrap
p_lastthe last cell of the container to wrap
Jrange of the data to wrap

Definition at line 248 of file STK_List1D.h.

249 : Base(J), IContainerRef(true)
250 , p_begin_(p_first)
251 , p_last_(p_last)
252 {
254 p_current_ = p_first;
255 }

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, and STK::List1D< Type_ >::p_current_.

◆ ~List1D()

template<class Type_ >
STK::List1D< Type_ >::~List1D ( )
inline

destructor.

Definition at line 258 of file STK_List1D.h.

258{ if (!this->isRef()) freeMem();}
void freeMem()
Protected function for deallocation.
Definition STK_List1D.h:651
bool isRef() const

References STK::List1D< Type_ >::freeMem(), and STK::TRef<-1 >::isRef().

Member Function Documentation

◆ begin()

◆ beginCols()

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

Definition at line 227 of file STK_List1D.h.

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

References STK::baseIdx.

◆ beginRows()

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

Definition at line 218 of file STK_List1D.h.

218{ return begin();}

References STK::List1D< Type_ >::begin().

◆ clear()

template<class Type_ >
void STK::List1D< Type_ >::clear ( )
inline

Clear the object.

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

Definition at line 314 of file STK_List1D.h.

315 {
316 if (this->isRef()) return; // Nothing to do for ref
317 freeMem(); // Free mem
318 this->setRange(); // Set to default the dimension
319 }
void setRange(RowRange const &I=RowRange())
Set range of the rows of the container.

References STK::List1D< Type_ >::freeMem(), STK::TRef<-1 >::isRef(), and STK::ITContainer1D< List1D< Type_ > >::setRange().

◆ cols()

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

Definition at line 225 of file STK_List1D.h.

225{ return ColRange(1);}
hidden::Traits< List1D< Type_ > >::ColRange ColRange
Definition STK_List1D.h:128

◆ elt1Impl() [1/2]

template<class Type_ >
Type & STK::List1D< Type_ >::elt1Impl ( int  pos)
inline

access to one element.

Parameters
posindex of the element
Returns
a reference on the element pos

Definition at line 267 of file STK_List1D.h.

268 {
270 return (p_current_->data());
271 }

References STK::List1D< Type_ >::moveCurrentPosition(), and STK::List1D< Type_ >::p_current_.

◆ elt1Impl() [2/2]

template<class Type_ >
Type const & STK::List1D< Type_ >::elt1Impl ( int  pos) const
inline

access to one element const.

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

Definition at line 276 of file STK_List1D.h.

277 {
279 return (p_current_->data());
280 }

References STK::List1D< Type_ >::moveCurrentPosition(), and STK::List1D< Type_ >::p_current_.

◆ end()

template<class Type_ >
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::List1D< Type_ >::endRows(), STK::List1D< Type_ >::freeMem(), STK::List1D< Type_ >::initialize(), and STK::List1D< Type_ >::List1D().

◆ endCols()

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

Definition at line 229 of file STK_List1D.h.

229{ return baseIdx+1;}

References STK::baseIdx.

◆ endRows()

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

Definition at line 220 of file STK_List1D.h.

220{ return end();}

References STK::List1D< Type_ >::end().

◆ erase()

template<class Type_ >
void STK::List1D< Type_ >::erase ( int  pos,
int const n = 1 
)
inline

Delete n elts at the pos index to the container.

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

Definition at line 475 of file STK_List1D.h.

476 {
477 // if n==0 nothing to do
478 if (n<=0) return;
479 // is this structure just a pointer?
480 if (this->isRef())
481 { STKRUNTIME_ERROR_2ARG(List1D::erase,pos, n,cannot operate on references.);}
482 // check bounds
483 if (begin() > pos)
485 if (this->lastIdx() < pos)
486 { STKOUT_OF_RANGE_2ARG(List1D::erase,pos, n,lastIdx() < pos);}
487 if (this->lastIdx() < pos+n-1)
488 { STKOUT_OF_RANGE_2ARG(List1D::erase,pos, n,lastIdx() < pos+n-1);}
489 // Move the current position to pos
491 Cell* p2 = p_current_; // get pos-th cell
492 moveCurrentPositionLeft(); // set current to (pos-1)th position
493 // delete n cells
494 for (int l=1; l<=n; l++)
495 { Cell* p3 = p2->getRight(); // get right cell in p3
496 delete p2; // delete current cell
497 p2 = p3; // next
498 }
499 // If the last column have been erased update p_last_
500 if (pos+n-1 == this->lastIdx()) { p_last_ = p_current_;}
501 // Update the dimension of the container
502 this->decLast(n);
503 // If we have erased all cols
504 if (size() == 0)
505 { setDefault();}
506 else
507 { p2->setLeft(p_current_); // p2 is the j+n cell
508 p_current_->setRight(p2); // p_current_ is on j-1 cell
509 // If the first column has been erased
510 if (pos == begin())
511 { p_begin_ = p2; // Set the new beg cell
512 p_current_ = p2; // p_current_
513 currentPosition_++; // and current position
514 }
515 }
516 }
#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
void decLast(int n=1)
decrement the end of the container.
void erase(int pos, int const &n=1)
Delete n elts at the pos index to the container.
Definition STK_List1D.h:475
void setDefault()
set members values to default.
Definition STK_List1D.h:671
int size() const
void moveCurrentPositionLeft() const
Move CurrentPositionent position to left.
Definition STK_List1D.h:679
int lastIdx() const

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::ITContainer1D< List1D< Type_ > >::decLast(), STK::List1D< Type_ >::erase(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::moveCurrentPosition(), STK::List1D< Type_ >::moveCurrentPositionLeft(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_current_, STK::List1D< Type_ >::p_last_, STK::List1D< Type_ >::setDefault(), STK::List1D< Type_ >::size(), STKOUT_OF_RANGE_2ARG, and STKRUNTIME_ERROR_2ARG.

Referenced by STK::List1D< Type_ >::erase(), and STK::List1D< Type_ >::popBack().

◆ freeMem()

template<class Type_ >
void STK::List1D< Type_ >::freeMem ( )
inlineprotected

Protected function for deallocation.

Definition at line 651 of file STK_List1D.h.

652 {
653 if (this->isRef()) return; // Nothing to do for ref
654 Cell *p2, *p1 =p_begin_; // Auxiliary pointers for cells
655 // for all cells
656 for (int j=begin(); j<end(); j++)
657 { p2 = p1->getRight(); // get the right cell
658 delete p1; // delete the curent cell
659 p1 = p2; // and iterate
660 }
661 setDefault();
662 }

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::end(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::p_begin_, and STK::List1D< Type_ >::setDefault().

Referenced by STK::List1D< Type_ >::clear(), and STK::List1D< Type_ >::~List1D().

◆ initialize()

template<class Type_ >
void STK::List1D< Type_ >::initialize ( Range const I)
inlineprotected

Protected function for initialization.

Definition at line 611 of file STK_List1D.h.

612 {
613 // set new dimensions
614 this->setRange(I);
615 if (this->empty())
616 {
617 setDefault(); return;
618 }
619 // Allocate memory for the cells
620 Cell *p1, *p2; // Auxiliary pointer for cells
621
622 p1 = new Cell(); // pointer on the first cell
623 p_begin_ = p1; // set the first cell
624 // main loop for the other cells
625 for (int j=begin()+1; j<end(); j++)
626 { try
627 { p2 = new Cell(p1);} // try to allocate memory
628 catch (std::bad_alloc & error) // if an alloc error occur
629 { while (p1 != (Cell*)NULL) // for all cells allocated
630 { p2 = p1->getLeft(); // get the cell left
631 delete p1; // delete the cell
632 p1 = p2; // and iterate
633 }
634 // set default
635 setDefault();
636 this->setRange();
637 // and throw the Exception
638 STKRUNTIME_ERROR_1ARG(List1D::initialize,I,memory allocation failed);
639 }
640 // if no error is catched
641 p1->setRight(p2); // Set the right cell
642 p1 = p2; // and iterate
643 }
644 p_last_ = p1; // Set the last cell
645 p_last_->setRight(p_begin_); // the last cell point on the first cell
646 p_begin_->setLeft(p_last_); // the first cell point on the last cell
647 currentPosition_ = begin(); // current position is first position
648 p_current_ = p_begin_; // CurrentPositionent cell is first cell
649 }
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
bool empty() const
Is there some data ?

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::ITContainer1D< List1D< Type_ > >::empty(), STK::List1D< Type_ >::end(), STK::List1D< Type_ >::initialize(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_current_, STK::List1D< Type_ >::p_last_, STK::List1D< Type_ >::setDefault(), STK::ITContainer1D< List1D< Type_ > >::setRange(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::List1D< Type_ >::initialize(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::List1D(), and STK::List1D< Type_ >::pushBack().

◆ insert()

template<class Type_ >
void STK::List1D< Type_ >::insert ( Range const I,
Type const v 
)
inline

Insert element v in the range I of the List1D.

Parameters
Irange of the index where to insert elements
vthe value tu insert

Definition at line 370 of file STK_List1D.h.

371 {
372 insertElt(I.begin(), I.size());
373 for (int i=I.begin(); i<=I.lastIdx(); i++)
374 this->elt(i) = v;
375 }
void insertElt(int pos, int const &n=1)
Insert n elts at the position pos of the container.
Definition STK_List1D.h:414

References STK::ITContainer1D< List1D< Type_ > >::elt(), and STK::List1D< Type_ >::insertElt().

◆ insertElt()

template<class Type_ >
void STK::List1D< Type_ >::insertElt ( int  pos,
int const n = 1 
)
inline

Insert n elts at the position pos of the container.

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

Definition at line 414 of file STK_List1D.h.

415 {
416 // if n<=0 nothing to do
417 if (n <= 0) return;
418 // is this structure just a pointer?
419 if (this->isRef())
420 { STKRUNTIME_ERROR_2ARG(List1D::insertElt,pos,n,cannot operate on references.);}
421 if (begin() > pos)
423 if (this->lastIdx()+1 < pos)
425 // Move the current position to j
427 Cell *p0 = p_current_->getLeft(); // Get the j-1 cell
428 Cell *p1 = p0; // Auxiliary cell;
429 // main loop for the other cells
430 for (int j1=1; j1<=n; j1++)
431 {
432 Cell *p2; // Auxiliary cell;
433 try
434 { p2 = new Cell(p1);} // try to allocate memory
435 catch (std::bad_alloc & error) // if an alloc error occur
436 { while ( p1 != p0) // for all cells allocated
437 { p2 = p1; // get the cell left
438 delete p1; // delete the curent cell
439 p1 = p2->getLeft(); // iterate
440 }
441 p0->setRight(p_current_);
442 STKRUNTIME_ERROR_2ARG(List1D::insertElt,pos,n,memory allocation failed);
443 } // catch block
444 // if no error is intercepted
445 p1->setRight(p2); // Set the right cell of the current cell
446 p1 = p2; // iterate
447 }
448 p1->setRight(p_current_); // the last cell point on the first cell
449 p_current_->setLeft(p1); // the first cell point on the last cell
450 if ( pos==begin() ) // if the beginning was modified
451 { p_begin_ = p0->getRight();} // set new beginning
452 this->incLast(n); // Update the size of the container
453 currentPosition_ +=n; // Update the current position
454 }
void incLast(int n=1)
increment the end of the container (can be negative).

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::ITContainer1D< List1D< Type_ > >::incLast(), STK::List1D< Type_ >::insertElt(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::moveCurrentPosition(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_current_, STKOUT_OF_RANGE_2ARG, and STKRUNTIME_ERROR_2ARG.

Referenced by STK::List1D< Type_ >::insert(), STK::List1D< Type_ >::insertElt(), and STK::DataFrame::insertVariable().

◆ lastIdx()

◆ lastIdxCols()

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

Definition at line 236 of file STK_List1D.h.

236{ return baseIdx;}

References STK::baseIdx.

◆ lastIdxRows()

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

Definition at line 234 of file STK_List1D.h.

234{ return this->lastIdx();}

References STK::List1D< Type_ >::lastIdx().

◆ merge()

template<class Type_ >
void STK::List1D< Type_ >::merge ( List1D< Type_ > const other)
inline

merge this with other.

other will become a reference.

Parameters
otherthe list to append

Definition at line 379 of file STK_List1D.h.

380 {
381 if (other.empty()) return;
382 // is this structure just a pointer?
383 if (this->isRef())
384 { STKRUNTIME_ERROR_NO_ARG(List1D::merge(other),*this is a reference.);}
385 // is T just a pointer?
386 if (other.isRef())
387 { STKRUNTIME_ERROR_NO_ARG(List1D::merge(other),other is a reference.);}
388 // break const reference
389 List1D& otherRef = const_cast<List1D&>(other);
390 // compute horizontal range of the container after insertion
391 Range range(this->range());
392
393 // merge
394 otherRef.p_begin_->setLeft(p_last_);
395 otherRef.p_last_->setRight(p_begin_);
396 p_last_->setRight(otherRef.p_begin_);
397 p_last_ = otherRef.p_last_;
398 p_begin_->setLeft(p_last_);
399
400 // compute first index of the first column added
401 const int first = range.lastIdx() + 1;
402 this->setRange(range.incLast(otherRef.size()));
403 otherRef.setRange(Range(first, other.size()));
404 otherRef.setRef(true);
405
406 // reset p_current_ to first position
407 otherRef.currentPosition_ = first;
408 otherRef.p_current_ = otherRef.p_begin_;
409 }
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
void merge(List1D const &other)
merge this with other.
Definition STK_List1D.h:379

References STK::TRange< UnknownSize >::incLast(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::merge(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_last_, STK::ITContainer1D< List1D< Type_ > >::range(), STK::ITContainer1D< List1D< Type_ > >::setRange(), and STKRUNTIME_ERROR_NO_ARG.

Referenced by STK::List1D< Type_ >::merge().

◆ moveCurrentPosition()

template<class Type_ >
void STK::List1D< Type_ >::moveCurrentPosition ( int  pos) const
inlineprivate

Move the current position to pos.

Parameters
posthe position to move

Definition at line 693 of file STK_List1D.h.

694 {
695 if (pos>currentPosition_)
696 {
697 if ((pos-currentPosition_) <= (this->lastIdx()-pos))
699 else // else start from the end
702 }
703 else
704 {
705 if ((currentPosition_-pos) <= (pos-begin()))
707 else // else start from the beginning
710 }
711 }
void moveCurrentPositionRight() const
move CurrentPositionent position to right
Definition STK_List1D.h:685

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::moveCurrentPositionLeft(), STK::List1D< Type_ >::moveCurrentPositionRight(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_current_, and STK::List1D< Type_ >::p_last_.

Referenced by STK::List1D< Type_ >::elt1Impl(), STK::List1D< Type_ >::elt1Impl(), STK::List1D< Type_ >::erase(), STK::List1D< Type_ >::insertElt(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::subImpl(), and STK::List1D< Type_ >::swap().

◆ moveCurrentPositionLeft()

template<class Type_ >
void STK::List1D< Type_ >::moveCurrentPositionLeft ( ) const
inlineprivate

Move CurrentPositionent position to left.

Definition at line 679 of file STK_List1D.h.

680 {
681 p_current_ = p_current_->getLeft();
683 }

References STK::List1D< Type_ >::currentPosition_, and STK::List1D< Type_ >::p_current_.

Referenced by STK::List1D< Type_ >::erase(), and STK::List1D< Type_ >::moveCurrentPosition().

◆ moveCurrentPositionRight()

template<class Type_ >
void STK::List1D< Type_ >::moveCurrentPositionRight ( ) const
inlineprivate

move CurrentPositionent position to right

Definition at line 685 of file STK_List1D.h.

686 {
687 p_current_ = p_current_->getRight();
689 }

References STK::List1D< Type_ >::currentPosition_, and STK::List1D< Type_ >::p_current_.

Referenced by STK::List1D< Type_ >::moveCurrentPosition().

◆ operator=() [1/2]

template<class Type_ >
List1D & STK::List1D< Type_ >::operator= ( const List1D< Type_ > &  T)
inline

operator = : overwrite the List1D with T.

We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.

Parameters
Tthe container to copy

Definition at line 549 of file STK_List1D.h.

550 {
551 // We have to resize if this and T have not the same size
552 // but if they have the same size, we don't scale the index
553 if (size()!=T.size()) { this->resize(T.range());}
554
555 /* copy without ovelapping. */
556 if (begin() < T.begin())
557 { Cell *p1 = p_begin_, *pt1 = T.p_begin_;
558 for (int j=1; j<=size(); j++)
559 { (*p1) = pt1->data(); // overwrite the value
560 p1 = p1->getRight(); // Goto Right for this
561 pt1 = pt1->getRight(); // Goto Right for T
562 }
563 }
564 else
565 { Cell *p1 = p_last_, *pt1 = T.p_last_;
566 for (int j=size(); j>=1; j--)
567 { (*p1) = pt1->data(); // overwrite the value
568 p1 = p1->getLeft(); // Goto Left for this
569 pt1 = pt1->getLeft(); // Goto Left for T
570 }
571 }
572 return *this;
573 }
List1D< Type_ > & resize(Range const &I=RowRange())

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_last_, STK::ITContainer1D< Derived >::range(), STK::ITContainer1D< List1D< Type_ > >::resize(), and STK::List1D< Type_ >::size().

◆ operator=() [2/2]

template<class Type_ >
List1D< Type > & STK::List1D< Type_ >::operator= ( Type const v)
inline

operator= : set the container to a constant value.

Parameters
vthe value to set

Definition at line 598 of file STK_List1D.h.

599 {
600 Cell* p1 = p_begin_;
601 for (int j=1; j<=size(); j++)
602 { p1->setData(v); // overwrite the value of the current cell
603 p1 = p1->getRight(); // Goto Right
604 }
605 return *this;
606 }
virtual void setData(YArray_ const &y, XArray_ const &x)
set the data set.

References STK::List1D< Type_ >::p_begin_, STK::IRunnerSupervised< YArray_, XArray_, Weights_ >::setData(), and STK::List1D< Type_ >::size().

◆ p_begin()

template<class Type_ >
Cell const *const STK::List1D< Type_ >::p_begin ( ) const
inline
Returns
the pointer on the first cell of the list

Definition at line 260 of file STK_List1D.h.

260{ return p_begin_;}

References STK::List1D< Type_ >::p_begin_.

◆ p_lastIdx()

template<class Type_ >
Cell const *const STK::List1D< Type_ >::p_lastIdx ( ) const
inline
Returns
the pointer on the last cell of the list

Definition at line 262 of file STK_List1D.h.

262{ return p_last_;}

References STK::List1D< Type_ >::p_last_.

◆ popBack()

template<class Type_ >
void STK::List1D< Type_ >::popBack ( int const n = 1)
inline

Delete n last elements of the container.

Parameters
nnumber of elts to delete

Definition at line 458 of file STK_List1D.h.

459 {
460 // if n<=0 nothing to do
461 if (n <= 0) return;
462 // is this structure just a pointer?
463 if (this->isRef())
464 { STKRUNTIME_ERROR_1ARG(List1D::popBack,n,cannot operate on references.);}
465 // if there is elts to erase
466 if (size()<n)
468 // erase elts with pos = end -n +1
469 erase(this->lastIdx() - n +1, n);
470 }
void popBack(int const &n=1)
Delete n last elements of the container.
Definition STK_List1D.h:458

References STK::List1D< Type_ >::erase(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::popBack(), STK::List1D< Type_ >::size(), STKOUT_OF_RANGE_1ARG, and STKRUNTIME_ERROR_1ARG.

Referenced by STK::List1D< Type_ >::popBack(), and STK::List1D< Type_ >::resizeImpl().

◆ pushBack()

template<class Type_ >
void STK::List1D< Type_ >::pushBack ( int const n = 1)
inline

Add n Elts to the container.

Parameters
nnumber of elements to add

Definition at line 323 of file STK_List1D.h.

324 {
325 // if n==0 nothing to do
326 if (n <= 0) return;
327 // is this structure just a pointer?
328 if (this->isRef())
329 { STKRUNTIME_ERROR_1ARG(List1D::pushBack,n,cannot operate on references.);}
330 // If the container is empty : create it
331 if (this->empty())
332 { initialize(Range(begin(), n));}
333 else // else adjust the beginning and the sizes
334 {
335 Cell *p1, *p2; // Auxiliary cells;
336 try
337 { p1 = new Cell(p_last_);} // Create the end+1 cell
338 catch (std::bad_alloc & error)
339 { STKRUNTIME_ERROR_1ARG(List1D::pushBack,n,memory allocation failed);}
340 // if no error is intercepted
341 p_last_->setRight(p1); // Set the right ending cell
342 for (int j=2; j<=n; j++) // main loop for the other cells
343 { try
344 { p2 = new Cell(p1);} // try to allocate memory
345 catch (std::bad_alloc & error) // if an alloc error occur
346 {
347 while ( p1 != p_last_) // for all cells allocated
348 { p2 = p1->getLeft(); // get the cell left
349 delete p1; // delete the curent cell
350 p1 = p2; // iterate
351 }
352 // set the original right side of cend
353 p_last_->setRight(p_begin_);
354 STKRUNTIME_ERROR_1ARG(List1D::pushBack,n,memory allocation failed);
355 } // end catch
356 // if no error
357 p1->setRight(p2); // Set the right cell of the current cell
358 p1 = p2; // Set the current cell to the the next cell
359 }
360 p1->setRight(p_begin_); // the last cell point on the first cell
361 p_begin_->setLeft(p1); // the first cell point on the last cell
362 p_last_ = p1; // the last cell adress
363 this->incLast(n); // Update size of the container
364 }
365 }
void pushBack(int const &n=1)
Add n Elts to the container.
Definition STK_List1D.h:323

References STK::List1D< Type_ >::begin(), STK::ITContainer1D< List1D< Type_ > >::empty(), STK::ITContainer1D< List1D< Type_ > >::incLast(), STK::List1D< Type_ >::initialize(), STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::p_begin_, STK::List1D< Type_ >::p_last_, STK::List1D< Type_ >::pushBack(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::List1D< Type_ >::pushBack(), and STK::List1D< Type_ >::resizeImpl().

◆ resizeImpl()

template<class Type_ >
List1D< Type > & STK::List1D< Type_ >::resizeImpl ( Range const I)
inline

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 List1D

Definition at line 580 of file STK_List1D.h.

581 {
582 // check if there is something to do
583 if ( this->range() == I) return *this;
584 if (this->isRef())
585 { STKRUNTIME_ERROR_1ARG(List1D::resizeImpl,I,cannot operate on references);}
586 // translate beg
587 shiftImpl(I.begin());
588 // compute number of elements to delete or add
589 const int inc = I.lastIdx() - this->lastIdx();
590 // adjust size of the container
591 if (inc > 0) this->pushBack(inc); // more elements
592 else this->popBack(-inc); // less elements
593 return *this;
594 }
void shiftImpl(int const &beg)
New first index for the object.
Definition STK_List1D.h:300
List1D< Type > & resizeImpl(Range const &I)
Resize the container.
Definition STK_List1D.h:580

References STK::TRef<-1 >::isRef(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::popBack(), STK::List1D< Type_ >::pushBack(), STK::ITContainer1D< List1D< Type_ > >::range(), STK::List1D< Type_ >::resizeImpl(), STK::List1D< Type_ >::shiftImpl(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::List1D< Type_ >::resizeImpl().

◆ rows()

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

Definition at line 216 of file STK_List1D.h.

216{ return this->range();}

References STK::ITContainer1D< List1D< Type_ > >::range().

◆ setDefault()

◆ shiftImpl()

template<class Type_ >
void STK::List1D< Type_ >::shiftImpl ( int const beg)
inline

New first index for the object.

Parameters
begnew first index of the Container.

Definition at line 300 of file STK_List1D.h.

301 {
302 if (begin() == beg) return;
303 // is this structure just a pointer?
304 if (this->isRef())
305 { STKRUNTIME_ERROR_1ARG(List1D::shift,beg,cannot operate on references);}
306 //compute increment
307 int inc = beg - begin();
308 this->incRange(inc); // update this->range_()
309 currentPosition_ += inc; // update current position
310 }
void incRange(int n=1)
increment the range of the container (can be negative).

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::currentPosition_, STK::ITContainer1D< List1D< Type_ > >::incRange(), STK::TRef<-1 >::isRef(), STK::ITContainer1D< List1D< Type_ > >::shift(), and STKRUNTIME_ERROR_1ARG.

Referenced by STK::List1D< Type_ >::resizeImpl().

◆ size()

template<class Type_ >
int STK::ITContainer1D< Derived >::size ( ) const
inline

◆ sizeCols()

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

Definition at line 231 of file STK_List1D.h.

231{ return 1;};

◆ sizeRows()

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

Definition at line 222 of file STK_List1D.h.

222{ return size();}

References STK::List1D< Type_ >::size().

◆ subImpl()

template<class Type_ >
List1D STK::List1D< Type_ >::subImpl ( Range const J) const
inline

access to many elements.

Parameters
Jthe range of the elements
Returns
a list with a reference to the elements in the given range

Definition at line 285 of file STK_List1D.h.

286 {
287 if ((J.begin()<begin()))
289 if ((J.lastIdx()>this->lastIdx()))
291 moveCurrentPosition(J.begin());
292 Cell* p_first = p_current_;
293 moveCurrentPosition(J.lastIdx());
294 Cell* p_last = p_current_;
295 return List1D(p_first, p_last, J);
296 }
List1D subImpl(Range const &J) const
access to many elements.
Definition STK_List1D.h:285

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::List1D(), STK::List1D< Type_ >::moveCurrentPosition(), STK::List1D< Type_ >::p_current_, STKOUT_OF_RANGE_1ARG, and STK::List1D< Type_ >::subImpl().

Referenced by STK::List1D< Type_ >::subImpl().

◆ swap()

template<class Type_ >
void STK::List1D< Type_ >::swap ( int const j1,
int const j2 
)
inline

Swapping the j1th column and the j2th column.

Parameters
j1index of the first element to swap
j2index of the second element to swap

Definition at line 521 of file STK_List1D.h.

522 {
523#ifdef STK_BOUNDS_CHECK
524 if (j1<begin())
526 if (j1>this->lastIdx())
528 if (j2<begin())
530 if (j2>this->lastIdx())
532#endif
533 // get j1th value in aux
535 Cell *p1 = p_current_;
536 Type aux = p1->data();
537 // set j2th value in j1th position
539 (*p1) = p_current_->data();
540 // set j2th value to aux
541 (*p_current_) = aux;
542 }
hidden::Traits< List1D< Type_ > >::Type Type
Definition STK_List1D.h:115
void swap(int const &j1, int const &j2)
Swapping the j1th column and the j2th column.
Definition STK_List1D.h:521

References STK::List1D< Type_ >::begin(), STK::List1D< Type_ >::lastIdx(), STK::List1D< Type_ >::moveCurrentPosition(), STK::List1D< Type_ >::p_current_, STKOUT_OF_RANGE_2ARG, and STK::List1D< Type_ >::swap().

Referenced by STK::List1D< Type_ >::swap().

Member Data Documentation

◆ currentPosition_

◆ p_begin_

◆ p_current_

◆ p_last_


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