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

Interface base class for 2D containers. More...

#include <STK_ITContainer.h>

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

Public Types

enum  {
  structure_ = hidden::Traits<Derived>::structure_ , orient_ = hidden::Traits<Derived>::orient_ , sizeRows_ = hidden::Traits<Derived>::sizeRows_ , sizeCols_ = hidden::Traits<Derived>::sizeCols_ ,
  storage_ = hidden::Traits<Derived>::storage_
}
 
typedef IRecursiveTemplate< Derived > Base
 
typedef hidden::Traits< Derived >::Type Type
 
typedef hidden::Traits< Derived >::TypeConst TypeConst
 
typedef TRange< sizeRows_RowRange
 Type of the Range for the rows.
 
typedef TRange< sizeCols_ColRange
 Type of the Range for the columns.
 

Public Member Functions

ColRange constcols () const
 
int beginCols () const
 
int endCols () const
 
int sizeCols () const
 
RowRange constrows () const
 
int beginRows () const
 
int endRows () const
 
int sizeRows () const
 
int firstIdxCols () const
 
int firstIdxRows () const
 
int lastIdxCols () const
 
int lastIdxRows () const
 
RowRange constrangeRowsInCol (int) const
 
ColRange constrangeColsInRow (int) const
 
bool empty () const
 
int size () const
 
TypeConst elt (int i, int j) const
 
TypeConst elt (int i) const
 
TypeConst elt () const
 
Typeelt (int i, int j)
 
Typeelt (int i)
 
Typeelt ()
 
TypeConst at (int i, int j) const
 
TypeConst at (int i) const
 
Typeat (int i, int j)
 
Typeat (int i)
 
TypeConst operator() (int i, int j) const
 
Typeoperator() (int i, int j)
 
TypeConst operator[] (int i) const
 
Typeoperator[] (int i)
 
TypeConst operator() () const
 
Typeoperator() ()
 
- 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

 ITContainerBase ()
 Default constructor.
 
 ~ITContainerBase ()
 destructor.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Detailed Description

template<class Derived>
class STK::ITContainerBase< Derived >

Interface base class for 2D containers.

Use the curious recursive template paradigm : the template parameter Derived is the name of the class that implements the interface ITContainer. For example

template<class Type>
class Derived: public ITContainer< Derived<Type> >
{...}
Specialized interface class for all arrays (can be either 2D arrays or 1D arrays).

The ITContainerBase class is the base class for all two-dimensional containers. A two-dimensional container is defined by an horizontal range of index for the columns and a vertical range of index for the rows.

The pseudo virtual function defined in this interface and to implement in the derived classes have the following definitions for the dimensions:

ColRange const& colsImpl() const;
RowRange const& rowsImpl() const;

and for the accessors the following definitions:

Type elt2Impl( int i, int j) const;
Type& elt2Impl( int i, int j);
hidden::Traits< Derived >::Type Type
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...

for all kind of arrays.

For the diagonal arrays, vectors and points (row-vectors) the following accessors have to be implemented

Type elt1Impl( int i) const; // when return by reference is not possible
Type& elt1Impl( int i);
Type const& elt1Impl( int i) const;

Finaly the following accesors have to be implemented for number-like arrays

Type elt0Impl() const; // when return by reference is not possible
Type& elt0Impl();
Type const& elt0Impl() const;

Definition at line 104 of file STK_ITContainer.h.

Member Typedef Documentation

◆ Base

template<class Derived >
typedef IRecursiveTemplate<Derived> STK::ITContainerBase< Derived >::Base

Definition at line 107 of file STK_ITContainer.h.

◆ ColRange

template<class Derived >
typedef TRange<sizeCols_> STK::ITContainerBase< Derived >::ColRange

Type of the Range for the columns.

Definition at line 121 of file STK_ITContainer.h.

◆ RowRange

template<class Derived >
typedef TRange<sizeRows_> STK::ITContainerBase< Derived >::RowRange

Type of the Range for the rows.

Definition at line 119 of file STK_ITContainer.h.

◆ Type

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

Definition at line 108 of file STK_ITContainer.h.

◆ TypeConst

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

Definition at line 109 of file STK_ITContainer.h.

Member Enumeration Documentation

◆ anonymous enum

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

Definition at line 110 of file STK_ITContainer.h.

111 {
112 structure_ = hidden::Traits<Derived>::structure_,
113 orient_ = hidden::Traits<Derived>::orient_,
114 sizeRows_ = hidden::Traits<Derived>::sizeRows_,
115 sizeCols_ = hidden::Traits<Derived>::sizeCols_,
116 storage_ = hidden::Traits<Derived>::storage_
117 };

Constructor & Destructor Documentation

◆ ITContainerBase()

template<class Derived >
STK::ITContainerBase< Derived >::ITContainerBase ( )
inlineprotected

Default constructor.

Definition at line 125 of file STK_ITContainer.h.

125: Base() {}
IRecursiveTemplate< Derived > Base

◆ ~ITContainerBase()

template<class Derived >
STK::ITContainerBase< Derived >::~ITContainerBase ( )
inlineprotected

destructor.

Definition at line 127 of file STK_ITContainer.h.

127{}

Member Function Documentation

◆ at() [1/4]

template<class Derived >
Type & STK::ITContainerBase< Derived >::at ( int  i)
inline
Returns
safely a reference on the element (i)
Note
this method is only valid for arrays as it allow to modify an element.
Parameters
iindex of the element

Definition at line 264 of file STK_ITContainer.h.

265 {
267 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::at, i, begin() > i);}
268 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::at, i, end() <= i);}
269 return this->asDerived().elt1Impl(i);
270 }
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93
#define STK_STATIC_ASSERT_ONE_DIMENSION_ONLY(EXPR)
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.
TypeConst at(int i, int j) const

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::at(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ at() [2/4]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::at ( int  i) const
inline
Returns
safely the constant ith element
Parameters
iindex of the element

Definition at line 241 of file STK_ITContainer.h.

242 {
244 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::at, i, begin() > i);}
245 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::at, i, end() <= i);}
246 return this->asDerived().elt1Impl(i);
247 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::at(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ at() [3/4]

template<class Derived >
Type & STK::ITContainerBase< Derived >::at ( int  i,
int  j 
)
inline
Returns
safely a reference on the element (i, j)
Note
this method is only valid for arrays as it allow to modify an element.
Parameters
i,jrow and column indexes

Definition at line 252 of file STK_ITContainer.h.

253 {
254 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(ITContainerBase::at, i, j, beginRows() > i);}
255 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(ITContainerBase::at, i, j, endRows() <= i);}
256 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(ITContainerBase::at, i, j, beginCols() > j);}
257 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(ITContainerBase::at, i, j, endCols() <= j);}
258 return this->asDerived().elt2Impl(i,j);
259 }
#define STKOUT_OF_RANGE_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:102

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::at(), STK::ITContainerBase< Derived >::beginCols(), STK::ITContainerBase< Derived >::beginRows(), STK::ITContainerBase< Derived >::endCols(), STK::ITContainerBase< Derived >::endRows(), and STKOUT_OF_RANGE_2ARG.

◆ at() [4/4]

◆ beginCols()

◆ beginRows()

◆ cols()

◆ elt() [1/6]

template<class Derived >
Type & STK::ITContainerBase< Derived >::elt ( )
inline
Returns
a value on the number

Definition at line 225 of file STK_ITContainer.h.

225{ return this->asDerived().elt0Impl();}

References STK::IRecursiveTemplate< Derived >::asDerived().

◆ elt() [2/6]

◆ elt() [3/6]

template<class Derived >
Type & STK::ITContainerBase< Derived >::elt ( int  i)
inline

Definition at line 215 of file STK_ITContainer.h.

216 {
218#ifdef STK_BOUNDS_CHECK
219 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::elt, i, begin() > i);}
220 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::elt, i, end() <= i);}
221#endif
222 return this->asDerived().elt1Impl(i);
223 }
TypeConst elt() const

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::elt(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ elt() [4/6]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::elt ( int  i) const
inline
Returns
the constant ith element
Parameters
iindex of the element to get

Definition at line 190 of file STK_ITContainer.h.

191 {
193#ifdef STK_BOUNDS_CHECK
194 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::elt, i, begin() > i);}
195 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainerBase::elt, i, end() <= i);}
196#endif
197return this->asDerived().elt1Impl(i);
198 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::elt(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ elt() [5/6]

template<class Derived >
Type & STK::ITContainerBase< Derived >::elt ( int  i,
int  j 
)
inline
Returns
a reference on element (i,j) of the 2D container
Parameters
i,jrow and column indexes

Definition at line 205 of file STK_ITContainer.h.

206 {
207#ifdef STK_BOUNDS_CHECK
208 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(ITContainer::elt, i, j, beginRows() > i);}
209 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(ITContainer::elt, i, j, endRows() <= i);}
210 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(ITContainer::elt, i, j, beginCols() > j);}
211 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(ITContainer::elt, i, j, endCols() <= j);}
212#endif
213 return this->asDerived().elt2Impl(i,j);
214 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::beginCols(), STK::ITContainerBase< Derived >::beginRows(), STK::ITContainerBase< Derived >::endCols(), STK::ITContainerBase< Derived >::endRows(), and STKOUT_OF_RANGE_2ARG.

◆ elt() [6/6]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::elt ( int  i,
int  j 
) const
inline
Returns
a constant reference on element (i,j) of the 2D container
Parameters
i,jrow and column indexes

Definition at line 177 of file STK_ITContainer.h.

178 {
179#ifdef STK_BOUNDS_CHECK
181 if (endRows() <= i) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, endRows() <= i);}
183 if (endCols() <= j) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, endCols() <= j);}
184#endif
185 return this->asDerived().elt2Impl(i,j);
186 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::beginCols(), STK::ITContainerBase< Derived >::beginRows(), STK::ITContainerBase< Derived >::elt(), STK::ITContainerBase< Derived >::endCols(), STK::ITContainerBase< Derived >::endRows(), and STKOUT_OF_RANGE_2ARG.

◆ empty()

template<class Derived >
bool STK::ITContainerBase< Derived >::empty ( ) const
inline
Returns
true if the container is empty, false otherwise

Definition at line 168 of file STK_ITContainer.h.

168{ return (sizeCols()<=0 || sizeRows()<=0);}

References STK::ITContainerBase< Derived >::sizeCols(), and STK::ITContainerBase< Derived >::sizeRows().

◆ endCols()

◆ endRows()

◆ firstIdxCols()

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

Definition at line 150 of file STK_ITContainer.h.

150{ return beginCols();}

References STK::ITContainerBase< Derived >::beginCols().

◆ firstIdxRows()

template<class Derived >
int STK::ITContainerBase< Derived >::firstIdxRows ( ) const
inline
Returns
the index of the first row

Definition at line 152 of file STK_ITContainer.h.

152{ return beginRows();}

References STK::ITContainerBase< Derived >::beginRows().

◆ lastIdxCols()

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

Definition at line 154 of file STK_ITContainer.h.

154{ return endCols()-1;}

References STK::ITContainerBase< Derived >::endCols().

◆ lastIdxRows()

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

Definition at line 156 of file STK_ITContainer.h.

156{ return endRows()-1;}

References STK::ITContainerBase< Derived >::endRows().

◆ operator()() [1/4]

template<class Derived >
Type & STK::ITContainerBase< Derived >::operator() ( )
inline
Returns
reference on the number

Definition at line 329 of file STK_ITContainer.h.

330 {
332 return this->elt();
333 }
#define STK_STATIC_ASSERT_ZERO_DIMENSION_ONLY(EXPR)

References STK::ITContainerBase< Derived >::elt(), and STK_STATIC_ASSERT_ZERO_DIMENSION_ONLY.

◆ operator()() [2/4]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::operator() ( ) const
inline
Returns
reference on the number

Definition at line 323 of file STK_ITContainer.h.

324 {
326 return this->elt();
327 }

References STK::ITContainerBase< Derived >::elt(), and STK_STATIC_ASSERT_ZERO_DIMENSION_ONLY.

◆ operator()() [3/4]

template<class Derived >
Type & STK::ITContainerBase< Derived >::operator() ( int  i,
int  j 
)
inline
Returns
value of the element (i,j) of the 2D container.
Parameters
i,jrow and column indexes

Definition at line 288 of file STK_ITContainer.h.

289 {
290 #ifdef STK_BOUNDS_CHECK
291 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(ITContainer::operator(), i, j, beginRows() > i);}
292 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(ITContainer::operator(), i, j, endRows() <= i);}
293 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(ITContainer::operator(), i, j, beginCols() > j);}
294 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(ITContainer::eoperator()lt, i, j, endCols() <= j);}
295 #endif
296 return this->asDerived().elt2Impl(i,j);
297 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::beginCols(), STK::ITContainerBase< Derived >::beginRows(), STK::ITContainerBase< Derived >::endCols(), STK::ITContainerBase< Derived >::endRows(), and STKOUT_OF_RANGE_2ARG.

◆ operator()() [4/4]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::operator() ( int  i,
int  j 
) const
inline
Returns
safely a constant value of the element (i,j) of the 2D container.
Parameters
i,jrow and column indexes

Definition at line 275 of file STK_ITContainer.h.

276 {
277#ifdef STK_BOUNDS_CHECK
278 if (this->beginRows() > i) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, beginRows() > i);}
279 if (this->endRows() <= i) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, endRows() <= i);}
280 if (this->beginCols() > j) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, beginCols() > j);}
281 if (this->endCols() <= j) { STKOUT_OF_RANGE_2ARG(ITContainerBase::elt, i, j, endCols() <= j);}
282#endif
283 return this->elt(i,j);
284 }

References STK::ITContainerBase< Derived >::beginCols(), STK::ITContainerBase< Derived >::beginRows(), STK::ITContainerBase< Derived >::elt(), STK::ITContainerBase< Derived >::endCols(), STK::ITContainerBase< Derived >::endRows(), and STKOUT_OF_RANGE_2ARG.

◆ operator[]() [1/2]

template<class Derived >
Type & STK::ITContainerBase< Derived >::operator[] ( int  i)
inline
Returns
reference on the ith element
Parameters
iindex of the element to get

Definition at line 313 of file STK_ITContainer.h.

314 {
316#ifdef STK_BOUNDS_CHECK
317 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer::operator[], i, begin() > i);}
318 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer::operator[], i, end() <= i);}
319#endif
320 return this->elt(i);
321 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::elt(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ operator[]() [2/2]

template<class Derived >
TypeConst STK::ITContainerBase< Derived >::operator[] ( int  i) const
inline
Returns
reference on the ith element
Parameters
iindex of the element to get

Definition at line 301 of file STK_ITContainer.h.

302 {
304#ifdef STK_BOUNDS_CHECK
305 if (this->asDerived().begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer::operator[], i, begin() > i);}
306 if (this->asDerived().end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer::operator[], i, end() <= i);}
307#endif
308 return this->elt(i);
309 }

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ITContainerBase< Derived >::elt(), STK_STATIC_ASSERT_ONE_DIMENSION_ONLY, and STKOUT_OF_RANGE_1ARG.

◆ rangeColsInRow()

template<class Derived >
ColRange const & STK::ITContainerBase< Derived >::rangeColsInRow ( int  ) const
inline
Returns
the range of the effectively stored elements in the row. (default implementation)

Definition at line 165 of file STK_ITContainer.h.

165{ return cols();}

References STK::ITContainerBase< Derived >::cols().

◆ rangeRowsInCol()

template<class Derived >
RowRange const & STK::ITContainerBase< Derived >::rangeRowsInCol ( int  ) const
inline
Returns
the range of the effectively stored elements in the column. (default implementation)

Definition at line 161 of file STK_ITContainer.h.

161{ return rows();}

References STK::ITContainerBase< Derived >::rows().

◆ rows()

◆ size()

template<class Derived >
int STK::ITContainerBase< Derived >::size ( ) const
inline
Returns
the size of the container (the number of rows by the number of columns

Definition at line 171 of file STK_ITContainer.h.

171{ return sizeRows()*sizeCols();}

References STK::ITContainerBase< Derived >::sizeCols(), and STK::ITContainerBase< Derived >::sizeRows().

◆ sizeCols()

template<class Derived >
int STK::ITContainerBase< Derived >::sizeCols ( ) const
inline
Returns
the Horizontal size (the number of column)

Definition at line 137 of file STK_ITContainer.h.

137{ return cols().size();}
int size() const
get the size of the TRange (the number of elements).
Definition STK_Range.h:196

References STK::ITContainerBase< Derived >::cols(), and STK::TRange< Size_ >::size().

Referenced by STK::ITContainerBase< Derived >::empty(), and STK::ITContainerBase< Derived >::size().

◆ sizeRows()

template<class Derived >
int STK::ITContainerBase< Derived >::sizeRows ( ) const
inline
Returns
the Vertical size (the number of rows)

Definition at line 146 of file STK_ITContainer.h.

146{ return rows().size();}

References STK::ITContainerBase< Derived >::rows(), and STK::TRange< Size_ >::size().

Referenced by STK::ITContainerBase< Derived >::empty(), and STK::ITContainerBase< Derived >::size().


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