Skip to content

Commit

Permalink
Combined pointer definition and initialization in ogrsf_frmts/ntf
Browse files Browse the repository at this point in the history
Also:
- Localize vars
- Fix formatting
- Initialize vars
- Balance {}
- Define one var per line

git-svn-id: https://svn.osgeo.org/gdal/trunk@35144 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Aug 18, 2016
1 parent fa6b1c3 commit 5a84488
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 143 deletions.
53 changes: 24 additions & 29 deletions gdal/ogr/ogrsf_frmts/ntf/ntf_estlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,24 +624,24 @@ static OGRFeature *TranslateBoundarylinePoly( NTFFileReader *poReader,
/* boundaries are. The boundary information will be emitted */
/* in the RingStart field. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poLayer->GetLayerDefn() );
int nNumLink = 0;
int anDirList[MAX_LINK*2], anGeomList[MAX_LINK*2];
int anRingStart[MAX_LINK], nRings = 0;
OGRFeature *poFeature = new OGRFeature( poLayer->GetLayerDefn() );
int nNumLink = 0;
int anDirList[MAX_LINK*2] = {};
int anGeomList[MAX_LINK*2] = {};
int anRingStart[MAX_LINK] = {};
int nRings = 0;

for( iRec = 0;
papoGroup[iRec] != NULL && papoGroup[iRec+1] != NULL
&& papoGroup[iRec]->GetType() == NRT_POLYGON
&& papoGroup[iRec+1]->GetType() == NRT_CHAIN;
iRec += 2 )
{
int i, nLineCount;

nLineCount = atoi(papoGroup[iRec+1]->GetField(9,12));
const int nLineCount = atoi(papoGroup[iRec+1]->GetField(9,12));

anRingStart[nRings++] = nNumLink;

for( i = 0; i < nLineCount && nNumLink < MAX_LINK*2; i++ )
for( int i = 0; i < nLineCount && nNumLink < MAX_LINK*2; i++ )
{
anDirList[nNumLink] =
atoi(papoGroup[iRec+1]->GetField( 19+i*7, 19+i*7 ));
Expand Down Expand Up @@ -821,24 +821,24 @@ static OGRFeature *TranslateBL2000Poly( NTFFileReader *poReader,
/* boundaries are. The boundary information will be emitted */
/* in the RingStart field. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = new OGRFeature( poLayer->GetLayerDefn() );
int nNumLink = 0;
int anDirList[MAX_LINK*2], anGeomList[MAX_LINK*2];
int anRingStart[MAX_LINK], nRings = 0;
OGRFeature *poFeature = new OGRFeature( poLayer->GetLayerDefn() );
int nNumLink = 0;
int anDirList[MAX_LINK*2] = {};
int anGeomList[MAX_LINK*2] = {};
int anRingStart[MAX_LINK] = {};
int nRings = 0;

for( iRec = 0;
papoGroup[iRec] != NULL && papoGroup[iRec+1] != NULL
&& papoGroup[iRec]->GetType() == NRT_POLYGON
&& papoGroup[iRec+1]->GetType() == NRT_CHAIN;
iRec += 2 )
{
int i, nLineCount;

nLineCount = atoi(papoGroup[iRec+1]->GetField(9,12));
const int nLineCount = atoi(papoGroup[iRec+1]->GetField(9,12));

anRingStart[nRings++] = nNumLink;

for( i = 0; i < nLineCount && nNumLink < MAX_LINK*2; i++ )
for( int i = 0; i < nLineCount && nNumLink < MAX_LINK*2; i++ )
{
anDirList[nNumLink] =
atoi(papoGroup[iRec+1]->GetField( 19+i*7, 19+i*7 ));
Expand Down Expand Up @@ -1675,15 +1675,11 @@ void NTFFileReader::EstablishLayer( const char * pszLayerName,
... )

{
va_list hVaArgs;
OGRFeatureDefn *poDefn;
OGRNTFLayer *poLayer;

/* -------------------------------------------------------------------- */
/* Does this layer already exist? If so, we do nothing */
/* ... note that we don't check the definition. */
/* -------------------------------------------------------------------- */
poLayer = poDS->GetNamedLayer(pszLayerName);
OGRNTFLayer *poLayer = poDS->GetNamedLayer(pszLayerName);

/* ==================================================================== */
/* Create a new layer matching the request if we don't already */
Expand All @@ -1694,29 +1690,28 @@ void NTFFileReader::EstablishLayer( const char * pszLayerName,
/* -------------------------------------------------------------------- */
/* Create a new feature definition. */
/* -------------------------------------------------------------------- */
poDefn = new OGRFeatureDefn( pszLayerName );
OGRFeatureDefn *poDefn = new OGRFeatureDefn( pszLayerName );
poDefn->GetGeomFieldDefn(0)->SetSpatialRef(poDS->GetSpatialRef());
poDefn->SetGeomType( eGeomType );
poDefn->Reference();

/* -------------------------------------------------------------------- */
/* Fetch definitions of each field in turn. */
/* -------------------------------------------------------------------- */
va_list hVaArgs;
va_start(hVaArgs, poClass);
while( true )
{
const char *pszFieldName = va_arg(hVaArgs, const char *);
OGRFieldType eType;
int nWidth, nPrecision;
const char *pszFieldName = va_arg(hVaArgs, const char *);

if( pszFieldName == NULL )
break;

eType = (OGRFieldType) va_arg(hVaArgs, int);
nWidth = va_arg(hVaArgs, int);
nPrecision = va_arg(hVaArgs, int);
const OGRFieldType eType = (OGRFieldType) va_arg(hVaArgs, int);
const int nWidth = va_arg(hVaArgs, int);
const int nPrecision = va_arg(hVaArgs, int);

OGRFieldDefn oFieldDefn( pszFieldName, eType );
OGRFieldDefn oFieldDefn( pszFieldName, eType );
oFieldDefn.SetWidth( nWidth );
oFieldDefn.SetPrecision( nPrecision );

Expand Down
16 changes: 7 additions & 9 deletions gdal/ogr/ogrsf_frmts/ntf/ntf_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,8 @@ void OGRNTFDataSource::WorkupGeneric( NTFFileReader * poReader )

for( int iAtt = 0; papszTypes[iAtt] != NULL; iAtt++ )
{
NTFAttDesc *poAttDesc;

poAttDesc = poReader->GetAttDesc( papszTypes[iAtt] );
NTFAttDesc *poAttDesc =
poReader->GetAttDesc( papszTypes[iAtt] );
if( poAttDesc != NULL )
{
poClass->CheckAddAttr( poAttDesc->val_type,
Expand Down Expand Up @@ -258,9 +257,8 @@ void OGRNTFDataSource::WorkupGeneric( NTFFileReader * poReader )
case NRT_LINEREC:
if( poReader->GetNTFLevel() < 3 )
{
NTFAttDesc *poAttDesc;

poAttDesc = poReader->GetAttDesc(poRecord->GetField(9,10));
NTFAttDesc *poAttDesc =
poReader->GetAttDesc(poRecord->GetField(9,10));
if( poAttDesc != NULL )
poClass->CheckAddAttr( poAttDesc->val_type,
poAttDesc->finter, 6 );
Expand Down Expand Up @@ -635,7 +633,7 @@ static OGRFeature *TranslateGenericPoint( NTFFileReader *poReader,
snprintf( szValType, sizeof(szValType), "%s", papoGroup[0]->GetField(9,10) );
if( !EQUAL(szValType," ") )
{
char *pszProcessedValue;
char *pszProcessedValue = NULL;

if( poReader->ProcessAttValue(szValType,
papoGroup[0]->GetField(11,16),
Expand Down Expand Up @@ -682,12 +680,12 @@ static OGRFeature *TranslateGenericLine( NTFFileReader *poReader,
// Handle singular attribute in pre-level 3 LINEREC.
if( poReader->GetNTFLevel() < 3 )
{
char szValType[3];
char szValType[3] = {};

snprintf( szValType, sizeof(szValType), "%s", papoGroup[0]->GetField(9,10) );
if( !EQUAL(szValType," ") )
{
char *pszProcessedValue;
char *pszProcessedValue = NULL;

if( poReader->ProcessAttValue(szValType,
papoGroup[0]->GetField(11,16),
Expand Down
16 changes: 5 additions & 11 deletions gdal/ogr/ogrsf_frmts/ntf/ntf_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void NTFFileReader::EstablishRasterAccess()
/* -------------------------------------------------------------------- */
/* Read the type 50 record. */
/* -------------------------------------------------------------------- */
NTFRecord *poRecord;
NTFRecord *poRecord = NULL;

while( (poRecord = ReadRecord()) != NULL
&& poRecord->GetType() != NRT_GRIDHREC
Expand Down Expand Up @@ -152,9 +152,7 @@ CPLErr NTFFileReader::ReadRasterColumn( int iColumn, float *pafElev )
/* -------------------------------------------------------------------- */
if( panColumnOffset[iColumn] == 0 )
{
int iPrev;

for( iPrev = 0; iPrev < iColumn-1; iPrev++ )
for( int iPrev = 0; iPrev < iColumn-1; iPrev++ )
{
if( panColumnOffset[iPrev+1] == 0 )
{
Expand All @@ -176,10 +174,8 @@ CPLErr NTFFileReader::ReadRasterColumn( int iColumn, float *pafElev )
/* -------------------------------------------------------------------- */
/* Read requested record. */
/* -------------------------------------------------------------------- */
NTFRecord *poRecord;

SetFPPos( panColumnOffset[iColumn], iColumn );
poRecord = ReadRecord();
NTFRecord *poRecord = ReadRecord();

if( iColumn < nRasterXSize-1 )
{
Expand All @@ -191,10 +187,8 @@ CPLErr NTFFileReader::ReadRasterColumn( int iColumn, float *pafElev )
/* -------------------------------------------------------------------- */
if( pafElev != NULL && GetProductId() == NPC_LANDRANGER_DTM )
{
double dfVScale, dfVOffset;

dfVOffset = atoi(poRecord->GetField(56,65));
dfVScale = atoi(poRecord->GetField(66,75)) * 0.001;
const double dfVOffset = atoi(poRecord->GetField(56,65));
const double dfVScale = atoi(poRecord->GetField(66,75)) * 0.001;

for( int iPixel = 0; iPixel < nRasterXSize; iPixel++ )
{
Expand Down
Loading

0 comments on commit 5a84488

Please sign in to comment.