Upgrade INT_ methods to numeric_limits

This commit is contained in:
Nyall Dawson 2018-06-16 12:56:00 +10:00
parent 17cd2fd5f3
commit c705670947
18 changed files with 41 additions and 34 deletions

View File

@ -437,6 +437,8 @@ sub fix_constants {
$line =~ s/\bstd::numeric_limits<double>::max\(\)/DBL_MAX/g;
$line =~ s/\bstd::numeric_limits<double>::lowest\(\)/-DBL_MAX/g;
$line =~ s/\bstd::numeric_limits<double>::epsilon\(\)/DBL_EPSILON/g;
$line =~ s/\bstd::numeric_limits<int>::max\(\)/INT_MAX/g;
$line =~ s/\bstd::numeric_limits<int>::min\(\)/INT_MIN/g;
return $line;
}

View File

@ -444,7 +444,7 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p )
void QgsDxfExport::writeGroup( const QColor &color, int exactMatchCode, int rgbCode, int transparencyCode )
{
int minDistAt = -1;
int minDist = INT_MAX;
int minDist = std::numeric_limits<int>::max();
for ( int i = 1; i < static_cast< int >( sizeof( sDxfColors ) / sizeof( *sDxfColors ) ) && minDist > 0; ++i )
{
@ -3910,7 +3910,7 @@ QString QgsDxfExport::lineStyleFromSymbolLayer( const QgsSymbolLayer *symbolLaye
int QgsDxfExport::closestColorMatch( QRgb pixel )
{
int idx = 0;
int current_distance = INT_MAX;
int current_distance = std::numeric_limits<int>::max();
for ( int i = 1; i < static_cast< int >( sizeof( sDxfColors ) / sizeof( *sDxfColors ) ); ++i )
{
int dist = color_distance( pixel, i );

View File

@ -46,7 +46,7 @@ int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
case QPaintDevice::PdmHeightMM:
return mDrawingSize.height();
case QPaintDevice::PdmNumColors:
return INT_MAX;
return std::numeric_limits<int>::max();
case QPaintDevice::PdmDepth:
return 32;
case QPaintDevice::PdmDpiX:

View File

@ -39,7 +39,7 @@
#include "priorityqueue.h"
#include "internalexception.h"
#include <cfloat>
#include <limits> //for INT_MAX
#include <limits> //for std::numeric_limits<int>::max()
#include "qgslabelingengine.h"
@ -347,7 +347,7 @@ void Problem::init_sol_falp()
{
if ( sol->s[i] == -1 )
{
nbOverlap = INT_MAX;
nbOverlap = std::numeric_limits<int>::max();
start_p = featStartId[i];
for ( p = 0; p < featNbLp[i]; p++ )
{

View File

@ -135,7 +135,7 @@ int QgsProcessingParameters::parameterAsInt( const QgsProcessingParameterDefinit
if ( ok )
{
double round = std::round( dbl );
if ( round > INT_MAX || round < -INT_MAX )
if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
{
//double too large to fit in int
return 0;

View File

@ -353,7 +353,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
}
double round = std::round( dbl );
if ( round > INT_MAX || round < -INT_MAX )
if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
{
//double too large to fit in int
v = QVariant( d->type );

View File

@ -40,7 +40,7 @@ void QgsStringStatisticalSummary::reset()
mCountMissing = 0;
mMin.clear();
mMax.clear();
mMinLength = INT_MAX;
mMinLength = std::numeric_limits<int>::max();
mMaxLength = 0;
mSumLengths = 0;
mMeanLength = 0;

View File

@ -2496,7 +2496,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::prepareWriteAsVectorFormat
{
QVariant min = layer->minimumValue( i );
QVariant max = layer->maximumValue( i );
if ( std::max( std::llabs( min.toLongLong() ), std::llabs( max.toLongLong() ) ) < INT_MAX )
if ( std::max( std::llabs( min.toLongLong() ), std::llabs( max.toLongLong() ) ) < std::numeric_limits<int>::max() )
{
details.outputFields[i].setType( QVariant::Int );
}

View File

@ -275,8 +275,8 @@ void QgsGradientStopEditor::mouseMoveEvent( QMouseEvent *e )
int QgsGradientStopEditor::findClosestStop( int x, int threshold ) const
{
int closestStop = -1;
int closestDiff = INT_MAX;
int currentDiff = INT_MAX;
int closestDiff = std::numeric_limits<int>::max();
int currentDiff = std::numeric_limits<int>::max();
// check for matching stops first, so that they take precedence
// otherwise it's impossible to select a stop which sits above the first/last stop, making

View File

@ -704,7 +704,7 @@ bool QgsPalettedRendererModel::removeRows( int row, int count, const QModelIndex
bool QgsPalettedRendererModel::insertRows( int row, int count, const QModelIndex & )
{
QgsPalettedRasterRenderer::ClassData::const_iterator cIt = mData.constBegin();
int currentMaxValue = -INT_MAX;
int currentMaxValue = -std::numeric_limits<int>::max();
for ( ; cIt != mData.constEnd(); ++cIt )
{
int value = cIt->value;

View File

@ -267,8 +267,8 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
, mValueType( String )
, mOutputType( None )
, mHaveLimits( false )
, mMin( INT_MAX )
, mMax( INT_MIN )
, mMin( std::numeric_limits<int>::max() )
, mMax( std::numeric_limits<int>::min() )
, mIsOutput( false )
, mUsesRegion( false )
{

View File

@ -114,7 +114,7 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const &uri )
double myInternalNoDataValue;
if ( mGrassDataType == CELL_TYPE )
{
myInternalNoDataValue = INT_MIN;
myInternalNoDataValue = std::numeric_limits<int>::min();
}
else if ( mGrassDataType == DCELL_TYPE )
{

View File

@ -83,7 +83,7 @@ void QgsGeomColumnTypeThread::run()
if ( !layerProperty.geometryColName.isNull() &&
( layerProperty.types.value( 0, QgsWkbTypes::Unknown ) == QgsWkbTypes::Unknown ||
layerProperty.srids.value( 0, INT_MIN ) == INT_MIN ) )
layerProperty.srids.value( 0, std::numeric_limits<int>::min() ) == std::numeric_limits<int>::min() ) )
{
if ( dontResolveType )
{

View File

@ -60,7 +60,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
{
tip = tr( "Specify a geometry type in the '%1' column" ).arg( tr( "Data Type" ) );
}
else if ( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN )
else if ( wkbType != QgsWkbTypes::NoGeometry && srid == std::numeric_limits<int>::min() )
{
tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) );
}
@ -82,7 +82,7 @@ void QgsPgTableModel::addTableEntry( const QgsPostgresLayerProperty &layerProper
QStandardItem *commentItem = new QStandardItem( layerProperty.tableComment );
QStandardItem *geomItem = new QStandardItem( layerProperty.geometryColName );
QStandardItem *sridItem = new QStandardItem( wkbType != QgsWkbTypes::NoGeometry ? QString::number( srid ) : QLatin1String( "" ) );
sridItem->setEditable( wkbType != QgsWkbTypes::NoGeometry && srid == INT_MIN );
sridItem->setEditable( wkbType != QgsWkbTypes::NoGeometry && srid == std::numeric_limits<int>::min() );
if ( sridItem->isEditable() )
{
sridItem->setText( tr( "Enter…" ) );
@ -264,7 +264,7 @@ bool QgsPgTableModel::setData( const QModelIndex &idx, const QVariant &value, in
bool ok;
int srid = idx.sibling( idx.row(), DbtmSrid ).data().toInt( &ok );
if ( !ok || srid == INT_MIN )
if ( !ok || srid == std::numeric_limits<int>::min() )
tip = tr( "Enter a SRID into the '%1' column" ).arg( tr( "SRID" ) );
}

View File

@ -540,11 +540,11 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
bool isMaterializedView = relkind == QLatin1String( "m" );
QString comment = result.PQgetvalue( idx, 7 );
int srid = ssrid.isEmpty() ? INT_MIN : ssrid.toInt();
int srid = ssrid.isEmpty() ? std::numeric_limits<int>::min() : ssrid.toInt();
if ( majorVersion() >= 2 && srid == 0 )
{
// 0 doesn't constraint => detect
srid = INT_MIN;
srid = std::numeric_limits<int>::min();
}
#if 0
@ -665,7 +665,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
//QgsDebugMsg( QString( "%1.%2.%3: %4" ).arg( schemaName ).arg( tableName ).arg( column ).arg( relkind ) );
layerProperty.types = QList<QgsWkbTypes::Type>() << QgsWkbTypes::Unknown;
layerProperty.srids = QList<int>() << INT_MIN;
layerProperty.srids = QList<int>() << std::numeric_limits<int>::min();
layerProperty.schemaName = schemaName;
layerProperty.tableName = tableName;
layerProperty.geometryColName = column;
@ -754,7 +754,7 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
//QgsDebugMsg( QString( "%1.%2: %3" ).arg( schema ).arg( table ).arg( relkind ) );
layerProperty.types = QList<QgsWkbTypes::Type>() << QgsWkbTypes::NoGeometry;
layerProperty.srids = QList<int>() << INT_MIN;
layerProperty.srids = QList<int>() << std::numeric_limits<int>::min();
layerProperty.schemaName = schema;
layerProperty.tableName = table;
layerProperty.geometryColName = QString();
@ -1486,8 +1486,8 @@ void QgsPostgresConn::retrieveLayerTypes( QgsPostgresLayerProperty &layerPropert
query += ',';
int srid = layerProperty.srids.value( 0, INT_MIN );
if ( srid == INT_MIN )
int srid = layerProperty.srids.value( 0, std::numeric_limits<int>::min() );
if ( srid == std::numeric_limits<int>::min() )
{
query += QStringLiteral( "%1(%2%3)" )
.arg( majorVersion() < 2 ? "srid" : "st_srid",

View File

@ -555,7 +555,7 @@ QVector<QgsDataItem *> QgsPGSchemaItem::createChildren()
if ( !layerProperty.geometryColName.isNull() &&
( layerProperty.types.value( 0, QgsWkbTypes::Unknown ) == QgsWkbTypes::Unknown ||
layerProperty.srids.value( 0, INT_MIN ) == INT_MIN ) )
layerProperty.srids.value( 0, std::numeric_limits<int>::min() ) == std::numeric_limits<int>::min() ) )
{
if ( dontResolveType )
{

View File

@ -67,14 +67,14 @@ namespace QgsWms
return false;
}
int rMin = INT_MAX;
int gMin = INT_MAX;
int bMin = INT_MAX;
int aMin = INT_MAX;
int rMax = INT_MIN;
int gMax = INT_MIN;
int bMax = INT_MIN;
int aMax = INT_MIN;
int rMin = std::numeric_limits<int>::max();
int gMin = std::numeric_limits<int>::max();
int bMin = std::numeric_limits<int>::max();
int aMin = std::numeric_limits<int>::max();
int rMax = std::numeric_limits<int>::min();
int gMax = std::numeric_limits<int>::min();
int bMax = std::numeric_limits<int>::min();
int aMax = std::numeric_limits<int>::min();
int currentRed = 0;
int currentGreen = 0;

View File

@ -17,6 +17,11 @@ HINTS[2]="Use the type-safe method std::numeric_limits<double>::min() instead (b
KEYWORDS[3]="DBL_EPSILON"
HINTS[3]="Use the type-safe method std::numeric_limits<double>::epsilon() instead"
KEYWORDS[4]="INT_MIN"
HINTS[4]="Use the type-safe method std::numeric_limits<int>::min() instead"
KEYWORDS[5]="INT_MAX"
HINTS[5]="Use the type-safe method std::numeric_limits<int>::max() instead"
RES=
DIR=$(git rev-parse --show-toplevel)