STK++ 0.9.13
STK::TRange< UnknownSize > Class Reference

Index sub-vector region: Specialization when the size is unknown. More...

#include <STK_Range.h>

Inheritance diagram for STK::TRange< UnknownSize >:
Inheritance graph

Public Types

typedef RangeBase< TRange< UnknownSize > > Base
 

Public Member Functions

 TRange (int size=0)
 constructor.
 
 TRange (int first, int size)
 Complete constructor.
 
 TRange (int first, int last, bool junk)
 Complete constructor.
 
 TRange (TRange const &I)
 Copy constructor.
 
template<int OtherSize_>
 TRange (TRange< OtherSize_ > const &I)
 Copy constructor.
 
 ~TRange ()
 destructor.
 
int end () const
 get the ending index of the TRange.
 
int size () const
 get the size of the TRange (the number of elements).
 
bool empty () const
 check if the range is empty or not.
 
int lastIdx () const
 get the last index of the TRange.
 
TRangeshift (int first)
 Shift the TRange giving the first element: the size is not modified.
 
TRangeinc (int inc=1)
 create the TRange [begin_+inc, end_+inc_).
 
TRangedec (int dec=1)
 create the TRange [begin_+inc, end_).
 
TRangeincFirst (int inc=1)
 create the TRange [begin_-dec, end_-dec)
 
TRangedecFirst (int dec=1)
 create the TRange [begin_-dec, end_)
 
TRangeincEnd (int inc=1)
 create the TRange [begin_, end_+inc)
 
TRangedecEnd (int dec=1)
 create the TRange [begin_, end_-dec)
 
TRangeincLast (int inc=1)
 create the TRange [begin_, end_+inc)
 
TRangedecLast (int dec=1)
 create the TRange [begin_, end_-dec)
 
template<int OtherSize_>
TRangesup (TRange< OtherSize_ > const &I)
 Take the lowest value of begin_ and I.begin_ for begin_ and the largest value of end_ and I.end_ for end_.
 
template<int OtherSize_>
TRangeinf (TRange< OtherSize_ > const &I)
 Take the largest value of begin_ and I.begin_ for begin_ and the lowest value of end_ and I.end_ for end_.
 
- Public Member Functions inherited from STK::RangeBase< TRange< UnknownSize > >
 ~RangeBase ()
 destructor.
 
int begin () const
 get the first index of the TRange.
 
bool isIn (TRange< OtherSize_ > const &I) const
 check if this TRange in include in an other TRange
 
bool isContaining (TRange< OtherSize_ > const &I) const
 check if the TRange I is include in the this TRange
 
bool isContaining (int i) const
 Return true if i is in this TRange.
 
TRange< UnknownSize > & operator+= (int i)
 shift range a:b becomes (a+i):(b+i)
 
TRange< UnknownSize > & operator-= (int i)
 shift range a:b becomes (a+i):(b+i)
 
bool operator== (TRange< OtherSize_ > const &I) const
 compare this range with range I
 
bool operator!= (TRange< OtherSize_ > const &I) const
 compare this range with range I
 
- 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.
 

Private Attributes

int size_
 theoretic Dimension size_ = end_- begin_
 

Friends

istreamoperator>> (istream &is, Range &I)
 Read a Range in the form first:last (MATLAB-like form) from an input stream.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::RangeBase< TRange< UnknownSize > >
 RangeBase ()
 Default constructor.
 
 RangeBase (int begin)
 constructor.
 
 RangeBase (RangeBase const &I)
 Copy constructor.
 
 RangeBase (RangeBase< OtherDerived > const &I)
 Copy constructor.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 
- Protected Attributes inherited from STK::RangeBase< TRange< UnknownSize > >
int begin_
 First index.
 

Detailed Description

Index sub-vector region: Specialization when the size is unknown.

A Range is an ordered pair [first,last] denoting a sub-vector region, similar to a Fortran 90 or Matlab colon notation. For example :

Vector A(10), B(Range(0,20));
Range I(2,4, false);
A(I) = B(Range(0,2, false));
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
TRange< UnknownSize > Range
Definition STK_Range.h:59

overwrite the elements (2, 3, 4) of A by the elements (0, 1, 2) of B. There is no stride argument, only contiguous regions are allowed.

Definition at line 264 of file STK_Range.h.

Member Typedef Documentation

◆ Base

Definition at line 267 of file STK_Range.h.

Constructor & Destructor Documentation

◆ TRange() [1/5]

STK::TRange< UnknownSize >::TRange ( int  size = 0)
inline

constructor.

By default the first index is defined by the firstIdx macro.

Parameters
sizesize of the sub-region

Definition at line 273 of file STK_Range.h.

273: Base(), size_(size) {}
RangeBase< TRange< UnknownSize > > Base
Definition STK_Range.h:267
int size_
theoretic Dimension size_ = end_- begin_
Definition STK_Range.h:389
int size() const
get the size of the TRange (the number of elements).
Definition STK_Range.h:303

◆ TRange() [2/5]

STK::TRange< UnknownSize >::TRange ( int  first,
int  size 
)
inline

Complete constructor.

Give the beginning and the size of the sub-region.

Parameters
first,sizebeginning and size of the range

Definition at line 277 of file STK_Range.h.

277: Base(first), size_(size) {}

◆ TRange() [3/5]

STK::TRange< UnknownSize >::TRange ( int  first,
int  last,
bool  junk 
)
inline

Complete constructor.

Give the first and last index of the sub-region.

Parameters
first,lastfirst and last indexes of the sub-region
junkallow to use the constructor (begin:last) rather than (begin,size)

Definition at line 282 of file STK_Range.h.

282: Base(first), size_(last+1-first) {}

◆ TRange() [4/5]

STK::TRange< UnknownSize >::TRange ( TRange< UnknownSize > const I)
inline

Copy constructor.

Create a copy of an existing TRange.

Parameters
Irange to copy

Definition at line 287 of file STK_Range.h.

287: Base(I), size_(I.size_) {}

◆ TRange() [5/5]

template<int OtherSize_>
STK::TRange< UnknownSize >::TRange ( TRange< OtherSize_ > const I)
inline

Copy constructor.

Create a copy of an existing TRange.

Parameters
Irange to copy

Definition at line 293 of file STK_Range.h.

293: Base(I), size_(I.size()) {}

◆ ~TRange()

STK::TRange< UnknownSize >::~TRange ( )
inline

destructor.

Definition at line 295 of file STK_Range.h.

295{}

Member Function Documentation

◆ dec()

TRange & STK::TRange< UnknownSize >::dec ( int  dec = 1)
inline

create the TRange [begin_+inc, end_).

Parameters
decthe decrement to apply

Definition at line 325 of file STK_Range.h.

325{ begin_ -=dec; return *this;}
TRange & dec(int dec=1)
create the TRange [begin_+inc, end_).
Definition STK_Range.h:325

References STK::RangeBase< TRange< Size_ > >::begin_, and dec().

Referenced by dec().

◆ decEnd()

TRange & STK::TRange< UnknownSize >::decEnd ( int  dec = 1)
inline

create the TRange [begin_, end_-dec)

Parameters
decthe decrement to apply

Definition at line 343 of file STK_Range.h.

343{ size_ -=dec; return *this;}

References STK::TRange< Size_ >::dec().

◆ decFirst()

TRange & STK::TRange< UnknownSize >::decFirst ( int  dec = 1)
inline

create the TRange [begin_-dec, end_)

Parameters
decthe decrement to apply

Definition at line 334 of file STK_Range.h.

334{ begin_ -=dec; size_ +=dec; return *this;}

References STK::RangeBase< TRange< Size_ > >::begin_, and STK::TRange< Size_ >::dec().

◆ decLast()

TRange & STK::TRange< UnknownSize >::decLast ( int  dec = 1)
inline

create the TRange [begin_, end_-dec)

Parameters
decthe decrement to apply

Definition at line 353 of file STK_Range.h.

353{ size_ -=dec; return *this;}

References STK::TRange< Size_ >::dec().

◆ empty()

bool STK::TRange< UnknownSize >::empty ( ) const
inline

check if the range is empty or not.

Returns
true if size <=0, false otherwise

Definition at line 307 of file STK_Range.h.

307{ return size_<=0;}

◆ end()

◆ inc()

TRange & STK::TRange< UnknownSize >::inc ( int  inc = 1)
inline

create the TRange [begin_+inc, end_+inc_).

Parameters
incthe increment to apply

Definition at line 321 of file STK_Range.h.

321{ begin_ +=inc; return *this;}
TRange & inc(int inc=1)
create the TRange [begin_+inc, end_+inc_).
Definition STK_Range.h:321

References STK::RangeBase< TRange< Size_ > >::begin_, and inc().

Referenced by inc().

◆ incEnd()

TRange & STK::TRange< UnknownSize >::incEnd ( int  inc = 1)
inline

create the TRange [begin_, end_+inc)

Parameters
incthe increment to apply

Definition at line 339 of file STK_Range.h.

339{ size_ +=inc; return *this;}

References STK::TRange< Size_ >::inc().

◆ incFirst()

TRange & STK::TRange< UnknownSize >::incFirst ( int  inc = 1)
inline

create the TRange [begin_-dec, end_-dec)

Parameters
incthe increment to apply to begin_

Definition at line 330 of file STK_Range.h.

330{ begin_ +=inc; size_ -=inc; return *this;}

References STK::RangeBase< TRange< Size_ > >::begin_, and STK::TRange< Size_ >::inc().

◆ incLast()

TRange & STK::TRange< UnknownSize >::incLast ( int  inc = 1)
inline

create the TRange [begin_, end_+inc)

Parameters
incthe increment to apply

Definition at line 349 of file STK_Range.h.

349{ size_ +=inc; return *this;}

References STK::TRange< Size_ >::inc().

Referenced by STK::IArray2D< Derived >::merge(), and STK::List1D< Type_ >::merge().

◆ inf()

template<int OtherSize_>
TRange & STK::TRange< UnknownSize >::inf ( TRange< OtherSize_ > const I)
inline

Take the largest value of begin_ and I.begin_ for begin_ and the lowest value of end_ and I.end_ for end_.

Parameters
Ithe index to apply

Definition at line 371 of file STK_Range.h.

372 {
373 begin_ = std::max(begin_, I.begin());
374 size_ = std::min(end(), I.end()) - begin_;
375 return *this;
376 }
int end() const
get the ending index of the TRange.
Definition STK_Range.h:299

References STK::RangeBase< TRange< Size_ > >::begin_, and STK::TRange< Size_ >::end().

◆ lastIdx()

int STK::TRange< UnknownSize >::lastIdx ( ) const
inline

get the last index of the TRange.

Returns
the last index of the range

Definition at line 313 of file STK_Range.h.

313{ return(end()-1);}

References STK::TRange< Size_ >::end().

Referenced by STK::MemSAllocator1D< Type_, NzMax_ >::memmove().

◆ shift()

TRange & STK::TRange< UnknownSize >::shift ( int  first)
inline

Shift the TRange giving the first element: the size is not modified.

Parameters
firstnew value of the first element.

Definition at line 317 of file STK_Range.h.

317{ return inc(first - begin_);}

References STK::RangeBase< TRange< Size_ > >::begin_, and STK::TRange< Size_ >::inc().

◆ size()

◆ sup()

template<int OtherSize_>
TRange & STK::TRange< UnknownSize >::sup ( TRange< OtherSize_ > const I)
inline

Take the lowest value of begin_ and I.begin_ for begin_ and the largest value of end_ and I.end_ for end_.

Parameters
Ithe index to apply

Definition at line 360 of file STK_Range.h.

361 {
362 begin_ = std::min(begin_, I.begin());
363 size_ = std::max(end(), I.end()) - begin_;
364 return *this;
365 }

References STK::RangeBase< TRange< Size_ > >::begin_, and STK::TRange< Size_ >::end().

Friends And Related Symbol Documentation

◆ operator>>

istream & operator>> ( istream is,
Range I 
)
friend

Read a Range in the form first:last (MATLAB-like form) from an input stream.

The input stream can also be a number (say n). In this case the range will be n:n. If the range cannot be read the method return a NA value

Parameters
isthe input stream
Ithe range to set
Returns
is stream

Definition at line 431 of file STK_Range.h.

432{
433 String str;
434 std::getline(is, str, _T(':'));
435 // get first number
436 if (!stringToType(I.begin_, str))
437 {
439 is.clear(); is.setstate(std::ios::failbit);
440 return is;
441 }
442 // check if the istream is exhausted
443 if (is.eof())
444 {
445 I.size_ = 1;
446 return is;
447 }
448 // skip the current char ":"
449 is.peek();
450 // get second number
451 if ((is >> I.size_).fail())
452 {
454 is.clear(); is.setstate(std::ios::failbit);
455 return is;
456 }
457 else { I.size_ -= I.begin_ ;}
458 return is;
459}
#define _T(x)
Let x unmodified.
bool stringToType(Type &t, String const &s, std::ios_base &(*f)(std::ios_base &)=std::dec)
convert a String to Type
Definition STK_String.h:195
std::basic_string< Char > String
STK fundamental type of a String.
static Type NA()
Adding a Non Available (NA) special number.

Member Data Documentation

◆ size_

int STK::TRange< UnknownSize >::size_
private

theoretic Dimension size_ = end_- begin_

Definition at line 389 of file STK_Range.h.


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