Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TRange< ElementType > Class Template Reference

#include <Range.h>

Public Types

typedef TRangeBound< ElementType > BoundsType
 
typedef TCallTraits< ElementType >::ParamType ElementValueOrConstRef
 

Public Member Functions

 TRange ()
 
 TRange (ElementValueOrConstRef A)
 
 TRange (ElementValueOrConstRef A, ElementValueOrConstRef B)
 
 TRange (const BoundsType &InLowerBound, const BoundsType &InUpperBound)
 
bool operator== (const TRange &Other) const
 
bool operator!= (const TRange &Other) const
 
bool Adjoins (const TRange &Other) const
 
bool Conjoins (const TRange &X, const TRange &Y) const
 
bool Contains (ElementValueOrConstRef Element) const
 
bool Contains (const TRange &Other) const
 
bool Contiguous (const TRange &Other) const
 
BoundsType GetLowerBound () const
 
void SetLowerBound (const BoundsType &NewLowerBound)
 
void SetLowerBoundValue (ElementValueOrConstRef NewLowerBoundValue)
 
ElementValueOrConstRef GetLowerBoundValue () const
 
BoundsType GetUpperBound () const
 
void SetUpperBound (const BoundsType &NewUpperBound)
 
void SetUpperBoundValue (ElementValueOrConstRef NewUpperBoundValue)
 
ElementValueOrConstRef GetUpperBoundValue () const
 
bool HasLowerBound () const
 
bool HasUpperBound () const
 
bool IsDegenerate () const
 
bool IsEmpty () const
 
bool Overlaps (const TRange &Other) const
 
template<typename DifferenceType >
DifferenceType Size () const
 
TArray< TRangeSplit (ElementValueOrConstRef Element) const
 

Static Public Member Functions

static FORCEINLINE TArray< TRangeDifference (const TRange &X, const TRange &Y)
 
static FORCEINLINE TRange Hull (const TRange &X, const TRange &Y)
 
static FORCEINLINE TRange Hull (const TArray< TRange > &Ranges)
 
static FORCEINLINE TRange Intersection (const TRange &X, const TRange &Y)
 
static FORCEINLINE TRange Intersection (const TArray< TRange > &Ranges)
 
static FORCEINLINE TArray< TRangeUnion (const TRange &X, const TRange &Y)
 
static FORCEINLINE TRange All ()
 
static FORCEINLINE TRange AtLeast (ElementValueOrConstRef Value)
 
static FORCEINLINE TRange AtMost (ElementValueOrConstRef Value)
 
static FORCEINLINE TRange Empty ()
 
static FORCEINLINE TRange Exclusive (ElementValueOrConstRef Min, ElementValueOrConstRef Max)
 
static FORCEINLINE TRange GreaterThan (ElementValueOrConstRef Value)
 
static FORCEINLINE TRange Inclusive (ElementValueOrConstRef Min, ElementValueOrConstRef Max)
 
static FORCEINLINE TRange LessThan (ElementValueOrConstRef Value)
 

Private Attributes

BoundsType LowerBound
 
BoundsType UpperBound
 

Friends

class FArchiveoperator<< (class FArchive &Ar, TRange &Range)
 
uint32 GetTypeHash (const TRange &Range)
 

Detailed Description

template<typename ElementType>
class TRange< ElementType >

Template for ranges.

Note: This class is not intended for interval arithmetic (see TInterval for that).

A range represents a contiguous set of elements that only stores the set's lower and upper bound values (aka. endpoints) for storage efficiency. Bound values may be exclusive (the value is not part of the range), inclusive (the value is part of the range) or open (there is no limit on the values).

The template's primary focus is on continuous ranges, but it can be used for the representation of discrete ranges as well. The element type of discrete ranges has a well-defined stepping, such as an integer or a date, that separates the neighboring elements. This is in contrast with continuous ranges in which the step sizes, such as floats or time spans, are not of interest, and other elements may be found between any two elements (although, in practice, all ranges are discrete due to the limited precision of numerical values in computers).

When working with ranges, the user of this template is responsible for correctly interpreting the range endpoints. Certain semantics will be different depending on whether the range is interpreted in a continuous or discrete domain.

Iteration of a discrete range [A, B) includes the elements A to B-1. The elements of continuous ranges are generally not meant to be iterated. It is also important to consider the equivalence of different representations of discrete ranges. For example, the ranges [2, 6), (1, 5] and [2, 5] are equivalent in discrete domains, but different in continuous ones. In order to keep this class simple, we have not included canonicalization functions or auxiliary template parameters, such as unit and min/max domain elements. For ease of use in most common use cases, it is recommended to limit all operations to canonical ranges of the form [A, B) in which the lower bound is included and the upper bound is excluded from the range.

Parameters
ElementTypeThe type of elements represented by the range
See also
RangeBound, TInterval

Definition at line 49 of file Range.h.

Member Typedef Documentation

◆ BoundsType

template<typename ElementType >
typedef TRangeBound<ElementType> TRange< ElementType >::BoundsType

Definition at line 53 of file Range.h.

◆ ElementValueOrConstRef

template<typename ElementType >
typedef TCallTraits<ElementType>::ParamType TRange< ElementType >::ElementValueOrConstRef

Definition at line 56 of file Range.h.

Constructor & Destructor Documentation

◆ TRange() [1/4]

template<typename ElementType >
TRange< ElementType >::TRange ( )
inline

Default constructor (no initialization).

Definition at line 59 of file Range.h.

◆ TRange() [2/4]

template<typename ElementType >
TRange< ElementType >::TRange ( ElementValueOrConstRef A)
inlineexplicit

Create a range with a single element.

The created range is of the form [A, A].

Parameters
AThe element in the range.

Definition at line 68 of file Range.h.

◆ TRange() [3/4]

template<typename ElementType >
TRange< ElementType >::TRange ( ElementValueOrConstRef A,
ElementValueOrConstRef B )
inlineexplicit

Create and initializes a new range with the given lower and upper bounds.

The created range is of the form [A, B).

Parameters
AThe range's lower bound value (inclusive).
BThe range's upper bound value (exclusive).

Definition at line 81 of file Range.h.

◆ TRange() [4/4]

template<typename ElementType >
TRange< ElementType >::TRange ( const BoundsType & InLowerBound,
const BoundsType & InUpperBound )
inlineexplicit

Create and initializes a new range with the given lower and upper bounds.

Parameters
InLowerBoundThe range's lower bound.
InUpperBoundThe range's upper bound.

Definition at line 92 of file Range.h.

Member Function Documentation

◆ Adjoins()

template<typename ElementType >
bool TRange< ElementType >::Adjoins ( const TRange< ElementType > & Other) const
inline

Check whether this range adjoins to another.

Two ranges are adjoint if they are next to each other without overlapping, i.e. [A, B) and [B, C) or [A, B] and (B, C)

Parameters
OtherThe other range.
Returns
true if this range adjoins the other, false otherwise.

Definition at line 143 of file Range.h.

◆ All()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::All ( )
inlinestatic

Create an unbounded (open) range that contains all elements of the domain.

Returns
A new range.
See also
AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

Definition at line 635 of file Range.h.

◆ AtLeast()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::AtLeast ( ElementValueOrConstRef Value)
inlinestatic

Create a left-bounded range that contains all elements greater than or equal to the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

Definition at line 647 of file Range.h.

◆ AtMost()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::AtMost ( ElementValueOrConstRef Value)
inlinestatic

Create a right-bounded range that contains all elements less than or equal to the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, Empty, Exclusive, GreaterThan, Inclusive, LessThan

Definition at line 659 of file Range.h.

◆ Conjoins()

template<typename ElementType >
bool TRange< ElementType >::Conjoins ( const TRange< ElementType > & X,
const TRange< ElementType > & Y ) const
inline

Check whether this range conjoins the two given ranges.

A range conjoins two non-overlapping ranges if it adjoins both of them, i.e. [B, C) conjoins the two ranges [A, B) and [C, D).

Parameters
XThe first range.
YThe second range.
Returns
true if this range conjoins the two ranges, false otherwise.

Definition at line 175 of file Range.h.

◆ Contains() [1/2]

template<typename ElementType >
bool TRange< ElementType >::Contains ( const TRange< ElementType > & Other) const
inline

Check whether this range contains another range.

Parameters
OtherThe range to check.
Returns
true if the range contains the other range, false otherwise.

Definition at line 203 of file Range.h.

◆ Contains() [2/2]

template<typename ElementType >
bool TRange< ElementType >::Contains ( ElementValueOrConstRef Element) const
inline

Check whether this range contains the specified element.

Parameters
ElementThe element to check.
Returns
true if the range contains the element, false otherwise.

Definition at line 191 of file Range.h.

◆ Contiguous()

template<typename ElementType >
bool TRange< ElementType >::Contiguous ( const TRange< ElementType > & Other) const
inline

Check if this range is contiguous with another range.

Two ranges are contiguous if they are adjoint or overlapping.

Parameters
OtherThe other range.
Returns
true if the ranges are contiguous, false otherwise.

Definition at line 217 of file Range.h.

◆ Difference()

template<typename ElementType >
static FORCEINLINE TArray< TRange > TRange< ElementType >::Difference ( const TRange< ElementType > & X,
const TRange< ElementType > & Y )
inlinestatic

Calculate the difference between two ranges, i.e. X - Y.

Parameters
XThe first range to subtract from.
YThe second range to subtract with.
Returns
Between 0 and 2 remaining ranges.
See also
Hull, Intersection, Union

Definition at line 468 of file Range.h.

◆ Empty()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Empty ( )
inlinestatic

Return an empty range.

Returns
Empty range.
See also
All, AtLeast, AtMost, Exclusive, GreaterThan, Inclusive, LessThan

Definition at line 670 of file Range.h.

◆ Exclusive()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Exclusive ( ElementValueOrConstRef Min,
ElementValueOrConstRef Max )
inlinestatic

Create a range that excludes the given minimum and maximum values.

Parameters
MinTheminimum value to be included.
MaxThe maximum value to be included.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive, LessThan

Definition at line 683 of file Range.h.

◆ GetLowerBound()

template<typename ElementType >
BoundsType TRange< ElementType >::GetLowerBound ( ) const
inline

Get the range's lower bound.

Returns
Lower bound.
See also
GetLowerBoundValue, GetUpperBound, HasLowerBound

Definition at line 228 of file Range.h.

◆ GetLowerBoundValue()

template<typename ElementType >
ElementValueOrConstRef TRange< ElementType >::GetLowerBoundValue ( ) const
inline

Get the value of the lower bound.

Use HasLowerBound() to ensure that this range actually has a lower bound.

Returns
Bound value.
See also
GetLowerBound, GetUpperBoundValue, HasLowerBound

Definition at line 263 of file Range.h.

◆ GetUpperBound()

template<typename ElementType >
BoundsType TRange< ElementType >::GetUpperBound ( ) const
inline

Get the range's upper bound.

Returns
Upper bound.
See also
GetLowerBound, GetUpperBoundValue, HasUpperBound

Definition at line 274 of file Range.h.

◆ GetUpperBoundValue()

template<typename ElementType >
ElementValueOrConstRef TRange< ElementType >::GetUpperBoundValue ( ) const
inline

Get the value of the upper bound.

Use HasUpperBound() to ensure that this range actually has an upper bound.

Returns
Bound value.
See also
GetLowerBoundValue, GetUpperBound, HasUpperBound

Definition at line 309 of file Range.h.

◆ GreaterThan()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::GreaterThan ( ElementValueOrConstRef Value)
inlinestatic

Create a left-bounded range that contains all elements greater than the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, Inclusive, LessThan

Definition at line 695 of file Range.h.

◆ HasLowerBound()

template<typename ElementType >
bool TRange< ElementType >::HasLowerBound ( ) const
inline

Check whether the range has a lower bound.

Returns
true if the range has a lower bound, false otherwise.
See also
GetLowerBound, GetLowerBoundValue, HasUpperBound

Definition at line 320 of file Range.h.

◆ HasUpperBound()

template<typename ElementType >
bool TRange< ElementType >::HasUpperBound ( ) const
inline

Check whether the range has an upper bound.

Returns
true if the range has an upper bound, false otherwise.
See also
GetUpperBound, GetUpperBoundValue, HasLowerBound

Definition at line 331 of file Range.h.

◆ Hull() [1/2]

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Hull ( const TArray< TRange< ElementType > > & Ranges)
inlinestatic

Compute the hull of many ranges.

Parameters
RangesThe ranges to hull.
Returns
The hull.
See also
Difference, Intersection, Union

Definition at line 527 of file Range.h.

◆ Hull() [2/2]

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Hull ( const TRange< ElementType > & X,
const TRange< ElementType > & Y )
inlinestatic

Compute the hull of two ranges.

The hull is the smallest range that contains both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The hull.
See also
Difference, Intersection, Union

Definition at line 505 of file Range.h.

◆ Inclusive()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Inclusive ( ElementValueOrConstRef Min,
ElementValueOrConstRef Max )
inlinestatic

Create a range that includes the given minimum and maximum values.

Parameters
MinThe minimum value to be included.
MaxThe maximum value to be included.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, LessThan

Definition at line 708 of file Range.h.

◆ Intersection() [1/2]

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Intersection ( const TArray< TRange< ElementType > > & Ranges)
inlinestatic

Compute the intersection of many ranges.

Parameters
RangesThe ranges to intersect.
Returns
The intersection.
See also
Difference, Hull, Union

Definition at line 576 of file Range.h.

◆ Intersection() [2/2]

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::Intersection ( const TRange< ElementType > & X,
const TRange< ElementType > & Y )
inlinestatic

Compute the intersection of two ranges.

The intersection of two ranges is the largest range that is contained by both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The intersection, or an empty range if the ranges do not overlap.
See also
Difference, Hull, Union

Definition at line 554 of file Range.h.

◆ IsDegenerate()

template<typename ElementType >
bool TRange< ElementType >::IsDegenerate ( ) const
inline

Check whether this range is degenerate.

A range is degenerate if it contains only a single element, i.e. has the following form: [A, A]

Returns
true if the range is degenerate, false otherwise.
See also
IsEmpty

Definition at line 345 of file Range.h.

◆ IsEmpty()

template<typename ElementType >
bool TRange< ElementType >::IsEmpty ( ) const
inline

Check whether this range is empty.

A range is empty if it contains no elements, i.e. (A, A) (A, A] [A, A)

Returns
true if the range is empty, false otherwise.
See also
IsDegenerate

Definition at line 361 of file Range.h.

◆ LessThan()

template<typename ElementType >
static FORCEINLINE TRange TRange< ElementType >::LessThan ( ElementValueOrConstRef Value)
inlinestatic

Create a right-bounded range that contains all elements less than the specified value.

Parameters
ValueThe value.
Returns
A new range.
See also
All, AtLeast, AtMost, Empty, Exclusive, GreaterThan, Inclusive

Definition at line 720 of file Range.h.

◆ operator!=()

template<typename ElementType >
bool TRange< ElementType >::operator!= ( const TRange< ElementType > & Other) const
inline

Compare this range with the specified range for inequality.

Parameters
OtherThe range to compare with.
Returns
true if the ranges are not equal, false otherwise.

Definition at line 121 of file Range.h.

◆ operator==()

template<typename ElementType >
bool TRange< ElementType >::operator== ( const TRange< ElementType > & Other) const
inline

Compare this range with the specified range for equality.

Parameters
OtherThe range to compare with.
Returns
true if the ranges are equal, false otherwise.

Definition at line 105 of file Range.h.

◆ Overlaps()

template<typename ElementType >
bool TRange< ElementType >::Overlaps ( const TRange< ElementType > & Other) const
inline

Check whether this range overlaps with another.

Parameters
OtherThe other range.
Returns
true if the ranges overlap, false otherwise.

Definition at line 382 of file Range.h.

◆ SetLowerBound()

template<typename ElementType >
void TRange< ElementType >::SetLowerBound ( const BoundsType & NewLowerBound)
inline

Assign the new lower bound for this range

Parameters
NewLowerBoundThe new lower bound to assign
See also
GetLowerBound

Definition at line 239 of file Range.h.

◆ SetLowerBoundValue()

template<typename ElementType >
void TRange< ElementType >::SetLowerBoundValue ( ElementValueOrConstRef NewLowerBoundValue)
inline

Assign the new lower bound value for this range. Current lower bound must not be open to call this method.

Parameters
NewLowerBoundValueThe new lower bound value to assign
See also
GetLowerBound

Definition at line 250 of file Range.h.

◆ SetUpperBound()

template<typename ElementType >
void TRange< ElementType >::SetUpperBound ( const BoundsType & NewUpperBound)
inline

Assign the new upper bound for this range

Parameters
NewUpperBoundThe new upper bound to assign
See also
GetUpperBound

Definition at line 285 of file Range.h.

◆ SetUpperBoundValue()

template<typename ElementType >
void TRange< ElementType >::SetUpperBoundValue ( ElementValueOrConstRef NewUpperBoundValue)
inline

Assign the new upper bound value for this range. Current upper bound must not be open to call this method.

Parameters
NewUpperBoundValueThe new upper bound value to assign
See also
GetUpperBound

Definition at line 296 of file Range.h.

◆ Size()

template<typename ElementType >
DifferenceType TRange< ElementType >::Size ( ) const
inline

Compute the size (diameter, length, width) of this range.

The size of a closed range is the difference between its upper and lower bound values. Use IsClosed() on the lower and upper bounds before calling this method in order to make sure that the range is closed.

Returns
Range size.

Definition at line 426 of file Range.h.

◆ Split()

template<typename ElementType >
TArray< TRange > TRange< ElementType >::Split ( ElementValueOrConstRef Element) const
inline

Split the range into two ranges at the specified element.

If a range [A, C) does not contain the element X, the original range is returned. Otherwise the range is split into two ranges [A, X) and [X, C), each of which may be empty.

Parameters
ElementThe element at which to split the range.

Definition at line 441 of file Range.h.

◆ Union()

template<typename ElementType >
static FORCEINLINE TArray< TRange > TRange< ElementType >::Union ( const TRange< ElementType > & X,
const TRange< ElementType > & Y )
inlinestatic

Return the union of two contiguous ranges.

A union is a range or series of ranges that contains both ranges.

Parameters
XThe first range.
YThe second range.
Returns
The union, or both ranges if the two ranges are not contiguous, or no ranges if both ranges are empty.
See also
Difference, Hull, Intersection

Definition at line 603 of file Range.h.

Friends And Related Symbol Documentation

◆ GetTypeHash

template<typename ElementType >
uint32 GetTypeHash ( const TRange< ElementType > & Range)
friend

Gets the hash for the specified range.

Parameters
RangeThe range to get the hash for.
Returns
Hash value.

Definition at line 745 of file Range.h.

◆ operator<<

template<typename ElementType >
class FArchive & operator<< ( class FArchive & Ar,
TRange< ElementType > & Range )
friend

Serializes the given range from or into the specified archive.

Parameters
ArThe archive to serialize from or into.
RangeThe range to serialize.
Returns
The archive.

Definition at line 734 of file Range.h.

Member Data Documentation

◆ LowerBound

template<typename ElementType >
BoundsType TRange< ElementType >::LowerBound
private

Holds the range's lower bound.

Definition at line 753 of file Range.h.

◆ UpperBound

template<typename ElementType >
BoundsType TRange< ElementType >::UpperBound
private

Holds the range's upper bound.

Definition at line 756 of file Range.h.


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