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... | |
QtlRange & | add (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... | |
QtlRange & | clip (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... | |
QtlRange & | merge (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... | |
QtlRange & | scale (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... | |
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.
|
inlineexplicit |
Default constructor.
|
inlineexplicit |
Constructor.
[in] | first | First value in the range. |
[in] | last | Last value in the range. Cannot be less than first - 1. |
|
inline |
Change the range.
[in] | first | First value in the range. |
[in] | last | Last value in the range. Cannot be less than first - 1. |
void QtlRange::setFirst | ( | qint64 | first | ) |
Change the first value in the range, without changing the last one.
[in] | first | First value in the range. |
void QtlRange::setLast | ( | qint64 | last | ) |
Change the last value in the range, without changing the first one.
[in] | last | Last value in the range. Cannot be less than first - 1. |
|
inline |
Get the first value in the range.
qint64 QtlRange::last | ( | ) | const |
Get the last value in the range.
qint64
, then the returned last is also this minimum value. This can be misleading.
|
inline |
Get the number of values in the range.
|
inline |
Check if the range contains no value.
|
inline |
Clear the range.
The first value remains unchanged.
bool QtlRange::contains | ( | qint64 | value | ) |
Check if a given value is in the range.
[in] | value | A value to check. |
QtlRange & QtlRange::add | ( | qint64 | offset | ) |
Add a given offset to first and last value.
There is no overflow, the range is bounded by qint64.
[in] | offset | Value to add. |
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.
[in] | factor | Scale factor. |
bool QtlRange::overlap | ( | const QtlRange & | other | ) | const |
Check if this object and other overlap (if they have at least one element in common).
[in] | other | An other instance to compare. |
bool QtlRange::adjacent | ( | const QtlRange & | other, |
Qtl::AdjacentFlags | flags = Qtl::AdjacentAny |
||
) | const |
Check if this object and other are exactly adjacent.
[in] | other | An other instance to compare. |
[in] | flags | Check if ranges are adjacent in a specific order. |
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.
[in] | other | Other instance to merge. |
Reduce the range so that it fits in a given range.
[in] | range | Limit the values within that range. |
|
inline |
Comparison operator.
[in] | other | Other instance to compare. |
|
inline |
Comparison operator.
[in] | other | Other instance to compare. |
|
inline |
Comparison operator.
The ranges are first ordered by their first value, then by last value.
[in] | other | Other instance to compare. |
|
inline |
Comparison operator.
The ranges are first ordered by their first value, then by last value.
[in] | other | Other instance to compare. |
|
inline |
Comparison operator.
The ranges are first ordered by their first value, then by last value.
[in] | other | Other instance to compare. |
|
inline |
Comparison operator.
The ranges are first ordered by their first value, then by last value.
[in] | other | Other instance to compare. |
QString QtlRange::toString | ( | ) | const |
Convert the range to a string.
|
static |
Minimum value in a range.
|
static |
Maximum value in a range.
|
private |
First value.
|
private |
Number of values in the range.