LCOV - code coverage report
Current view: top level - gcore - gdal_proxy.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 6 8 75.0 %
Date: 2026-01-31 22:56:34 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL Core
       4             :  * Purpose:  GDAL Core C++/Private declarations
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDAL_PROXY_H_INCLUDED
      14             : #define GDAL_PROXY_H_INCLUDED
      15             : 
      16             : #ifndef DOXYGEN_SKIP
      17             : 
      18             : #include "gdal.h"
      19             : 
      20             : #ifdef __cplusplus
      21             : 
      22             : #include "gdal_priv.h"
      23             : #include "cpl_hash_set.h"
      24             : 
      25             : /* ******************************************************************** */
      26             : /*                        GDALProxyDataset                              */
      27             : /* ******************************************************************** */
      28             : 
      29             : class CPL_DLL GDALProxyDataset : public GDALDataset
      30             : {
      31             :   protected:
      32        6111 :     GDALProxyDataset()
      33        6111 :     {
      34        6111 :     }
      35             : 
      36             :     virtual GDALDataset *RefUnderlyingDataset() const = 0;
      37             :     virtual void UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const;
      38             : 
      39             :     CPLErr IBuildOverviews(const char *, int, const int *, int, const int *,
      40             :                            GDALProgressFunc, void *,
      41             :                            CSLConstList papszOptions) override;
      42             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
      43             :                      GDALDataType, int, BANDMAP_TYPE, GSpacing, GSpacing,
      44             :                      GSpacing, GDALRasterIOExtraArg *psExtraArg) override;
      45             :     CPLErr BlockBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
      46             :                               int nXSize, int nYSize, void *pData,
      47             :                               int nBufXSize, int nBufYSize,
      48             :                               GDALDataType eBufType, int nBandCount,
      49             :                               const int *panBandMap, GSpacing nPixelSpace,
      50             :                               GSpacing nLineSpace, GSpacing nBandSpace,
      51             :                               GDALRasterIOExtraArg *psExtraArg) override;
      52             : 
      53             :   public:
      54             :     CPLErr Close(GDALProgressFunc, void *) override;
      55             :     bool GetCloseReportsProgress() const override;
      56             : 
      57             :     char **GetMetadataDomainList() override;
      58             :     CSLConstList GetMetadata(const char *pszDomain) override;
      59             :     CPLErr SetMetadata(CSLConstList papszMetadata,
      60             :                        const char *pszDomain) override;
      61             :     const char *GetMetadataItem(const char *pszName,
      62             :                                 const char *pszDomain) override;
      63             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
      64             :                            const char *pszDomain) override;
      65             : 
      66             :     CPLErr FlushCache(bool bAtClosing) override;
      67             : 
      68             :     const OGRSpatialReference *GetSpatialRef() const override;
      69             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
      70             : 
      71             :     CPLErr GetGeoTransform(GDALGeoTransform &) const override;
      72             :     CPLErr SetGeoTransform(const GDALGeoTransform &) override;
      73             : 
      74             :     void *GetInternalHandle(const char *) override;
      75             :     GDALDriver *GetDriver() override;
      76             :     char **GetFileList() override;
      77             : 
      78             :     int GetGCPCount() override;
      79             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
      80             :     const GDAL_GCP *GetGCPs() override;
      81             :     CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
      82             :                    const OGRSpatialReference *poGCP_SRS) override;
      83             : 
      84             :     CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
      85             :                       int nBufXSize, int nBufYSize, GDALDataType eDT,
      86             :                       int nBandCount, int *panBandList,
      87             :                       CSLConstList papszOptions) override;
      88             : 
      89             :     CPLErr CreateMaskBand(int nFlags) override;
      90             : 
      91             :     virtual CPLStringList
      92             :     GetCompressionFormats(int nXOff, int nYOff, int nXSize, int nYSize,
      93             :                           int nBandCount, const int *panBandList) override;
      94             :     virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
      95             :                                       int nYOff, int nXSize, int nYSize,
      96             :                                       int nBandCount, const int *panBandList,
      97             :                                       void **ppBuffer, size_t *pnBufferSize,
      98             :                                       char **ppszDetailedFormat) override;
      99             : 
     100             :   private:
     101             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyDataset)
     102             : };
     103             : 
     104             : /* ******************************************************************** */
     105             : /*                         GDALProxyRasterBand                          */
     106             : /* ******************************************************************** */
     107             : 
     108             : class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
     109             : {
     110             :   protected:
     111      108024 :     GDALProxyRasterBand()
     112      108024 :     {
     113      108024 :     }
     114             : 
     115             :     virtual GDALRasterBand *
     116             :     RefUnderlyingRasterBand(bool bForceOpen = true) const = 0;
     117             :     virtual void
     118             :     UnrefUnderlyingRasterBand(GDALRasterBand *poUnderlyingRasterBand) const;
     119             : 
     120             :     CPLErr IReadBlock(int, int, void *) override;
     121             :     CPLErr IWriteBlock(int, int, void *) override;
     122             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     123             :                      GDALDataType, GSpacing, GSpacing,
     124             :                      GDALRasterIOExtraArg *psExtraArg) override;
     125             : 
     126             :     int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
     127             :                                int nMaskFlagStop, double *pdfDataPct) override;
     128             : 
     129             :   public:
     130             :     char **GetMetadataDomainList() override;
     131             :     CSLConstList GetMetadata(const char *pszDomain) override;
     132             :     CPLErr SetMetadata(CSLConstList papszMetadata,
     133             :                        const char *pszDomain) override;
     134             :     const char *GetMetadataItem(const char *pszName,
     135             :                                 const char *pszDomain) override;
     136             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
     137             :                            const char *pszDomain) override;
     138             : 
     139             :     GDALRasterBlock *GetLockedBlockRef(int nXBlockOff, int nYBlockOff,
     140             :                                        int bJustInitialize) override;
     141             : 
     142             :     GDALRasterBlock *TryGetLockedBlockRef(int nXBlockOff,
     143             :                                           int nYBlockYOff) override;
     144             : 
     145             :     CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
     146             :                       int bWriteDirtyBlock) override;
     147             : 
     148             :     CPLErr FlushCache(bool bAtClosing) override;
     149             :     char **GetCategoryNames() override;
     150             :     double GetNoDataValue(int *pbSuccess = nullptr) override;
     151             :     double GetMinimum(int *pbSuccess = nullptr) override;
     152             :     double GetMaximum(int *pbSuccess = nullptr) override;
     153             :     double GetOffset(int *pbSuccess = nullptr) override;
     154             :     double GetScale(int *pbSuccess = nullptr) override;
     155             :     const char *GetUnitType() override;
     156             :     GDALColorInterp GetColorInterpretation() override;
     157             :     GDALColorTable *GetColorTable() override;
     158             :     CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0) override;
     159             : 
     160             :     CPLErr SetCategoryNames(char **) override;
     161             :     CPLErr SetNoDataValue(double) override;
     162             :     CPLErr DeleteNoDataValue() override;
     163             :     CPLErr SetColorTable(GDALColorTable *) override;
     164             :     CPLErr SetColorInterpretation(GDALColorInterp) override;
     165             :     CPLErr SetOffset(double) override;
     166             :     CPLErr SetScale(double) override;
     167             :     CPLErr SetUnitType(const char *) override;
     168             : 
     169             :     CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
     170             :                          double *pdfMax, double *pdfMean,
     171             :                          double *padfStdDev) override;
     172             :     CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
     173             :                              double *pdfMean, double *pdfStdDev,
     174             :                              GDALProgressFunc, void *pProgressData) override;
     175             :     CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
     176             :                          double dfStdDev) override;
     177             :     CPLErr ComputeRasterMinMax(int, double *) override;
     178             : 
     179             :     int HasArbitraryOverviews() override;
     180             :     int GetOverviewCount() override;
     181             :     GDALRasterBand *GetOverview(int) override;
     182             :     GDALRasterBand *GetRasterSampleOverview(GUIntBig) override;
     183             :     CPLErr BuildOverviews(const char *, int, const int *, GDALProgressFunc,
     184             :                           void *, CSLConstList papszOptions) override;
     185             : 
     186             :     CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
     187             :                       int nBufXSize, int nBufYSize, GDALDataType eDT,
     188             :                       CSLConstList papszOptions) override;
     189             : 
     190             :     CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
     191             :                         GUIntBig *panHistogram, int bIncludeOutOfRange,
     192             :                         int bApproxOK, GDALProgressFunc,
     193             :                         void *pProgressData) override;
     194             : 
     195             :     CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
     196             :                                GUIntBig **ppanHistogram, int bForce,
     197             :                                GDALProgressFunc, void *pProgressData) override;
     198             :     CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
     199             :                                GUIntBig *panHistogram) override;
     200             : 
     201             :     GDALRasterAttributeTable *GetDefaultRAT() override;
     202             :     CPLErr SetDefaultRAT(const GDALRasterAttributeTable *) override;
     203             : 
     204             :     GDALRasterBand *GetMaskBand() override;
     205             :     int GetMaskFlags() override;
     206             :     CPLErr CreateMaskBand(int nFlags) override;
     207             :     bool IsMaskBand() const override;
     208             :     GDALMaskValueRange GetMaskValueRange() const override;
     209             : 
     210             :     CPLVirtualMem *GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
     211             :                                      GIntBig *pnLineSpace,
     212             :                                      CSLConstList papszOptions) override;
     213             : 
     214             :     CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
     215             :                               GDALRIOResampleAlg eInterpolation,
     216             :                               double *pdfRealValue,
     217             :                               double *pdfImagValue) const override;
     218             : 
     219             :     void EnablePixelTypeSignedByteWarning(bool b) override;
     220             : 
     221             :   private:
     222             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyRasterBand)
     223             : };
     224             : 
     225             : /* ******************************************************************** */
     226             : /*                     GDALProxyPoolDataset                             */
     227             : /* ******************************************************************** */
     228             : 
     229             : typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
     230             : class GDALProxyPoolRasterBand;
     231             : 
     232             : class CPL_DLL GDALProxyPoolDataset /* non final */ : public GDALProxyDataset
     233             : {
     234             :   private:
     235             :     GIntBig responsiblePID = -1;
     236             : 
     237             :     mutable char *pszProjectionRef = nullptr;
     238             :     mutable OGRSpatialReference *m_poSRS = nullptr;
     239             :     mutable OGRSpatialReference *m_poGCPSRS = nullptr;
     240             :     GDALGeoTransform m_gt{};
     241             :     bool m_bHasSrcSRS = false;
     242             :     bool m_bHasSrcGeoTransform = false;
     243             :     char *pszGCPProjection = nullptr;
     244             :     int nGCPCount = 0;
     245             :     GDAL_GCP *pasGCPList = nullptr;
     246             :     CPLHashSet *metadataSet = nullptr;
     247             :     CPLHashSet *metadataItemSet = nullptr;
     248             : 
     249             :     mutable GDALProxyPoolCacheEntry *cacheEntry = nullptr;
     250             :     char *m_pszOwner = nullptr;
     251             : 
     252             :     GDALDataset *RefUnderlyingDataset(bool bForceOpen) const;
     253             : 
     254             :     GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
     255             :                          GDALAccess eAccess, int bShared, const char *pszOwner);
     256             : 
     257             :   protected:
     258             :     GDALDataset *RefUnderlyingDataset() const override;
     259             :     void
     260             :     UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const override;
     261             : 
     262             :     friend class GDALProxyPoolRasterBand;
     263             : 
     264             :   public:
     265             :     GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
     266             :                          int nRasterXSize, int nRasterYSize,
     267             :                          GDALAccess eAccess = GA_ReadOnly, int bShared = FALSE,
     268             :                          const char *pszProjectionRef = nullptr,
     269             :                          const GDALGeoTransform *pGT = nullptr,
     270             :                          const char *pszOwner = nullptr);
     271             : 
     272             :     static GDALProxyPoolDataset *Create(const char *pszSourceDatasetDescription,
     273             :                                         CSLConstList papszOpenOptions = nullptr,
     274             :                                         GDALAccess eAccess = GA_ReadOnly,
     275             :                                         int bShared = FALSE,
     276             :                                         const char *pszOwner = nullptr);
     277             : 
     278             :     ~GDALProxyPoolDataset() override;
     279             : 
     280             :     void SetOpenOptions(CSLConstList papszOpenOptions);
     281             : 
     282             :     // If size (nBlockXSize&nBlockYSize) parameters is zero
     283             :     // they will be loaded when RefUnderlyingRasterBand function is called.
     284             :     // But in this case we cannot use them in other non-virtual methods before
     285             :     // RefUnderlyingRasterBand fist call.
     286             :     void AddSrcBandDescription(GDALDataType eDataType, int nBlockXSize,
     287             :                                int nBlockYSize);
     288             : 
     289             :     // Used by VRT SimpleSource to add a single GDALProxyPoolRasterBand while
     290             :     // keeping all other bands initialized to a nullptr. This is under the
     291             :     // assumption, VRT SimpleSource will not have to access any other bands than
     292             :     // the one added.
     293             :     void AddSrcBand(int nBand, GDALDataType eDataType, int nBlockXSize,
     294             :                     int nBlockYSize);
     295             :     CPLErr FlushCache(bool bAtClosing) override;
     296             : 
     297             :     const OGRSpatialReference *GetSpatialRef() const override;
     298             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
     299             : 
     300             :     CPLErr GetGeoTransform(GDALGeoTransform &) const override;
     301             :     CPLErr SetGeoTransform(const GDALGeoTransform &) override;
     302             : 
     303             :     // Special behavior for the following methods : they return a pointer
     304             :     // data type, that must be cached by the proxy, so it doesn't become invalid
     305             :     // when the underlying object get closed.
     306             :     CSLConstList GetMetadata(const char *pszDomain) override;
     307             :     const char *GetMetadataItem(const char *pszName,
     308             :                                 const char *pszDomain) override;
     309             : 
     310             :     void *GetInternalHandle(const char *pszRequest) override;
     311             : 
     312             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
     313             :     const GDAL_GCP *GetGCPs() override;
     314             : 
     315             :   private:
     316             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolDataset)
     317             : };
     318             : 
     319             : /* ******************************************************************** */
     320             : /*                  GDALProxyPoolRasterBand                             */
     321             : /* ******************************************************************** */
     322             : 
     323             : class GDALProxyPoolOverviewRasterBand;
     324             : class GDALProxyPoolMaskBand;
     325             : 
     326             : class CPL_DLL
     327             :     GDALProxyPoolRasterBand /* non final */ : public GDALProxyRasterBand
     328             : {
     329             :   private:
     330             :     CPLHashSet *metadataSet = nullptr;
     331             :     CPLHashSet *metadataItemSet = nullptr;
     332             :     char *pszUnitType = nullptr;
     333             :     char **papszCategoryNames = nullptr;
     334             :     GDALColorTable *poColorTable = nullptr;
     335             : 
     336             :     int nSizeProxyOverviewRasterBand = 0;
     337             :     GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand = nullptr;
     338             :     GDALProxyPoolMaskBand *poProxyMaskBand = nullptr;
     339             : 
     340             :   protected:
     341             :     GDALRasterBand *
     342             :     RefUnderlyingRasterBand(bool bForceOpen = true) const override;
     343             :     void UnrefUnderlyingRasterBand(
     344             :         GDALRasterBand *poUnderlyingRasterBand) const override;
     345             : 
     346             :     friend class GDALProxyPoolOverviewRasterBand;
     347             :     friend class GDALProxyPoolMaskBand;
     348             : 
     349             :   public:
     350             :     GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS, int nBand,
     351             :                             GDALDataType eDataType, int nBlockXSize,
     352             :                             int nBlockYSize);
     353             :     GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS,
     354             :                             GDALRasterBand *poUnderlyingRasterBand);
     355             :     ~GDALProxyPoolRasterBand() override;
     356             : 
     357             :     void AddSrcMaskBandDescription(GDALDataType eDataType, int nBlockXSize,
     358             :                                    int nBlockYSize);
     359             : 
     360             :     void AddSrcMaskBandDescriptionFromUnderlying();
     361             : 
     362             :     // Special behavior for the following methods : they return a pointer
     363             :     // data type, that must be cached by the proxy, so it doesn't become invalid
     364             :     // when the underlying object get closed.
     365             :     CSLConstList GetMetadata(const char *pszDomain) override;
     366             :     const char *GetMetadataItem(const char *pszName,
     367             :                                 const char *pszDomain) override;
     368             :     char **GetCategoryNames() override;
     369             :     const char *GetUnitType() override;
     370             :     GDALColorTable *GetColorTable() override;
     371             :     GDALRasterBand *GetOverview(int) override;
     372             :     GDALRasterBand *
     373             :     GetRasterSampleOverview(GUIntBig nDesiredSamples) override;  // TODO
     374             :     GDALRasterBand *GetMaskBand() override;
     375             : 
     376             :     CPLErr FlushCache(bool bAtClosing) override;
     377             : 
     378             :   private:
     379             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolRasterBand)
     380             : };
     381             : 
     382             : /* ******************************************************************** */
     383             : /*                  GDALProxyPoolOverviewRasterBand                     */
     384             : /* ******************************************************************** */
     385             : 
     386             : class GDALProxyPoolOverviewRasterBand final : public GDALProxyPoolRasterBand
     387             : {
     388             :   private:
     389             :     GDALProxyPoolRasterBand *poMainBand = nullptr;
     390             :     int nOverviewBand = 0;
     391             : 
     392             :     mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
     393             :     mutable int nRefCountUnderlyingMainRasterBand = 0;
     394             : 
     395             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolOverviewRasterBand)
     396             : 
     397             :   protected:
     398             :     GDALRasterBand *
     399             :     RefUnderlyingRasterBand(bool bForceOpen = true) const override;
     400             :     void UnrefUnderlyingRasterBand(
     401             :         GDALRasterBand *poUnderlyingRasterBand) const override;
     402             : 
     403             :   public:
     404             :     GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset *poDS,
     405             :                                     GDALRasterBand *poUnderlyingOverviewBand,
     406             :                                     GDALProxyPoolRasterBand *poMainBand,
     407             :                                     int nOverviewBand);
     408             :     ~GDALProxyPoolOverviewRasterBand() override;
     409             : };
     410             : 
     411             : /* ******************************************************************** */
     412             : /*                      GDALProxyPoolMaskBand                           */
     413             : /* ******************************************************************** */
     414             : 
     415             : class GDALProxyPoolMaskBand final : public GDALProxyPoolRasterBand
     416             : {
     417             :   private:
     418             :     GDALProxyPoolRasterBand *poMainBand = nullptr;
     419             : 
     420             :     mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
     421             :     mutable int nRefCountUnderlyingMainRasterBand = 0;
     422             : 
     423             :     CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolMaskBand)
     424             : 
     425             :   protected:
     426             :     GDALRasterBand *
     427             :     RefUnderlyingRasterBand(bool bForceOpen = true) const override;
     428             :     void UnrefUnderlyingRasterBand(
     429             :         GDALRasterBand *poUnderlyingRasterBand) const override;
     430             : 
     431             :   public:
     432             :     GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
     433             :                           GDALRasterBand *poUnderlyingMaskBand,
     434             :                           GDALProxyPoolRasterBand *poMainBand);
     435             :     GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
     436             :                           GDALProxyPoolRasterBand *poMainBand,
     437             :                           GDALDataType eDataType, int nBlockXSize,
     438             :                           int nBlockYSize);
     439             :     ~GDALProxyPoolMaskBand() override;
     440             : 
     441           0 :     bool IsMaskBand() const override
     442             :     {
     443           0 :         return true;
     444             :     }
     445             : };
     446             : 
     447             : #endif
     448             : 
     449             : /* ******************************************************************** */
     450             : /*            C types and methods declarations                          */
     451             : /* ******************************************************************** */
     452             : 
     453             : CPL_C_START
     454             : 
     455             : typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
     456             : 
     457             : GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(
     458             :     const char *pszSourceDatasetDescription, int nRasterXSize, int nRasterYSize,
     459             :     GDALAccess eAccess, int bShared, const char *pszProjectionRef,
     460             :     const double *padfGeoTransform);
     461             : 
     462             : void CPL_DLL
     463             : GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
     464             : 
     465             : void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription(
     466             :     GDALProxyPoolDatasetH hProxyPoolDataset, GDALDataType eDataType,
     467             :     int nBlockXSize, int nBlockYSize);
     468             : 
     469             : int CPL_DLL GDALGetMaxDatasetPoolSize(void);
     470             : 
     471             : CPL_C_END
     472             : 
     473             : #endif /* #ifndef DOXYGEN_SKIP */
     474             : 
     475             : #endif /* GDAL_PROXY_H_INCLUDED */

Generated by: LCOV version 1.14