From a42afc2146378c5845d8d2c17fb2ba8a8aae50a0 Mon Sep 17 00:00:00 2001 From: Julien Michel Date: Thu, 7 Jul 2016 16:20:05 +0200 Subject: [PATCH] ENH: Hide static const DerivedDatasetDescription asDDSDesc [] in a compiled file to avoid duplication in binaries (from PR review) --- gdal/frmts/cderived/GNUmakefile | 2 +- gdal/frmts/cderived/cderiveddataset.cpp | 12 ++++-- gdal/frmts/cderived/derivedlist.c | 56 +++++++++++++++++++++++++ gdal/frmts/cderived/derivedlist.h | 14 +------ gdal/frmts/cderived/makefile.vc | 2 +- gdal/gcore/gdaldataset.cpp | 12 ++++-- 6 files changed, 76 insertions(+), 22 deletions(-) create mode 100644 gdal/frmts/cderived/derivedlist.c diff --git a/gdal/frmts/cderived/GNUmakefile b/gdal/frmts/cderived/GNUmakefile index dd9b946208a7..91a8866efa9e 100644 --- a/gdal/frmts/cderived/GNUmakefile +++ b/gdal/frmts/cderived/GNUmakefile @@ -1,7 +1,7 @@ include ../../GDALmake.opt -OBJ = cderiveddataset.o +OBJ = cderiveddataset.o derivedlist.o default: $(OBJ:.o=.$(OBJ_EXT)) diff --git a/gdal/frmts/cderived/cderiveddataset.cpp b/gdal/frmts/cderived/cderiveddataset.cpp index 6c97b0f82d13..4356028fc1be 100644 --- a/gdal/frmts/cderived/cderiveddataset.cpp +++ b/gdal/frmts/cderived/cderiveddataset.cpp @@ -79,13 +79,17 @@ GDALDataset * ComplexDerivedDataset::Open(GDALOpenInfo * poOpenInfo) CPLString pixelFunctionName = ""; bool datasetFound = false; + + const unsigned int nbSupportedDerivedDS = GDALGetNumberOfDerivedDatasetDecriptions(); - for(unsigned int derivedId = 0; derivedIdpszDatasetName) { datasetFound = true; - pixelFunctionName = asDDSDesc[derivedId].pszPixelFunction; + pixelFunctionName = poCurrentDerivedDatasetDescription->pszPixelFunction; } } diff --git a/gdal/frmts/cderived/derivedlist.c b/gdal/frmts/cderived/derivedlist.c new file mode 100644 index 000000000000..5c1a8ce11986 --- /dev/null +++ b/gdal/frmts/cderived/derivedlist.c @@ -0,0 +1,56 @@ +/****************************************************************************** + * + * Project: GDAL + * Purpose: Implementation of derived subdatasets + * Author: Julien Michel + * + ****************************************************************************** + * Copyright (c) 2016 Julien Michel + * + * 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; +} diff --git a/gdal/frmts/cderived/derivedlist.h b/gdal/frmts/cderived/derivedlist.h index 7f21005c9713..5726e818cc36 100644 --- a/gdal/frmts/cderived/derivedlist.h +++ b/gdal/frmts/cderived/derivedlist.h @@ -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 diff --git a/gdal/frmts/cderived/makefile.vc b/gdal/frmts/cderived/makefile.vc index 5fd83953a1ee..b2ab580b3a1f 100644 --- a/gdal/frmts/cderived/makefile.vc +++ b/gdal/frmts/cderived/makefile.vc @@ -1,5 +1,5 @@ -OBJ = cderiveddataset.obj +OBJ = cderiveddataset.obj derivedlist.obj GDAL_ROOT = ..\.. diff --git a/gdal/gcore/gdaldataset.cpp b/gdal/gcore/gdaldataset.cpp index 378896c55be3..b17908c1690d 100644 --- a/gdal/gcore/gdaldataset.cpp +++ b/gdal/gcore/gdaldataset.cpp @@ -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; derivedIdpszDatasetName,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()); } }