QtlMovie 1.12 (A specialized FFmpeg front-end)
QtlRange Class Reference

A class which describes a contiguous range of qint64 integer values. More...

Public Member Functions

 QtlRange ()
 Default constructor. More...
 
 QtlRange (qint64 first, qint64 last)
 Constructor. More...
 
QtlRangeadd (qint64 offset)
 Add a given offset to first and last value. More...
 
bool adjacent (const QtlRange &other, Qtl::AdjacentFlags flags=Qtl::AdjacentAny) const
 Check if this object and other are exactly adjacent. More...
 
void clear ()
 Clear the range. More...
 
QtlRangeclip (const QtlRange &range)
 Reduce the range so that it fits in a given range. More...
 
bool contains (qint64 value)
 Check if a given value is in the range. More...
 
quint64 count () const
 Get the number of values in the range. More...
 
qint64 first () const
 Get the first value in the range. More...
 
bool isEmpty () const
 Check if the range contains no value. More...
 
qint64 last () const
 Get the last value in the range. More...
 
QtlRangemerge (const QtlRange &other)
 Merge the content of another object into this one. More...
 
bool operator!= (const QtlRange &other) const
 Comparison operator. More...
 
bool operator< (const QtlRange &other) const
 Comparison operator. More...
 
bool operator<= (const QtlRange &other) const
 Comparison operator. More...
 
bool operator== (const QtlRange &other) const
 Comparison operator. More...
 
bool operator> (const QtlRange &other) const
 Comparison operator. More...
 
bool operator>= (const QtlRange &other) const
 Comparison operator. More...
 
bool overlap (const QtlRange &other) const
 Check if this object and other overlap (if they have at least one element in common). More...
 
QtlRangescale (qint64 factor)
 Scale the range by a given factor. More...
 
void setFirst (qint64 first)
 Change the first value in the range, without changing the last one. More...
 
void setLast (qint64 last)
 Change the last value in the range, without changing the first one. More...
 
void setRange (qint64 first, qint64 last)
 Change the range. More...
 
QString toString () const
 Convert the range to a string. More...
 

Static Public Attributes

static const qint64 RANGE_MAX = Q_INT64_C(0x7FFFFFFFFFFFFFFF)
 Maximum value in a range. More...
 
static const qint64 RANGE_MIN = Q_INT64_C(0x8000000000000000)
 Minimum value in a range. More...
 

Private Attributes

quint64 _count
 Number of values in the range. More...
 
qint64 _first
 First value. More...
 

Detailed Description

A class which describes a contiguous range of qint64 integer values.

Note that this class could be transformed into a template one for any integer type. However, the handling of type boundaries, overflow, signed vs. unsigned make the code bloated (believe me, I started from that), so I wanted to keep it simple.

Constructor & Destructor Documentation

◆ QtlRange() [1/2]

QtlRange::QtlRange ( )
inlineexplicit

Default constructor.

◆ QtlRange() [2/2]

QtlRange::QtlRange ( qint64  first,
qint64  last 
)
inlineexplicit

Constructor.

Parameters
[in]firstFirst value in the range.
[in]lastLast value in the range. Cannot be less than first - 1.

Member Function Documentation

◆ setRange()

void QtlRange::setRange ( qint64  first,
qint64  last 
)
inline

Change the range.

Parameters
[in]firstFirst value in the range.
[in]lastLast value in the range. Cannot be less than first - 1.

◆ setFirst()

void QtlRange::setFirst ( qint64  first)

Change the first value in the range, without changing the last one.

Parameters
[in]firstFirst value in the range.

◆ setLast()

void QtlRange::setLast ( qint64  last)

Change the last value in the range, without changing the first one.

Parameters
[in]lastLast value in the range. Cannot be less than first - 1.

◆ first()

qint64 QtlRange::first ( ) const
inline

Get the first value in the range.

Returns
The first value in the range.

◆ last()

qint64 QtlRange::last ( ) const

Get the last value in the range.

Returns
The last value in the range. Note that if the range is empty and first is the minimum value in the type qint64, then the returned last is also this minimum value. This can be misleading.

◆ count()

quint64 QtlRange::count ( ) const
inline

Get the number of values in the range.

Returns
The number of values in the range. The returned type is quint64 and not qint64 since this is the only type which is guaranteed to always hold the right count for any combination of first and last.

◆ isEmpty()

bool QtlRange::isEmpty ( ) const
inline

Check if the range contains no value.

Returns
True if the range contains no value.

◆ clear()

void QtlRange::clear ( )
inline

Clear the range.

The first value remains unchanged.

◆ contains()

bool QtlRange::contains ( qint64  value)

Check if a given value is in the range.

Parameters
[in]valueA value to check.
Returns
True if value is in the range.

◆ add()

QtlRange & QtlRange::add ( qint64  offset)

Add a given offset to first and last value.

There is no overflow, the range is bounded by qint64.

Parameters
[in]offsetValue to add.
Returns
A reference to this object.

◆ scale()

QtlRange & QtlRange::scale ( qint64  factor)

Scale the range by a given factor.

If first() or last() are negative, the scale operation is meaningless and sets the range to zero. Otherwise, the new first() is the previous first() times factor and the new last() is the previous last() plus one, times factor, minus one. There is no overflow, the range is bounded by qint64.

Parameters
[in]factorScale factor.
Returns
A reference to this object.

◆ overlap()

bool QtlRange::overlap ( const QtlRange other) const

Check if this object and other overlap (if they have at least one element in common).

Parameters
[in]otherAn other instance to compare.
Returns
True if the two objects have at least one element in common.

◆ adjacent()

bool QtlRange::adjacent ( const QtlRange other,
Qtl::AdjacentFlags  flags = Qtl::AdjacentAny 
) const

Check if this object and other are exactly adjacent.

Parameters
[in]otherAn other instance to compare.
[in]flagsCheck if ranges are adjacent in a specific order.
Returns
True if the two objects are exactly adjacent.

◆ merge()

QtlRange & QtlRange::merge ( const QtlRange other)

Merge the content of another object into this one.

The new first value is the smallest of the two first values. The new last value is the largest of the two last values.

Parameters
[in]otherOther instance to merge.
Returns
A reference to this object.

◆ clip()

QtlRange & QtlRange::clip ( const QtlRange range)

Reduce the range so that it fits in a given range.

Parameters
[in]rangeLimit the values within that range.
Returns
A reference to this object.

◆ operator==()

bool QtlRange::operator== ( const QtlRange other) const
inline

Comparison operator.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is equal to other. False otherwise.

◆ operator!=()

bool QtlRange::operator!= ( const QtlRange other) const
inline

Comparison operator.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is different from other. False otherwise.

◆ operator<()

bool QtlRange::operator< ( const QtlRange other) const
inline

Comparison operator.

The ranges are first ordered by their first value, then by last value.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is less than other. False otherwise.

◆ operator<=()

bool QtlRange::operator<= ( const QtlRange other) const
inline

Comparison operator.

The ranges are first ordered by their first value, then by last value.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is less than or equal to other. False otherwise.

◆ operator>()

bool QtlRange::operator> ( const QtlRange other) const
inline

Comparison operator.

The ranges are first ordered by their first value, then by last value.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is greater than other. False otherwise.

◆ operator>=()

bool QtlRange::operator>= ( const QtlRange other) const
inline

Comparison operator.

The ranges are first ordered by their first value, then by last value.

Parameters
[in]otherOther instance to compare.
Returns
True if this instance is greater than or equal to other. False otherwise.

◆ toString()

QString QtlRange::toString ( ) const

Convert the range to a string.

Returns
A string in format "[first, last]".

Member Data Documentation

◆ RANGE_MIN

const qint64 QtlRange::RANGE_MIN = Q_INT64_C(0x8000000000000000)
static

Minimum value in a range.

◆ RANGE_MAX

const qint64 QtlRange::RANGE_MAX = Q_INT64_C(0x7FFFFFFFFFFFFFFF)
static

Maximum value in a range.

◆ _first

qint64 QtlRange::_first
private

First value.

◆ _count

quint64 QtlRange::_count
private

Number of values in the range.


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