Skip to content

Commit

Permalink
ENH: Hide static const DerivedDatasetDescription asDDSDesc [] in a co…
Browse files Browse the repository at this point in the history
…mpiled file to avoid duplication in binaries (from PR review)
  • Loading branch information
jmichel-otb committed Jul 7, 2016
1 parent 44f6f4d commit a42afc2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gdal/frmts/cderived/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

include ../../GDALmake.opt

OBJ = cderiveddataset.o
OBJ = cderiveddataset.o derivedlist.o

default: $(OBJ:.o=.$(OBJ_EXT))

Expand Down
12 changes: 8 additions & 4 deletions gdal/frmts/cderived/cderiveddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ GDALDataset * ComplexDerivedDataset::Open(GDALOpenInfo * poOpenInfo)

CPLString pixelFunctionName = "";
bool datasetFound = false;

const unsigned int nbSupportedDerivedDS = GDALGetNumberOfDerivedDatasetDecriptions();

for(unsigned int derivedId = 0; derivedId<NB_DERIVED_DATASETS;++derivedId)
{
if(odDerivedName == asDDSDesc[derivedId].pszDatasetName)
for(unsigned int derivedId = 0; derivedId<nbSupportedDerivedDS;++derivedId)
{
const DerivedDatasetDescription * poCurrentDerivedDatasetDescription = GDALGetDerivedDatasetDescription(&derivedId);

if(poCurrentDerivedDatasetDescription != NULL && odDerivedName == poCurrentDerivedDatasetDescription->pszDatasetName)
{
datasetFound = true;
pixelFunctionName = asDDSDesc[derivedId].pszPixelFunction;
pixelFunctionName = poCurrentDerivedDatasetDescription->pszPixelFunction;
}
}

Expand Down
56 changes: 56 additions & 0 deletions gdal/frmts/cderived/derivedlist.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/******************************************************************************
*
* Project: GDAL
* Purpose: Implementation of derived subdatasets
* Author: Julien Michel <julien dot michel at cnes dot fr>
*
******************************************************************************
* Copyright (c) 2016 Julien Michel <julien dot michel at cnes dot fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#include "derivedlist.h"
#include "gdal.h"

static const DerivedDatasetDescription asDDSDesc [] =
{
{ "AMPLITUDE", "Amplitude of input bands", "mod"},
{ "PHASE", "Phase of input bands", "phase"},
{ "REAL", "Real part of input bands", "real"},
{ "IMAG", "Imaginary part of input bands", "imag"},
{ "CONJ", "Conjugate of input bands", "conj"},
{ "INTENSITY", "Intensity (squared amplitude) of input bands", "intensity"},
{ "LOGAMPLITUDE", "log10 of amplitude of input bands", "log10"}
};

#define NB_DERIVED_DATASETS (sizeof(asDDSDesc)/sizeof(asDDSDesc[0]))

const DerivedDatasetDescription* GDALGetDerivedDatasetDescription(const unsigned int * pnDescriptionCount)
{
if(*pnDescriptionCount < (int)NB_DERIVED_DATASETS)
{
return &asDDSDesc[*pnDescriptionCount];
}
return NULL;
}

unsigned int GDALGetNumberOfDerivedDatasetDecriptions(void)
{
return (unsigned int)NB_DERIVED_DATASETS;
}
14 changes: 2 additions & 12 deletions gdal/frmts/cderived/derivedlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,8 @@ typedef struct
const char * pszPixelFunction;
} DerivedDatasetDescription;

static const DerivedDatasetDescription asDDSDesc [] =
{
{ "AMPLITUDE", "Amplitude of input bands", "mod"},
{ "PHASE", "Phase of input bands", "phase"},
{ "REAL", "Real part of input bands", "real"},
{ "IMAG", "Imaginary part of input bands", "imag"},
{ "CONJ", "Conjugate of input bands", "conj"},
{ "INTENSITY", "Intensity (squared amplitude) of input bands", "intensity"},
{ "LOGAMPLITUDE", "log10 of amplitude of input bands", "log10"}
};

#define NB_DERIVED_DATASETS (sizeof(asDDSDesc)/sizeof(asDDSDesc[0]))
const DerivedDatasetDescription* GDALGetDerivedDatasetDescription(const unsigned int * pnDescriptionCount);

unsigned int GDALGetNumberOfDerivedDatasetDecriptions(void);

#endif
2 changes: 1 addition & 1 deletion gdal/frmts/cderived/makefile.vc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

OBJ = cderiveddataset.obj
OBJ = cderiveddataset.obj derivedlist.obj

GDAL_ROOT = ..\..

Expand Down
12 changes: 8 additions & 4 deletions gdal/gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3305,11 +3305,15 @@ char ** GDALDataset::GetMetadata(const char * pszDomain)
// First condition: at least one raster band
if(GetRasterCount()>0)
{
for(unsigned int derivedId = 0; derivedId<NB_DERIVED_DATASETS;++derivedId)
{
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_NAME",derivedId),CPLSPrintf("DERIVED_SUBDATASET:%s:%s",asDDSDesc[derivedId].pszDatasetName,GetDescription()));
const unsigned int nbSupportedDerivedDS = GDALGetNumberOfDerivedDatasetDecriptions();

for(unsigned int derivedId = 0; derivedId<nbSupportedDerivedDS;++derivedId)
{

const DerivedDatasetDescription * poCurrentDerivedDatasetDescription = GDALGetDerivedDatasetDescription(&derivedId);
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_NAME",derivedId),CPLSPrintf("DERIVED_SUBDATASET:%s:%s",poCurrentDerivedDatasetDescription->pszDatasetName,GetDescription()));

CPLString osDesc(CPLSPrintf("%s from %s",asDDSDesc[derivedId].pszDatasetDescritpion,GetDescription()));
CPLString osDesc(CPLSPrintf("%s from %s",poCurrentDerivedDatasetDescription->pszDatasetDescritpion,GetDescription()));
oDerivedMetadataList.SetNameValue(CPLSPrintf("DERIVED_SUBDATASET_%i_DESC",derivedId),osDesc.c_str());
}
}
Expand Down

0 comments on commit a42afc2

Please sign in to comment.