Skip to content

Commit

Permalink
Combine pointer definition and initialization in ogr.
Browse files Browse the repository at this point in the history
Also:
- Localize vars
- if(a) b = c; else b = d; -> b = a ? b : d;
- Fix formatting
- Fit to 80 cols
- /* */ -> //
- Add const to local vars

git-svn-id: https://svn.osgeo.org/gdal/trunk@35136 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
schwehr committed Aug 17, 2016
1 parent c8a6b54 commit 318b518
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 302 deletions.
3 changes: 1 addition & 2 deletions gdal/ogr/ogr_geocoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,6 @@ static OGRLayerH OGRGeocodeCommon( OGRGeocodingSessionH hSession,
pszCachedResult = OGRGeocodeGetFromCache(hSession, osURL);
if( pszCachedResult == NULL )
{
CPLHTTPResult* psResult;

double* pdfLastQueryTime = NULL;
if( EQUAL(hSession->pszGeocodingService, "OSM_NOMINATIM") )
pdfLastQueryTime = &dfLastQueryTimeStampOSMNominatim;
Expand All @@ -1302,6 +1300,7 @@ static OGRLayerH OGRGeocodeCommon( OGRGeocodingSessionH hSession,
char** papszHTTPOptions = CSLAddNameValue(NULL, "HEADERS",
osHeaders.c_str());

CPLHTTPResult* psResult = NULL;
if( pdfLastQueryTime != NULL )
{
CPLMutexHolderD(&hMutex);
Expand Down
11 changes: 3 additions & 8 deletions gdal/ogr/ogr_srs_pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ OGRErr OGRSpatialReference::importFromPCI( const char *pszProj,
/* D-02 or D109. */
/* -------------------------------------------------------------------- */
char szEarthModel[5];
const char *pszEM;
int bIsNAD27 = FALSE;

strcpy( szEarthModel, "" );
pszEM = pszProj + strlen(pszProj) - 1;
const char *pszEM = pszProj + strlen(pszProj) - 1;
while( pszEM != pszProj )
{
if( *pszEM == 'e' || *pszEM == 'E' || *pszEM == 'd' || *pszEM == 'D' )
Expand Down Expand Up @@ -1304,12 +1303,8 @@ OGRErr OGRSpatialReference::exportToPCI( char **ppszProj, char **ppszUnits,
/* -------------------------------------------------------------------- */
/* Translate the linear units. */
/* -------------------------------------------------------------------- */
const char *pszUnits;

if( STARTS_WITH_CI(szProj, "LONG/LAT") )
pszUnits = "DEGREE";
else
pszUnits = "METRE";
const char *pszUnits =
STARTS_WITH_CI(szProj, "LONG/LAT") ? "DEGREE" : "METRE";

/* -------------------------------------------------------------------- */
/* Report results. */
Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogr_srs_proj4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ OGRErr OGRSpatialReference::importFromProj4( const char * pszProj4 )
/* Preserve authority (for example IGNF) */
/* -------------------------------------------------------------------- */
const char *pszINIT = CSLFetchNameValue(papszNV,"init");
const char *pszColumn;
const char *pszColumn = NULL;
if( pszINIT != NULL && (pszColumn = strchr(pszINIT, ':')) != NULL &&
GetRoot()->FindChild( "AUTHORITY" ) < 0 )
{
Expand Down
9 changes: 4 additions & 5 deletions gdal/ogr/ogr_srs_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,12 +1229,11 @@ OGRErr OGRSpatialReference::ValidateProjection(OGR_SRSNode *poRoot)
/* -------------------------------------------------------------------- */
/* Find the matching group in the proj and parms table. */
/* -------------------------------------------------------------------- */
const char *pszProjection;
int iOffset;
const char *pszProjection =
poPROJCS->GetNode("PROJECTION")->GetChild(0)->GetValue();

pszProjection = poPROJCS->GetNode("PROJECTION")->GetChild(0)->GetValue();

for( iOffset = 0;
int iOffset = 0; // Used after for.
for( ;
papszProjWithParms[iOffset] != NULL
&& !EQUAL(papszProjWithParms[iOffset],pszProjection); )
{
Expand Down
69 changes: 25 additions & 44 deletions gdal/ogr/ogr_srs_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,12 @@ static void addGMLId( CPLXMLNode *psParent )
static CPLMutex *hGMLIdMutex = NULL;
CPLMutexHolderD( &hGMLIdMutex );

/* CPLXMLNode *psId; */
static int nNextGMLId = 1;
char szIdText[40];

snprintf( szIdText, sizeof(szIdText), "ogrcrs%d", nNextGMLId++ );

/* psId = */
// CPLXMLNode *psId =
CPLCreateXMLNode(
CPLCreateXMLNode( psParent, CXT_Attribute, "gml:id" ),
CXT_Text, szIdText );
Expand All @@ -260,15 +259,13 @@ static CPLXMLNode *exportAuthorityToXML( const OGR_SRSNode *poAuthParent,
int bUseSubName = TRUE )

{
const OGR_SRSNode *poAuthority;

/* -------------------------------------------------------------------- */
/* Get authority node from parent. */
/* -------------------------------------------------------------------- */
if( poAuthParent->FindChild( "AUTHORITY" ) == -1 )
return NULL;

poAuthority = poAuthParent->GetChild(
const OGR_SRSNode *poAuthority = poAuthParent->GetChild(
poAuthParent->FindChild( "AUTHORITY" ));

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -303,12 +300,9 @@ static void addProjArg( const OGRSpatialReference *poSRS, CPLXMLNode *psBase,
/* -------------------------------------------------------------------- */
/* Handle the UOM. */
/* -------------------------------------------------------------------- */
const char *pszUOMValue;

if( EQUAL(pszMeasureType,"Angular") )
pszUOMValue = "urn:ogc:def:uom:EPSG::9102";
else
pszUOMValue = "urn:ogc:def:uom:EPSG::9001";
const char *pszUOMValue = EQUAL(pszMeasureType, "Angular")
? "urn:ogc:def:uom:EPSG::9102"
: "urn:ogc:def:uom:EPSG::9001";

CPLXMLNode *psValue
= CPLCreateXMLNode( psNode, CXT_Element, "gml:value" );
Expand Down Expand Up @@ -758,7 +752,6 @@ static void importXMLUnits( CPLXMLNode *psSrcXML, const char *pszClass,
{
const char *pszUnitName, *pszUnitsPer;
OGR_SRSNode *poNode = poSRS->GetAttrNode( pszTarget );
OGR_SRSNode *poUnits;

CPLAssert( EQUAL(pszClass,"AngularUnit")
|| EQUAL(pszClass,"LinearUnit") );
Expand Down Expand Up @@ -788,6 +781,7 @@ static void importXMLUnits( CPLXMLNode *psSrcXML, const char *pszClass,
goto DefaultTarget;
}

OGR_SRSNode *poUnits = NULL;
if( poNode->FindChild("UNIT") != -1 )
{
poUnits = poNode->GetChild( poNode->FindChild( "UNIT" ) );
Expand Down Expand Up @@ -963,9 +957,7 @@ static double getProjectionParm( CPLXMLNode *psRootNode,
double dfDefault )

{
CPLXMLNode *psUsesParameter;

for( psUsesParameter = psRootNode->psChild;
for( CPLXMLNode *psUsesParameter = psRootNode->psChild;
psUsesParameter != NULL;
psUsesParameter = psUsesParameter->psNext )
{
Expand Down Expand Up @@ -1005,18 +997,15 @@ static double getNormalizedValue( CPLXMLNode *psNode, const char *pszPath,
double dfDefault )

{
CPLXMLNode *psTargetNode;
CPLXMLNode *psValueNode;

if( pszPath == NULL || strlen(pszPath) == 0 )
psTargetNode = psNode;
else
psTargetNode = CPLGetXMLNode( psNode, pszPath );
CPLXMLNode *psTargetNode = pszPath == NULL || strlen(pszPath) == 0
? psNode
: CPLGetXMLNode( psNode, pszPath );

if( psTargetNode == NULL )
return dfDefault;

for( psValueNode = psTargetNode->psChild;
CPLXMLNode *psValueNode = psTargetNode->psChild; // Used after for.
for( ;
psValueNode != NULL && psValueNode->eType != CXT_Text;
psValueNode = psValueNode->psNext ) {}

Expand Down Expand Up @@ -1049,9 +1038,8 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS,
/* If we don't seem to have a detailed coordinate system */
/* definition, check if we can define based on an EPSG code. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psDatum;

psDatum = CPLGetXMLNode( psCRS, "usesGeodeticDatum.GeodeticDatum" );
CPLXMLNode *psDatum =
CPLGetXMLNode( psCRS, "usesGeodeticDatum.GeodeticDatum" );

if( psDatum == NULL )
{
Expand All @@ -1078,9 +1066,7 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS,
/* -------------------------------------------------------------------- */
/* Get ellipsoid information. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psE;

psE = CPLGetXMLNode( psDatum, "usesEllipsoid.Ellipsoid" );
CPLXMLNode *psE = CPLGetXMLNode( psDatum, "usesEllipsoid.Ellipsoid" );
pszEllipsoidName =
CPLGetXMLValue( psE, "ellipsoidName", "Unnamed Ellipsoid" );

Expand All @@ -1101,9 +1087,8 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS,
/* -------------------------------------------------------------------- */
/* Get the prime meridian. */
/* -------------------------------------------------------------------- */
CPLXMLNode *psPM;

psPM = CPLGetXMLNode( psDatum, "usesPrimeMeridian.PrimeMeridian" );
CPLXMLNode *psPM =
CPLGetXMLNode( psDatum, "usesPrimeMeridian.PrimeMeridian" );
if( psPM == NULL )
{
pszPMName = "Greenwich";
Expand All @@ -1130,10 +1115,9 @@ static OGRErr importGeogCSFromXML( OGRSpatialReference *poSRS,
/* at this time. */
/* -------------------------------------------------------------------- */
#ifdef notdef
CPLXMLNode *psAxis;

psAxis = CPLGetXMLNode( psGeo2DCRS,
"EllipsoidalCoordinateSystem.CoordinateAxis" );
CPLXMLNode *psAxis =
CPLGetXMLNode( psGeo2DCRS,
"EllipsoidalCoordinateSystem.CoordinateAxis" );
importXMLUnits( psAxis, "AngularUnit", poSRS, "GEOGCS" );
#endif

Expand Down Expand Up @@ -1161,9 +1145,6 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS,
CPLXMLNode *psCRS )

{
CPLXMLNode *psSubXML;
OGRErr eErr;

/* -------------------------------------------------------------------- */
/* Setup the PROJCS node with a name. */
/* -------------------------------------------------------------------- */
Expand All @@ -1189,7 +1170,8 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS,
/* Try to set the GEOGCS info. */
/* -------------------------------------------------------------------- */

psSubXML = CPLGetXMLNode( psCRS, "baseCRS.GeographicCRS" );
OGRErr eErr = OGRERR_NONE;
CPLXMLNode *psSubXML = CPLGetXMLNode( psCRS, "baseCRS.GeographicCRS" );
if( psSubXML != NULL )
{
eErr = importGeogCSFromXML( poSRS, psSubXML );
Expand Down Expand Up @@ -1267,15 +1249,12 @@ static OGRErr importProjCSFromXML( OGRSpatialReference *poSRS,
OGRErr OGRSpatialReference::importFromXML( const char *pszXML )

{
CPLXMLNode *psTree;
OGRErr eErr = OGRERR_UNSUPPORTED_SRS;

this->Clear();

/* -------------------------------------------------------------------- */
/* Parse the XML. */
/* -------------------------------------------------------------------- */
psTree = CPLParseXMLString( pszXML );
CPLXMLNode *psTree = CPLParseXMLString( pszXML );

if( psTree == NULL )
return OGRERR_CORRUPT_DATA;
Expand All @@ -1287,6 +1266,8 @@ OGRErr OGRSpatialReference::importFromXML( const char *pszXML )
/* root elements as there is sometimes prefix stuff like */
/* <?xml>. */
/* -------------------------------------------------------------------- */
OGRErr eErr = OGRERR_UNSUPPORTED_SRS;

for( CPLXMLNode* psNode = psTree; psNode != NULL; psNode = psNode->psNext )
{
if( EQUAL(psNode->pszValue,"GeographicCRS") )
Expand Down
16 changes: 6 additions & 10 deletions gdal/ogr/ogrcompoundcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ OGRErr OGRCompoundCurve::exportToWkt( char ** ppszDstText,

OGRGeometry *OGRCompoundCurve::clone() const
{
OGRCompoundCurve *poNewCC;

poNewCC = new OGRCompoundCurve;
OGRCompoundCurve *poNewCC = new OGRCompoundCurve;
poNewCC->assignSpatialReference( getSpatialReference() );
poNewCC->flags = flags;

Expand Down Expand Up @@ -341,11 +339,9 @@ OGRLineString* OGRCompoundCurve::CurveToLineInternal(double dfMaxAngleStepSizeDe
const char* const* papszOptions,
int bIsLinearRing) const
{
OGRLineString* poLine;
if( bIsLinearRing )
poLine = new OGRLinearRing();
else
poLine = new OGRLineString();
OGRLineString* const poLine = bIsLinearRing
? new OGRLinearRing()
: new OGRLineString();
poLine->assignSpatialReference(getSpatialReference());
for( int iGeom = 0; iGeom < oCC.nCurveCount; iGeom++ )
{
Expand Down Expand Up @@ -682,8 +678,8 @@ class OGRCompoundCurvePointIterator: public OGRPointIterator

public:
OGRCompoundCurvePointIterator(const OGRCompoundCurve* poCCIn) :
poCC(poCCIn), iCurCurve(0), poCurveIter(NULL) {}
~OGRCompoundCurvePointIterator() { delete poCurveIter; }
poCC(poCCIn), iCurCurve(0), poCurveIter(NULL) {}
virtual ~OGRCompoundCurvePointIterator() { delete poCurveIter; }

virtual OGRBoolean getNextPoint(OGRPoint* p);
};
Expand Down
26 changes: 11 additions & 15 deletions gdal/ogr/ogrct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,13 @@ static bool LoadProjLibrary_unlocked()

{
static bool bTriedToLoad = false;
const char *pszLibName;

if( bTriedToLoad )
return( pfn_pj_transform != NULL );
return pfn_pj_transform != NULL;

bTriedToLoad = true;

pszLibName = GetProjLibraryName();
const char *pszLibName = GetProjLibraryName();

#ifdef PROJ_STATIC
pfn_pj_init = pj_init;
Expand Down Expand Up @@ -423,8 +422,6 @@ OGRCreateCoordinateTransformation( OGRSpatialReference *poSource,
OGRSpatialReference *poTarget )

{
OGRProj4CT *poCT;

if( pfn_pj_init == NULL && !LoadProjLibrary() )
{
CPLError( CE_Failure, CPLE_NotSupported,
Expand All @@ -434,7 +431,7 @@ OGRCreateCoordinateTransformation( OGRSpatialReference *poSource,
return NULL;
}

poCT = new OGRProj4CT();
OGRProj4CT *poCT = new OGRProj4CT();

if( !poCT->Initialize( poSource, poTarget ) )
{
Expand Down Expand Up @@ -636,8 +633,6 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn,
/* -------------------------------------------------------------------- */
/* Preliminary logic to setup wrapping. */
/* -------------------------------------------------------------------- */
const char *pszCENTER_LONG;

if( CPLGetConfigOption( "CENTER_LONG", NULL ) != NULL )
{
bSourceWrap = true;
Expand All @@ -647,7 +642,8 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn,
CPLDebug( "OGRCT", "Wrap at %g.", dfSourceWrapLong );
}

pszCENTER_LONG = poSRSSource->GetExtension( "GEOGCS", "CENTER_LONG" );
const char *pszCENTER_LONG =
poSRSSource->GetExtension( "GEOGCS", "CENTER_LONG" );
if( pszCENTER_LONG != NULL )
{
dfSourceWrapLong = CPLAtof(pszCENTER_LONG);
Expand Down Expand Up @@ -736,17 +732,18 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn,
strstr(pszDstProj4Defn, "+towgs84") == NULL )
{
char* pszDst = strstr(pszSrcProj4Defn, "+towgs84=0,0,0,0,0,0,0 ");
char* pszSrc;
if( pszDst != NULL )
{
pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 ");
char *pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 ");
memmove(pszDst, pszSrc, strlen(pszSrc)+1);
}
else
{
memcpy(strstr(pszSrcProj4Defn, "+datum=WGS84"), "+ellps", 6);
}

pszDst = strstr(pszDstProj4Defn, "+nadgrids=@null ");
pszSrc = pszDst + strlen("+nadgrids=@null ");
char *pszSrc = pszDst + strlen("+nadgrids=@null ");
memmove(pszDst, pszSrc, strlen(pszSrc)+1);

pszDst = strstr(pszDstProj4Defn, "+wktext ");
Expand All @@ -767,17 +764,16 @@ int OGRProj4CT::InitializeNoLock( OGRSpatialReference * poSourceIn,
strstr(pszSrcProj4Defn, "+towgs84") == NULL )
{
char* pszDst = strstr(pszDstProj4Defn, "+towgs84=0,0,0,0,0,0,0 ");
char* pszSrc;
if( pszDst != NULL)
{
pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 ");
char* pszSrc = pszDst + strlen("+towgs84=0,0,0,0,0,0,0 ");
memmove(pszDst, pszSrc, strlen(pszSrc)+1);
}
else
memcpy(strstr(pszDstProj4Defn, "+datum=WGS84"), "+ellps", 6);

pszDst = strstr(pszSrcProj4Defn, "+nadgrids=@null ");
pszSrc = pszDst + strlen("+nadgrids=@null ");
char* pszSrc = pszDst + strlen("+nadgrids=@null ");
memmove(pszDst, pszSrc, strlen(pszSrc)+1);

pszDst = strstr(pszSrcProj4Defn, "+wktext ");
Expand Down
Loading

0 comments on commit 318b518

Please sign in to comment.