ant
A2 ant: class-based analysis framework
ant::interval< T > Class Template Reference

Interval class template. More...

#include <interval.h>

+ Inheritance diagram for ant::interval< T >:
+ Collaboration diagram for ant::interval< T >:

Public Member Functions

constexpr interval (const T &start, const T &stop) noexcept
 
constexpr const T & Start () const noexcept
 Get the lower boundary. More...
 
T & Start () noexcept
 Get the lower boundary. More...
 
constexpr const T & Stop () const noexcept
 Get the upper boundary. More...
 
T & Stop () noexcept
 Get the upper boundary. More...
 
constexpr T Length () const noexcept
 Get the length of the interval. More...
 
constexpr T Center () const noexcept
 Get the center. More...
 
interval< T > & operator+= (const T &a)
 Add a value to both boundaries. This shifts the interval to higher values. More...
 
interval< T > & operator-= (const T &a)
 Subtract a value to both boundaries. This shifts the interval to lower values. More...
 
interval< T > & operator*= (const T &f)
 Multiply both boundaries with a factor. This scales the interval (but also moves the center if center != 0) More...
 
interval< T > & operator/= (const T &f)
 Deivide both boundaries by a factor. This scales the interval (but also moves the center if center != 0) More...
 
interval< T > operator+ (const T &a) const
 Add a value to both boundaries and return the resulting interval (a new copy) The result is shifted to higher values (if a positive, of course). More...
 
interval< T > operator- (const T &a) const
 Subtract a value to both boundaries and return the resulting interval (a new copy) The result is shifted to lower values (if a positive, of course). More...
 
interval< T > operator* (const T &f) const
 Multiply both boundaries with a factor and return the resulting interval (a new copy). The result is scaled and the center is shifted if != 0. More...
 
interval< T > operator/ (const T &f) const
 Deivide both boundaries by a factor and return the resulting interval (a new copy). The result is scaled and the center is shifted if != 0. More...
 
operator[] (const index_t n) const
 operator []: Access boundaries array-style More...
 
constexpr bool operator== (const interval< T > &rhs) const noexcept
 
constexpr bool operator!= (const interval< T > &rhs) const noexcept
 
void SetWidth (const T &width)
 
void SetCenter (const T &center)
 
constexpr bool Contains (const T &x) const noexcept
 
constexpr bool Disjoint (const ant::interval< T > &i) const noexcept
 
void Extend (const interval< T > &other)
 Extend the interval if the given covers a larger range. More...
 
void Extend (const T &other)
 Extend the interval if the given covers a larger range. More...
 
bool tryJoinWith (const ant::interval< T > &other)
 Join another interval into this one if they overlap. More...
 
void MakeSane ()
 Make sure, start < stop. More...
 
constexpr bool IsSane () const noexcept
 
constexpr T Clip (const T &x) const
 Clip x to be inside the interval. More...
 
interval< T > & Round () noexcept
 Round boundaries to integer using std::round. More...
 
std::string AsRangeString (const std::string &label="x") const noexcept
 AsRangeString makes "mathematical" string expression of interval. More...
 

Static Public Member Functions

static constexpr interval CenterWidth (const T center, const T width) noexcept
 Factory Function: Create interval from center and width. More...
 
static constexpr interval getMaxRange () noexcept
 
static constexpr interval getMaxPositiveRange () noexcept
 
static constexpr interval getMaxNegativeRange () noexcept
 

Protected Attributes

_start
 
_stop
 

Friends

std::ostream & operator<< (std::ostream &stream, const interval< T > &i)
 
std::istream & operator>> (std::istream &out, interval< T > &t)
 

Detailed Description

template<class T>
class ant::interval< T >

Interval class template.

Constructor & Destructor Documentation

◆ interval()

template<class T>
constexpr ant::interval< T >::interval ( const T &  start,
const T &  stop 
)
inlinenoexcept

Member Function Documentation

◆ AsRangeString()

template<class T>
std::string ant::interval< T >::AsRangeString ( const std::string &  label = "x") const
inlinenoexcept

AsRangeString makes "mathematical" string expression of interval.

Parameters
labelthe label this interval applies to
Returns
the string
Note
it works well with _start, _stop being infinite/nan

◆ Center()

template<class T>
constexpr T ant::interval< T >::Center ( ) const
inlinenoexcept

Get the center.

Returns
center

◆ CenterWidth()

template<class T>
static constexpr interval ant::interval< T >::CenterWidth ( const T  center,
const T  width 
)
inlinestaticnoexcept

Factory Function: Create interval from center and width.

Parameters
centerthe center
widththe width
Returns
an interval that spans symmetrically around center with given width

◆ Clip()

template<class T>
constexpr T ant::interval< T >::Clip ( const T &  x) const
inline

Clip x to be inside the interval.

Parameters
x
Returns

◆ Contains()

template<class T>
constexpr bool ant::interval< T >::Contains ( const T &  x) const
inlinenoexcept

◆ Disjoint()

template<class T>
constexpr bool ant::interval< T >::Disjoint ( const ant::interval< T > &  i) const
inlinenoexcept

◆ Extend() [1/2]

template<class T>
void ant::interval< T >::Extend ( const interval< T > &  other)
inline

Extend the interval if the given covers a larger range.

Parameters
otheranother interval

◆ Extend() [2/2]

template<class T>
void ant::interval< T >::Extend ( const T &  other)
inline

Extend the interval if the given covers a larger range.

Parameters
otheranother interval

◆ getMaxNegativeRange()

template<class T>
static constexpr interval ant::interval< T >::getMaxNegativeRange ( )
inlinestaticnoexcept

◆ getMaxPositiveRange()

template<class T>
static constexpr interval ant::interval< T >::getMaxPositiveRange ( )
inlinestaticnoexcept

◆ getMaxRange()

template<class T>
static constexpr interval ant::interval< T >::getMaxRange ( )
inlinestaticnoexcept

◆ IsSane()

template<class T>
constexpr bool ant::interval< T >::IsSane ( ) const
inlinenoexcept

◆ Length()

template<class T>
constexpr T ant::interval< T >::Length ( ) const
inlinenoexcept

Get the length of the interval.

Returns
length

◆ MakeSane()

template<class T>
void ant::interval< T >::MakeSane ( )
inline

Make sure, start < stop.

This protected method is called whenever a write access to _start or _stop occurs.

◆ operator!=()

template<class T>
constexpr bool ant::interval< T >::operator!= ( const interval< T > &  rhs) const
inlinenoexcept

◆ operator*()

template<class T>
interval<T> ant::interval< T >::operator* ( const T &  f) const
inline

Multiply both boundaries with a factor and return the resulting interval (a new copy). The result is scaled and the center is shifted if != 0.

Parameters
fThe factor to multiply with
Returns
this * f

◆ operator*=()

template<class T>
interval<T>& ant::interval< T >::operator*= ( const T &  f)
inline

Multiply both boundaries with a factor. This scales the interval (but also moves the center if center != 0)

Parameters
fThe factor to multiply with
Returns
itself (Interval)

◆ operator+()

template<class T>
interval<T> ant::interval< T >::operator+ ( const T &  a) const
inline

Add a value to both boundaries and return the resulting interval (a new copy) The result is shifted to higher values (if a positive, of course).

Parameters
aThe value to add
Returns
this + a

◆ operator+=()

template<class T>
interval<T>& ant::interval< T >::operator+= ( const T &  a)
inline

Add a value to both boundaries. This shifts the interval to higher values.

Parameters
aThe value to add
Returns
itself (Interval)

◆ operator-()

template<class T>
interval<T> ant::interval< T >::operator- ( const T &  a) const
inline

Subtract a value to both boundaries and return the resulting interval (a new copy) The result is shifted to lower values (if a positive, of course).

Parameters
aThe value to subtract
Returns
this - a

◆ operator-=()

template<class T>
interval<T>& ant::interval< T >::operator-= ( const T &  a)
inline

Subtract a value to both boundaries. This shifts the interval to lower values.

Parameters
aThe value to subtract
Returns
itself (Interval)

◆ operator/()

template<class T>
interval<T> ant::interval< T >::operator/ ( const T &  f) const
inline

Deivide both boundaries by a factor and return the resulting interval (a new copy). The result is scaled and the center is shifted if != 0.

Parameters
fThe factor to divide by
Returns
itself (Interval)

◆ operator/=()

template<class T>
interval<T>& ant::interval< T >::operator/= ( const T &  f)
inline

Deivide both boundaries by a factor. This scales the interval (but also moves the center if center != 0)

Parameters
fThe factor to divide by
Returns
itself (Interval)

◆ operator==()

template<class T>
constexpr bool ant::interval< T >::operator== ( const interval< T > &  rhs) const
inlinenoexcept

◆ operator[]()

template<class T>
T ant::interval< T >::operator[] ( const index_t  n) const
inline

operator []: Access boundaries array-style

Parameters
n=0 -> lower, =1 -> upper
Returns
boundary n
Exceptions
std::out_of_rangeif index != {0,1}

◆ Round()

template<class T>
interval<T>& ant::interval< T >::Round ( )
inlinenoexcept

Round boundaries to integer using std::round.

Returns
reference to rounded instance
Note
interval may become not sane by this operation

◆ SetCenter()

template<class T>
void ant::interval< T >::SetCenter ( const T &  center)
inline

◆ SetWidth()

template<class T>
void ant::interval< T >::SetWidth ( const T &  width)
inline

◆ Start() [1/2]

template<class T>
constexpr const T& ant::interval< T >::Start ( ) const
inlinenoexcept

Get the lower boundary.

Returns
start position

◆ Start() [2/2]

template<class T>
T& ant::interval< T >::Start ( )
inlinenoexcept

Get the lower boundary.

Returns
start position

◆ Stop() [1/2]

template<class T>
constexpr const T& ant::interval< T >::Stop ( ) const
inlinenoexcept

Get the upper boundary.

Returns

◆ Stop() [2/2]

template<class T>
T& ant::interval< T >::Stop ( )
inlinenoexcept

Get the upper boundary.

Returns

◆ tryJoinWith()

template<class T>
bool ant::interval< T >::tryJoinWith ( const ant::interval< T > &  other)
inline

Join another interval into this one if they overlap.

Parameters
otheranother interval
Returns
true if joined, false if intervals are disjoint

Friends And Related Function Documentation

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  stream,
const interval< T > &  i 
)
friend

◆ operator>>

template<class T>
std::istream& operator>> ( std::istream &  out,
interval< T > &  t 
)
friend

Member Data Documentation

◆ _start

template<class T>
T ant::interval< T >::_start
protected

◆ _stop

template<class T>
T ant::interval< T >::_stop
protected

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