JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Static Public Member Functions | List of all members
Range< ValueType > Class Template Reference

A general-purpose range object, that simply represents any linear range with a start and end point. More...

Public Member Functions

 Range () noexcept
 Constructs an empty range.
 
 Range (const ValueType startValue, const ValueType endValue) noexcept
 Constructs a range with given start and end values.
 
 Range (const Range &other) noexcept
 Constructs a copy of another range.
 
Rangeoperator= (Range other) noexcept
 Copies another range object.
 
ValueType getStart () const noexcept
 Returns the start of the range.
 
ValueType getLength () const noexcept
 Returns the length of the range.
 
ValueType getEnd () const noexcept
 Returns the end of the range.
 
bool isEmpty () const noexcept
 Returns true if the range has a length of zero.
 
void setStart (const ValueType newStart) noexcept
 Changes the start position of the range, leaving the end position unchanged.
 
Range withStart (const ValueType newStart) const noexcept
 Returns a range with the same end as this one, but a different start.
 
Range movedToStartAt (const ValueType newStart) const noexcept
 Returns a range with the same length as this one, but moved to have the given start position.
 
void setEnd (const ValueType newEnd) noexcept
 Changes the end position of the range, leaving the start unchanged.
 
Range withEnd (const ValueType newEnd) const noexcept
 Returns a range with the same start position as this one, but a different end.
 
Range movedToEndAt (const ValueType newEnd) const noexcept
 Returns a range with the same length as this one, but moved to have the given end position.
 
void setLength (const ValueType newLength) noexcept
 Changes the length of the range.
 
Range withLength (const ValueType newLength) const noexcept
 Returns a range with the same start as this one, but a different length.
 
Range operator+= (const ValueType amountToAdd) noexcept
 Adds an amount to the start and end of the range.
 
Range operator-= (const ValueType amountToSubtract) noexcept
 Subtracts an amount from the start and end of the range.
 
Range operator+ (const ValueType amountToAdd) const noexcept
 Returns a range that is equal to this one with an amount added to its start and end.
 
Range operator- (const ValueType amountToSubtract) const noexcept
 Returns a range that is equal to this one with the specified amount subtracted from its start and end.
 
bool operator== (Range other) const noexcept
 
bool operator!= (Range other) const noexcept
 
bool contains (const ValueType position) const noexcept
 Returns true if the given position lies inside this range.
 
ValueType clipValue (const ValueType value) const noexcept
 Returns the nearest value to the one supplied, which lies within the range.
 
bool contains (Range other) const noexcept
 Returns true if the given range lies entirely inside this range.
 
bool intersects (Range other) const noexcept
 Returns true if the given range intersects this one.
 
Range getIntersectionWith (Range other) const noexcept
 Returns the range that is the intersection of the two ranges, or an empty range with an undefined start position if they don't overlap.
 
Range getUnionWith (Range other) const noexcept
 Returns the smallest range that contains both this one and the other one.
 
Range getUnionWith (const ValueType valueToInclude) const noexcept
 Returns the smallest range that contains both this one and the given value.
 
Range constrainRange (Range rangeToConstrain) const noexcept
 Returns a given range, after moving it forwards or backwards to fit it within this range.
 

Static Public Member Functions

static Range between (const ValueType position1, const ValueType position2) noexcept
 Returns the range that lies between two positions (in either order).
 
static Range withStartAndLength (const ValueType startValue, const ValueType length) noexcept
 Returns a range with a given start and length.
 
static Range emptyRange (const ValueType start) noexcept
 Returns a range with the specified start position and a length of zero.
 
static Range findMinAndMax (const ValueType *values, int numValues) noexcept
 Scans an array of values for its min and max, and returns these as a Range.
 

Detailed Description

template<typename ValueType>
class Range< ValueType >

A general-purpose range object, that simply represents any linear range with a start and end point.

Note that when checking whether values fall within the range, the start value is considered to be inclusive, and the end of the range exclusive.

The templated parameter is expected to be a primitive integer or floating point type, though class types could also be used if they behave in a number-like way.

Constructor & Destructor Documentation

template<typename ValueType>
Range< ValueType >::Range ( )
noexcept
template<typename ValueType>
Range< ValueType >::Range ( const ValueType  startValue,
const ValueType  endValue 
)
noexcept

Constructs a range with given start and end values.

template<typename ValueType>
Range< ValueType >::Range ( const Range< ValueType > &  other)
noexcept

Constructs a copy of another range.

Member Function Documentation

template<typename ValueType>
Range& Range< ValueType >::operator= ( Range< ValueType >  other)
noexcept

Copies another range object.

template<typename ValueType>
static Range Range< ValueType >::between ( const ValueType  position1,
const ValueType  position2 
)
staticnoexcept

Returns the range that lies between two positions (in either order).

template<typename ValueType>
static Range Range< ValueType >::withStartAndLength ( const ValueType  startValue,
const ValueType  length 
)
staticnoexcept

Returns a range with a given start and length.

template<typename ValueType>
static Range Range< ValueType >::emptyRange ( const ValueType  start)
staticnoexcept

Returns a range with the specified start position and a length of zero.

template<typename ValueType>
ValueType Range< ValueType >::getStart ( ) const
noexcept
template<typename ValueType>
ValueType Range< ValueType >::getLength ( ) const
noexcept
template<typename ValueType>
ValueType Range< ValueType >::getEnd ( ) const
noexcept
template<typename ValueType>
bool Range< ValueType >::isEmpty ( ) const
noexcept

Returns true if the range has a length of zero.

template<typename ValueType>
void Range< ValueType >::setStart ( const ValueType  newStart)
noexcept

Changes the start position of the range, leaving the end position unchanged.

If the new start position is higher than the current end of the range, the end point will be pushed along to equal it, leaving an empty range at the new position.

template<typename ValueType>
Range Range< ValueType >::withStart ( const ValueType  newStart) const
noexcept

Returns a range with the same end as this one, but a different start.

If the new start position is higher than the current end of the range, the end point will be pushed along to equal it, returning an empty range at the new position.

template<typename ValueType>
Range Range< ValueType >::movedToStartAt ( const ValueType  newStart) const
noexcept

Returns a range with the same length as this one, but moved to have the given start position.

template<typename ValueType>
void Range< ValueType >::setEnd ( const ValueType  newEnd)
noexcept

Changes the end position of the range, leaving the start unchanged.

If the new end position is below the current start of the range, the start point will be pushed back to equal the new end point.

template<typename ValueType>
Range Range< ValueType >::withEnd ( const ValueType  newEnd) const
noexcept

Returns a range with the same start position as this one, but a different end.

If the new end position is below the current start of the range, the start point will be pushed back to equal the new end point.

template<typename ValueType>
Range Range< ValueType >::movedToEndAt ( const ValueType  newEnd) const
noexcept

Returns a range with the same length as this one, but moved to have the given end position.

template<typename ValueType>
void Range< ValueType >::setLength ( const ValueType  newLength)
noexcept

Changes the length of the range.

Lengths less than zero are treated as zero.

template<typename ValueType>
Range Range< ValueType >::withLength ( const ValueType  newLength) const
noexcept

Returns a range with the same start as this one, but a different length.

Lengths less than zero are treated as zero.

template<typename ValueType>
Range Range< ValueType >::operator+= ( const ValueType  amountToAdd)
noexcept

Adds an amount to the start and end of the range.

template<typename ValueType>
Range Range< ValueType >::operator-= ( const ValueType  amountToSubtract)
noexcept

Subtracts an amount from the start and end of the range.

template<typename ValueType>
Range Range< ValueType >::operator+ ( const ValueType  amountToAdd) const
noexcept

Returns a range that is equal to this one with an amount added to its start and end.

template<typename ValueType>
Range Range< ValueType >::operator- ( const ValueType  amountToSubtract) const
noexcept

Returns a range that is equal to this one with the specified amount subtracted from its start and end.

template<typename ValueType>
bool Range< ValueType >::operator== ( Range< ValueType >  other) const
noexcept
template<typename ValueType>
bool Range< ValueType >::operator!= ( Range< ValueType >  other) const
noexcept
template<typename ValueType>
bool Range< ValueType >::contains ( const ValueType  position) const
noexcept

Returns true if the given position lies inside this range.

template<typename ValueType>
ValueType Range< ValueType >::clipValue ( const ValueType  value) const
noexcept

Returns the nearest value to the one supplied, which lies within the range.

template<typename ValueType>
bool Range< ValueType >::contains ( Range< ValueType >  other) const
noexcept

Returns true if the given range lies entirely inside this range.

When making this comparison, the start value is considered to be inclusive, and the end of the range exclusive.

template<typename ValueType>
bool Range< ValueType >::intersects ( Range< ValueType >  other) const
noexcept

Returns true if the given range intersects this one.

template<typename ValueType>
Range Range< ValueType >::getIntersectionWith ( Range< ValueType >  other) const
noexcept

Returns the range that is the intersection of the two ranges, or an empty range with an undefined start position if they don't overlap.

template<typename ValueType>
Range Range< ValueType >::getUnionWith ( Range< ValueType >  other) const
noexcept

Returns the smallest range that contains both this one and the other one.

template<typename ValueType>
Range Range< ValueType >::getUnionWith ( const ValueType  valueToInclude) const
noexcept

Returns the smallest range that contains both this one and the given value.

template<typename ValueType>
Range Range< ValueType >::constrainRange ( Range< ValueType >  rangeToConstrain) const
noexcept

Returns a given range, after moving it forwards or backwards to fit it within this range.

If the supplied range has a greater length than this one, the return value will be this range.

Otherwise, if the supplied range is smaller than this one, the return value will be the new range, shifted forwards or backwards so that it doesn't extend beyond this one, but keeping its original length.

template<typename ValueType>
static Range Range< ValueType >::findMinAndMax ( const ValueType *  values,
int  numValues 
)
staticnoexcept

Scans an array of values for its min and max, and returns these as a Range.


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