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: 2024-11-21 22:18:42 Functions: 4 4 100.0 %

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

Generated by: LCOV version 1.14