LCOV - code coverage report
Current view: top level - frmts/kea - keadataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 19 100.0 %
Date: 2025-01-18 12:42:00 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  keadataset.h
       3             :  *
       4             :  *  Created by Pete Bunting on 01/08/2012.
       5             :  *  Copyright 2012 LibKEA. All rights reserved.
       6             :  *
       7             :  *  This file is part of LibKEA.
       8             :  *
       9             :  * SPDX-License-Identifier: MIT
      10             :  *
      11             :  */
      12             : 
      13             : #ifndef KEADATASET_H
      14             : #define KEADATASET_H
      15             : 
      16             : #include "gdal_priv.h"
      17             : #include "cpl_multiproc.h"
      18             : #include "libkea_headers.h"
      19             : 
      20             : class LockedRefCount;
      21             : 
      22             : // class that implements a GDAL dataset
      23             : class KEADataset final : public GDALDataset
      24             : {
      25             :     static H5::H5File *CreateLL(const char *pszFilename, int nXSize, int nYSize,
      26             :                                 int nBands, GDALDataType eType,
      27             :                                 char **papszParamList);
      28             : 
      29             :   public:
      30             :     // constructor/destructor
      31             :     KEADataset(H5::H5File *keaImgH5File, GDALAccess eAccess);
      32             :     ~KEADataset();
      33             : 
      34             :     // static methods that handle open and creation
      35             :     // the driver class has pointers to these
      36             :     static GDALDataset *Open(GDALOpenInfo *);
      37             :     static int Identify(GDALOpenInfo *poOpenInfo);
      38             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
      39             :                                int nBands, GDALDataType eType,
      40             :                                char **papszParamList);
      41             :     static GDALDataset *CreateCopy(const char *pszFilename, GDALDataset *pSrcDs,
      42             :                                    int bStrict, char **papszParamList,
      43             :                                    GDALProgressFunc pfnProgress,
      44             :                                    void *pProgressData);
      45             : 
      46             :     // virtual methods for dealing with transform and projection
      47             :     CPLErr GetGeoTransform(double *padfTransform) override;
      48             :     const OGRSpatialReference *GetSpatialRef() const override;
      49             : 
      50             :     CPLErr SetGeoTransform(double *padfTransform) override;
      51             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
      52             : 
      53             :     // method to get a pointer to the imageio class
      54             :     void *GetInternalHandle(const char *) override;
      55             : 
      56             :     // virtual methods for dealing with metadata
      57             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
      58             :                            const char *pszDomain = "") override;
      59             :     const char *GetMetadataItem(const char *pszName,
      60             :                                 const char *pszDomain = "") override;
      61             : 
      62             :     char **GetMetadata(const char *pszDomain = "") override;
      63             :     CPLErr SetMetadata(char **papszMetadata,
      64             :                        const char *pszDomain = "") override;
      65             : 
      66             :     // virtual method for adding new image bands
      67             :     CPLErr AddBand(GDALDataType eType, char **papszOptions = nullptr) override;
      68             : 
      69             :     // GCPs
      70             :     int GetGCPCount() override;
      71             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
      72             :     const GDAL_GCP *GetGCPs() override;
      73             :     CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
      74             :                    const OGRSpatialReference *poSRS) override;
      75             : 
      76             :   protected:
      77             :     // this method builds overviews for the specified bands.
      78             :     virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
      79             :                                    const int *panOverviewList, int nListBands,
      80             :                                    const int *panBandList,
      81             :                                    GDALProgressFunc pfnProgress,
      82             :                                    void *pProgressData,
      83             :                                    CSLConstList papszOptions) override;
      84             : 
      85             :     // internal method to update m_papszMetadataList
      86             :     void UpdateMetadataList();
      87             : 
      88             :     void DestroyGCPs();
      89             : 
      90             :   private:
      91             :     // pointer to KEAImageIO class and the refcount for it
      92             :     kealib::KEAImageIO *m_pImageIO;
      93             :     LockedRefCount *m_pRefcount;
      94             :     char **m_papszMetadataList;  // CSLStringList for metadata
      95             :     GDAL_GCP *m_pGCPs;
      96             :     mutable OGRSpatialReference m_oGCPSRS{};
      97             :     mutable CPLMutex *m_hMutex;
      98             :     mutable OGRSpatialReference m_oSRS{};
      99             : };
     100             : 
     101             : // conversion functions
     102             : GDALDataType KEA_to_GDAL_Type(kealib::KEADataType ekeaType);
     103             : kealib::KEADataType GDAL_to_KEA_Type(GDALDataType egdalType);
     104             : 
     105             : // For unloading the VFL
     106             : void KEADatasetDriverUnload(GDALDriver *);
     107             : 
     108             : // A thresafe reference count. Used to manage shared pointer to
     109             : // the kealib::KEAImageIO instance between bands and dataset.
     110             : class LockedRefCount
     111             : {
     112             :   private:
     113             :     int m_nRefCount;
     114             :     CPLMutex *m_hMutex;
     115             : 
     116             :     CPL_DISALLOW_COPY_ASSIGN(LockedRefCount)
     117             : 
     118             :   public:
     119         252 :     explicit LockedRefCount(int initCount = 1)
     120         252 :     {
     121         252 :         m_nRefCount = initCount;
     122         252 :         m_hMutex = CPLCreateMutex();
     123         252 :         CPLReleaseMutex(m_hMutex);
     124         252 :     }
     125             : 
     126         252 :     ~LockedRefCount()
     127         252 :     {
     128         252 :         CPLDestroyMutex(m_hMutex);
     129         252 :         m_hMutex = nullptr;
     130         252 :     }
     131             : 
     132         355 :     void IncRef()
     133             :     {
     134         355 :         CPLMutexHolderD(&m_hMutex);
     135         355 :         m_nRefCount++;
     136         355 :     }
     137             : 
     138             :     // returns true if reference count now 0
     139         607 :     bool DecRef()
     140             :     {
     141         607 :         CPLMutexHolderD(&m_hMutex);
     142         607 :         m_nRefCount--;
     143        1214 :         return m_nRefCount <= 0;
     144             :     }
     145             : };
     146             : 
     147             : #endif  // KEADATASET_H

Generated by: LCOV version 1.14