Skip to content

Commit

Permalink
Localize loop variables in ogr
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/gdal/trunk@35129 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Aug 16, 2016
1 parent 684d278 commit b54e481
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 109 deletions.
10 changes: 5 additions & 5 deletions gdal/ogr/ogr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void CPL_DLL OGR_G_SetPoints( OGRGeometryH hGeom, int nPointsIn,
{
poSC->setNumPoints( nPointsIn );

for (int i = 0; i < nPointsIn; ++i)
for( int i = 0; i < nPointsIn; ++i )
{
double x = *(double*)((char*)pabyX + i * nXStride);
double y = *(double*)((char*)pabyY + i * nYStride);
Expand Down Expand Up @@ -705,7 +705,7 @@ void CPL_DLL OGR_G_SetPointsZM( OGRGeometryH hGeom, int nPointsIn,

if (!pabyZ && !pabyM)
{
for (int i = 0; i < nPointsIn; ++i)
for( int i = 0; i < nPointsIn; ++i )
{
double x = *(double*)((char*)pabyX + i * nXStride);
double y = *(double*)((char*)pabyY + i * nYStride);
Expand All @@ -714,7 +714,7 @@ void CPL_DLL OGR_G_SetPointsZM( OGRGeometryH hGeom, int nPointsIn,
}
else if (pabyZ && !pabyM)
{
for (int i = 0; i < nPointsIn; ++i)
for( int i = 0; i < nPointsIn; ++i )
{
double x = *(double*)((char*)pabyX + i * nXStride);
double y = *(double*)((char*)pabyY + i * nYStride);
Expand All @@ -724,7 +724,7 @@ void CPL_DLL OGR_G_SetPointsZM( OGRGeometryH hGeom, int nPointsIn,
}
else if (!pabyZ && pabyM)
{
for (int i = 0; i < nPointsIn; ++i)
for( int i = 0; i < nPointsIn; ++i )
{
double x = *(double*)((char*)pabyX + i * nXStride);
double y = *(double*)((char*)pabyY + i * nYStride);
Expand All @@ -734,7 +734,7 @@ void CPL_DLL OGR_G_SetPointsZM( OGRGeometryH hGeom, int nPointsIn,
}
else
{
for (int i = 0; i < nPointsIn; ++i)
for( int i = 0; i < nPointsIn; ++i )
{
double x = *(double*)((char*)pabyX + i * nXStride);
double y = *(double*)((char*)pabyY + i * nYStride);
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogr_fromepsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ int EPSGGetWGS84Transform( int nGeogCS, std::vector<CPLString>& asTransform )
return FALSE;

asTransform.resize(0);
for(int iField = 0; iField < 7; iField++ )
for( int iField = 0; iField < 7; iField++ )
{
const char* pszValue = papszLine[iDXField+iField];
if( pszValue[0] )
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogr_geocoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ static OGRLayerH OGRGeocodeBuildLayerYahoo(CPLXMLNode* psResultSet,
}

CPLString osDisplayName;
for( int i=1; ; ++i)
for( int i = 1; ; ++i )
{
const int nIdx =
poFDefn->GetFieldIndex(CPLSPrintf("line%d", i));
Expand Down
25 changes: 14 additions & 11 deletions gdal/ogr/ograpispy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,24 @@ static std::map<OGRFieldDefnH, CPLString> oGlobalMapFieldDefn;
void FeatureDefnDescription::Free()
{
{
std::map<OGRGeomFieldDefnH, int>::iterator oIter = oMapGeomFieldDefn.begin();
for(; oIter != oMapGeomFieldDefn.end(); ++oIter)
std::map<OGRGeomFieldDefnH, int>::iterator oIter =
oMapGeomFieldDefn.begin();
for( ; oIter != oMapGeomFieldDefn.end(); ++oIter )
oGlobalMapGeomFieldDefn.erase(oIter->first);
}
{
std::map<OGRFieldDefnH, int>::iterator oIter = oMapFieldDefn.begin();
for(; oIter != oMapFieldDefn.end(); ++oIter)
std::map<OGRFieldDefnH, int>::iterator oIter =
oMapFieldDefn.begin();
for( ; oIter != oMapFieldDefn.end(); ++oIter )
oGlobalMapFieldDefn.erase(oIter->first);
}
}

DatasetDescription::~DatasetDescription()
{
std::map<OGRLayerH, LayerDescription>::iterator oIter = oMapLayer.begin();
for(; oIter != oMapLayer.end(); ++oIter)
std::map<OGRLayerH, LayerDescription>::iterator oIter =
oMapLayer.begin();
for( ; oIter != oMapLayer.end(); ++oIter )
oGlobalMapLayer.erase(oIter->first);
}

Expand Down Expand Up @@ -186,7 +189,7 @@ static CPLString OGRAPISpyGetOptions(char** papszOptions)
else
{
options = "[";
for(char** papszIter = papszOptions; *papszIter != NULL; papszIter++)
for( char** papszIter = papszOptions; *papszIter != NULL; papszIter++ )
{
if( papszIter != papszOptions )
options += ", ";
Expand Down Expand Up @@ -472,7 +475,7 @@ int OGRAPISpyOpenTakeSnapshot(const char* pszName, int bUpdate)
fprintf(fpSpyFile, "except:\n");
fprintf(fpSpyFile, " pass\n");
fprintf(fpSpyFile, "os.mkdir('%s')\n", osWorkingDir.c_str());
for(char** papszIter = papszFileList; *papszIter; papszIter++)
for( char** papszIter = papszFileList; *papszIter; papszIter++ )
{
CPLString osSnapshotSrcFile = CPLFormFilename(
osSrcDir, CPLGetFilename(*papszIter), NULL);
Expand Down Expand Up @@ -533,17 +536,17 @@ void OGRAPISpyPostClose()
if( !GDALIsInGlobalDestructor() )
{
std::map<OGRFeatureDefnH, FeatureDefnDescription>::iterator oIter =
oMapFDefn.begin();
oMapFDefn.begin();
std::vector<OGRFeatureDefnH> oArray;
for(; oIter != oMapFDefn.end(); ++oIter)
for( ; oIter != oMapFDefn.end(); ++oIter )
{
FeatureDefnDescription& featureDefnDescription = oIter->second;
if( ((OGRFeatureDefn*)featureDefnDescription.hFDefn)->GetReferenceCount() == 1 )
{
oArray.push_back(featureDefnDescription.hFDefn);
}
}
for(size_t i = 0; i < oArray.size(); i++)
for( size_t i = 0; i < oArray.size(); i++ )
{
FeatureDefnDescription& featureDefnDescription = oMapFDefn[oArray[i]];
((OGRFeatureDefn*)featureDefnDescription.hFDefn)->Release();
Expand Down
10 changes: 5 additions & 5 deletions gdal/ogr/ograssemblepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ OGRGeometryH OGRBuildPolygonFromEdges( OGRGeometryH hLines,
OGRGeometry* poGeom = (OGRGeometry*) hLines;
if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection )
{
int iGeom;
OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;

for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
for( int iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )
{
if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType())
!= wkbLineString )
Expand Down Expand Up @@ -202,7 +201,7 @@ OGRGeometryH OGRBuildPolygonFromEdges( OGRGeometryH hLines,
/* -------------------------------------------------------------------- */
/* Find the first unconsumed edge. */
/* -------------------------------------------------------------------- */
int iEdge = 0;
int iEdge = 0; // Used after for.
for( ; panEdgeConsumed[iEdge]; iEdge++ ) {}

OGRLineString *poLine =
Expand Down Expand Up @@ -234,7 +233,6 @@ OGRGeometryH OGRBuildPolygonFromEdges( OGRGeometryH hLines,
&& nRemainingEdges > 0
&& bWorkDone )
{
int iBestEdge = -1;
bool bReverse = false;

bWorkDone = false;
Expand All @@ -243,9 +241,11 @@ OGRGeometryH OGRBuildPolygonFromEdges( OGRGeometryH hLines,
// We consider linking the end to the beginning. If this is
// closer than any other option we will just close the loop.

//CheckPoints(poRing,0,poRing,poRing->getNumPoints()-1,&dfBestDist);
// CheckPoints(poRing, 0, poRing, poRing->getNumPoints()-1,
// &dfBestDist);

// Find unused edge with end point closest to our loose end.
int iBestEdge = -1;
for( iEdge = 0; iEdge < nEdges; iEdge++ )
{
if( panEdgeConsumed[iEdge] )
Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrcompoundcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ OGRLineString* OGRCompoundCurve::CastToLineString(OGRCompoundCurve* poCC)

OGRLinearRing* OGRCompoundCurve::CastToLinearRing(OGRCompoundCurve* poCC)
{
for(int i=0;i<poCC->oCC.nCurveCount;i++)
for( int i = 0; i < poCC->oCC.nCurveCount; i++ )
{
poCC->oCC.papoCurves[i] = OGRCurve::CastToLineString(poCC->oCC.papoCurves[i]);
if( poCC->oCC.papoCurves[i] == NULL )
Expand Down Expand Up @@ -829,7 +829,7 @@ double OGRCompoundCurve::get_Area() const
OGRLineString oLS;
oLS.setNumPoints( getNumPoints() );
OGRPoint p;
for(int i = 0; poIter->getNextPoint(&p); i++ )
for( int i = 0; poIter->getNextPoint(&p); i++ )
{
oLS.setPoint( i, p.getX(), p.getY() );
}
Expand Down
7 changes: 3 additions & 4 deletions gdal/ogr/ogrcurvecollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom,

{
char **papszGeoms;
int iGeom;
size_t nCumulativeLength = 0;
OGRErr eErr;

Expand All @@ -310,7 +309,7 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom,
/* -------------------------------------------------------------------- */
papszGeoms = (char **) CPLCalloc(sizeof(char *),nCurveCount);

for( iGeom = 0; iGeom < nCurveCount; iGeom++ )
for( int iGeom = 0; iGeom < nCurveCount; iGeom++ )
{
eErr = papoCurves[iGeom]->exportToWkt( &(papszGeoms[iGeom]), wkbVariantIso );
if( eErr != OGRERR_NONE )
Expand Down Expand Up @@ -344,7 +343,7 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom,
strcat( *ppszDstText, " (" );
nCumulativeLength = strlen(*ppszDstText);

for( iGeom = 0; iGeom < nCurveCount; iGeom++ )
for( int iGeom = 0; iGeom < nCurveCount; iGeom++ )
{
if( iGeom > 0 )
(*ppszDstText)[nCumulativeLength++] = ',';
Expand Down Expand Up @@ -377,7 +376,7 @@ OGRErr OGRCurveCollection::exportToWkt( const OGRGeometry* poGeom,
return OGRERR_NONE;

error:
for( iGeom = 0; iGeom < nCurveCount; iGeom++ )
for( int iGeom = 0; iGeom < nCurveCount; iGeom++ )
CPLFree( papszGeoms[iGeom] );
CPLFree( papszGeoms );
return eErr;
Expand Down
6 changes: 2 additions & 4 deletions gdal/ogr/ogrcurvepolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,9 @@ double OGRCurvePolygon::get_Area() const

if( getExteriorRingCurve() != NULL )
{
int iRing;

dfArea = getExteriorRingCurve()->get_Area();

for( iRing = 0; iRing < getNumInteriorRings(); iRing++ )
for( int iRing = 0; iRing < getNumInteriorRings(); iRing++ )
{
dfArea -= getInteriorRingCurve(iRing)->get_Area();
}
Expand Down Expand Up @@ -770,7 +768,7 @@ OGRBoolean OGRCurvePolygon::Intersects( const OGRGeometry *poOtherGeom ) const

OGRPolygon* OGRCurvePolygon::CastToPolygon(OGRCurvePolygon* poCP)
{
for(int i=0;i<poCP->oCC.nCurveCount;i++)
for( int i = 0; i < poCP->oCC.nCurveCount; i++ )
{
poCP->oCC.papoCurves[i] = OGRCurve::CastToLinearRing(poCP->oCC.papoCurves[i]);
if( poCP->oCC.papoCurves[i] == NULL )
Expand Down
31 changes: 16 additions & 15 deletions gdal/ogr/ogrfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3481,7 +3481,7 @@ void OGRFeature::SetField( int iField, int nCount, int *panValues )

if( poFDefn->GetSubType() == OFSTBoolean || poFDefn->GetSubType() == OFSTInt16 )
{
for( int i=0;i<nCount;i++)
for( int i = 0; i < nCount; i++ )
{
int nVal = OGRFeatureGetIntegerValue(poFDefn, panValues[i]);
if( panValues[i] != nVal )
Expand Down Expand Up @@ -3510,7 +3510,7 @@ void OGRFeature::SetField( int iField, int nCount, int *panValues )
{
std::vector<GIntBig> anValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
anValues.push_back( panValues[i] );

SetField( iField, nCount, &anValues[0] );
Expand All @@ -3519,7 +3519,7 @@ void OGRFeature::SetField( int iField, int nCount, int *panValues )
{
std::vector<double> adfValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
adfValues.push_back( (double) panValues[i] );

SetField( iField, nCount, &adfValues[0] );
Expand All @@ -3537,7 +3537,7 @@ void OGRFeature::SetField( int iField, int nCount, int *panValues )
VSI_MALLOC_VERBOSE((nCount+1) * sizeof(char*)) );
if( papszValues == NULL )
return;
for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
papszValues[i] = VSI_STRDUP_VERBOSE(CPLSPrintf("%d", panValues[i]));
papszValues[nCount] = NULL;
SetField( iField, papszValues);
Expand Down Expand Up @@ -3615,7 +3615,7 @@ void OGRFeature::SetField( int iField, int nCount, const GIntBig *panValues )
{
std::vector<int> anValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
{
GIntBig nValue = panValues[i];
int nVal32 = (nValue < INT_MIN ) ? INT_MIN :
Expand Down Expand Up @@ -3645,7 +3645,7 @@ void OGRFeature::SetField( int iField, int nCount, const GIntBig *panValues )
{
std::vector<double> adfValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
adfValues.push_back( (double) panValues[i] );

SetField( iField, nCount, &adfValues[0] );
Expand All @@ -3663,7 +3663,7 @@ void OGRFeature::SetField( int iField, int nCount, const GIntBig *panValues )
VSI_MALLOC_VERBOSE((nCount+1) * sizeof(char*)) );
if( papszValues == NULL )
return;
for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
papszValues[i] = VSI_STRDUP_VERBOSE(CPLSPrintf(CPL_FRMT_GIB, panValues[i]));
papszValues[nCount] = NULL;
SetField( iField, papszValues);
Expand Down Expand Up @@ -3751,7 +3751,7 @@ void OGRFeature::SetField( int iField, int nCount, double * padfValues )
{
std::vector<int> anValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
anValues.push_back( (int) padfValues[i] );

SetField( iField, nCount, &anValues[0] );
Expand All @@ -3760,7 +3760,7 @@ void OGRFeature::SetField( int iField, int nCount, double * padfValues )
{
std::vector<GIntBig> anValues;

for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
anValues.push_back( (GIntBig) padfValues[i] );

SetField( iField, nCount, &anValues[0] );
Expand All @@ -3778,7 +3778,7 @@ void OGRFeature::SetField( int iField, int nCount, double * padfValues )
VSI_MALLOC_VERBOSE((nCount+1) * sizeof(char*)) );
if( papszValues == NULL )
return;
for( int i=0; i < nCount; i++ )
for( int i = 0; i < nCount; i++ )
papszValues[i] = VSI_STRDUP_VERBOSE(CPLSPrintf("%.16g", padfValues[i]));
papszValues[nCount] = NULL;
SetField( iField, papszValues);
Expand Down Expand Up @@ -3864,7 +3864,7 @@ void OGRFeature::SetField( int iField, char ** papszValues )
VSI_MALLOC_VERBOSE(nValues * sizeof(int)) );
if( panValues == NULL )
return;
for(int i=0;i<nValues;i++)
for( int i = 0; i < nValues; i++ )
{
errno = 0; /* As allowed by C standard, some systems like MSVC doesn't reset errno */
int nVal = atoi(papszValues[i]);
Expand All @@ -3890,7 +3890,7 @@ void OGRFeature::SetField( int iField, char ** papszValues )
VSI_MALLOC_VERBOSE(nValues * sizeof(GIntBig)) );
if( panValues == NULL )
return;
for(int i=0;i<nValues;i++)
for( int i = 0; i < nValues; i++ )
{
panValues[i] = CPLAtoGIntBigEx(papszValues[i], TRUE, NULL);
}
Expand All @@ -3904,7 +3904,7 @@ void OGRFeature::SetField( int iField, char ** papszValues )
VSI_MALLOC_VERBOSE(nValues * sizeof(double)) );
if( padfValues == NULL )
return;
for(int i=0;i<nValues;i++)
for( int i = 0; i < nValues; i++ )
{
padfValues[i] = CPLAtof(papszValues[i]);
}
Expand Down Expand Up @@ -4352,8 +4352,9 @@ bool OGRFeature::SetFieldInternal( int iField, OGRField * puValue )
else
{
char** papszNewList = NULL;
char** papszIter = puValue->StringList.paList;
for(; papszIter != NULL && *papszIter != NULL; ++papszIter )
for( char** papszIter = puValue->StringList.paList;
papszIter != NULL && *papszIter != NULL;
++papszIter )
{
char** papszNewList2 = CSLAddStringMayFail(papszNewList, *papszIter);
if( papszNewList2 == NULL )
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrfeaturedefn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ OGRErr OGRFeatureDefn::ReorderFieldDefns( int* panMap )
OGRFieldDefn** papoFieldDefnNew = (OGRFieldDefn**)
CPLMalloc(sizeof(OGRFieldDefn*) * nFieldCount);

for(int i=0;i<nFieldCount;i++)
for( int i = 0; i < nFieldCount; i++ )
{
papoFieldDefnNew[i] = papoFieldDefn[panMap[i]];
}
Expand Down
Loading

0 comments on commit b54e481

Please sign in to comment.