Add ++/--/min/max to QSpecialInteger
Add both prefix and postfix versions of the increment/decrement operators, and a static constexpr min/max which returns the minimum/maximumm values that can be stored in the QSpecialInteger. These latter functions are useful to define constants, e.g.: typedef quint8_be IPv4_TTL; static constexpr TTL_TO_DROP = IPv4_TTL::min(); Change-Id: I825a279feb68b93572765a9fdb5aa7b06d1be35b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
d7fbc9ea88
commit
d26289ffb4
@ -432,6 +432,46 @@ QT_BEGIN_NAMESPACE
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger &QLEInteger<T>::operator++()
|
||||
|
||||
Performs a prefix ++ (increment) on this QLEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger QLEInteger<T>::operator++(int)
|
||||
|
||||
Performs a postfix ++ (increment) on this QLEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger &QLEInteger<T>::operator--()
|
||||
|
||||
Performs a prefix -- (decrement) on this QLEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger QLEInteger<T>::operator--(int)
|
||||
|
||||
Performs a postfix -- (decrement) on this QLEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger QLEInteger<T>::max()
|
||||
|
||||
Returns the maximum (finite) value representable by the numeric type T.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QLEInteger QLEInteger<T>::min()
|
||||
|
||||
Returns the minimum (finite) value representable by the numeric type T.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QBEInteger
|
||||
\inmodule QtCore
|
||||
@ -551,6 +591,46 @@ QT_BEGIN_NAMESPACE
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger &QBEInteger<T>::operator++()
|
||||
|
||||
Performs a prefix ++ (increment) on this QBEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger QBEInteger<T>::operator++(int)
|
||||
|
||||
Performs a postfix ++ (increment) on this QBEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger &QBEInteger<T>::operator--()
|
||||
|
||||
Performs a prefix -- (decrement) on this QBEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger QBEInteger<T>::operator--(int)
|
||||
|
||||
Performs a postfix -- (decrement) on this QBEInteger and returns a reference to
|
||||
this object.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger QBEInteger<T>::max()
|
||||
|
||||
Returns the maximum (finite) value representable by the numeric type T.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename T> QBEInteger QBEInteger<T>::min()
|
||||
|
||||
Returns the minimum (finite) value representable by the numeric type T.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\typedef quint16_le
|
||||
\relates <QtEndian>
|
||||
|
@ -47,6 +47,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef min // MSVC
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*
|
||||
@ -279,6 +284,27 @@ public:
|
||||
{ return (*this = S::fromSpecial(val) & i); }
|
||||
QSpecialInteger &operator ^=(T i)
|
||||
{ return (*this = S::fromSpecial(val) ^ i); }
|
||||
QSpecialInteger &operator ++()
|
||||
{ return (*this = S::fromSpecial(val) + 1); }
|
||||
QSpecialInteger &operator --()
|
||||
{ return (*this = S::fromSpecial(val) - 1); }
|
||||
QSpecialInteger operator ++(int)
|
||||
{
|
||||
QSpecialInteger<S> pre = *this;
|
||||
*this += 1;
|
||||
return pre;
|
||||
}
|
||||
QSpecialInteger operator --(int)
|
||||
{
|
||||
QSpecialInteger<S> pre = *this;
|
||||
*this -= 1;
|
||||
return pre;
|
||||
}
|
||||
|
||||
static constexpr QSpecialInteger max()
|
||||
{ return QSpecialInteger(std::numeric_limits<T>::max()); }
|
||||
static constexpr QSpecialInteger min()
|
||||
{ return QSpecialInteger(std::numeric_limits<T>::min()); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -316,6 +342,13 @@ public:
|
||||
QLEInteger &operator |=(T i);
|
||||
QLEInteger &operator &=(T i);
|
||||
QLEInteger &operator ^=(T i);
|
||||
QLEInteger &operator ++();
|
||||
QLEInteger &operator --();
|
||||
QLEInteger &operator ++(int);
|
||||
QLEInteger &operator --(int);
|
||||
|
||||
static constexpr QLEInteger max();
|
||||
static constexpr QLEInteger min();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -336,6 +369,13 @@ public:
|
||||
QBEInteger &operator |=(T i);
|
||||
QBEInteger &operator &=(T i);
|
||||
QBEInteger &operator ^=(T i);
|
||||
QBEInteger &operator ++();
|
||||
QBEInteger &operator --();
|
||||
QBEInteger &operator ++(int);
|
||||
QBEInteger &operator --(int);
|
||||
|
||||
static constexpr QBEInteger max();
|
||||
static constexpr QBEInteger min();
|
||||
};
|
||||
#else
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user