LCOV - code coverage report
Current view: top level - gcore - gdal_driver.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 21 21 100.0 %
Date: 2025-10-01 17:07:58 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Name:     gdal_driver.h
       4             :  * Project:  GDAL Core
       5             :  * Purpose:  Declaration of GDALDriver class
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 1998, Frank Warmerdam
      10             :  * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef GDALDRIVER_H_INCLUDED
      16             : #define GDALDRIVER_H_INCLUDED
      17             : 
      18             : #include "cpl_port.h"
      19             : #include "gdal.h"
      20             : #include "gdal_majorobject.h"
      21             : 
      22             : #include <vector>
      23             : 
      24             : class GDALAlgorithm;
      25             : class GDALDataset;
      26             : class GDALOpenInfo;
      27             : 
      28             : /* ******************************************************************** */
      29             : /*                          GDALIdentifyEnum                            */
      30             : /* ******************************************************************** */
      31             : 
      32             : /**
      33             :  * Enumeration used by GDALDriver::pfnIdentify().
      34             :  *
      35             :  * @since GDAL 2.1
      36             :  */
      37             : typedef enum
      38             : {
      39             :     /** Identify could not determine if the file is recognized or not by the
      40             :        probed driver. */
      41             :     GDAL_IDENTIFY_UNKNOWN = -1,
      42             :     /** Identify determined the file is not recognized by the probed driver. */
      43             :     GDAL_IDENTIFY_FALSE = 0,
      44             :     /** Identify determined the file is recognized by the probed driver. */
      45             :     GDAL_IDENTIFY_TRUE = 1
      46             : } GDALIdentifyEnum;
      47             : 
      48             : /* ******************************************************************** */
      49             : /*                              GDALDriver                              */
      50             : /* ******************************************************************** */
      51             : 
      52             : /**
      53             :  * \brief Format specific driver.
      54             :  *
      55             :  * An instance of this class is created for each supported format, and
      56             :  * manages information about the format.
      57             :  *
      58             :  * This roughly corresponds to a file format, though some
      59             :  * drivers may be gateways to many formats through a secondary
      60             :  * multi-library.
      61             :  */
      62             : 
      63      398929 : class CPL_DLL GDALDriver : public GDALMajorObject
      64             : {
      65             :   public:
      66             :     GDALDriver();
      67             :     ~GDALDriver() override;
      68             : 
      69             :     const char *GetMetadataItem(const char *pszName,
      70             :                                 const char *pszDomain = "") override;
      71             : 
      72             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
      73             :                            const char *pszDomain = "") override;
      74             : 
      75             :     /* -------------------------------------------------------------------- */
      76             :     /*      Public C++ methods.                                             */
      77             :     /* -------------------------------------------------------------------- */
      78             :     GDALDataset *Create(const char *pszName, int nXSize, int nYSize, int nBands,
      79             :                         GDALDataType eType,
      80             :                         CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
      81             : 
      82             :     GDALDataset *
      83             :     CreateMultiDimensional(const char *pszName,
      84             :                            CSLConstList papszRootGroupOptions,
      85             :                            CSLConstList papszOptions) CPL_WARN_UNUSED_RESULT;
      86             : 
      87             :     CPLErr Delete(const char *pszName);
      88             :     CPLErr Delete(GDALDataset *poDS, CSLConstList papszFileList);
      89             :     CPLErr Rename(const char *pszNewName, const char *pszOldName);
      90             :     CPLErr CopyFiles(const char *pszNewName, const char *pszOldName);
      91             : 
      92             :     GDALDataset *CreateCopy(const char *, GDALDataset *, int,
      93             :                             CSLConstList papszOptions,
      94             :                             GDALProgressFunc pfnProgress,
      95             :                             void *pProgressData) CPL_WARN_UNUSED_RESULT;
      96             : 
      97             :     bool CanVectorTranslateFrom(const char *pszDestName,
      98             :                                 GDALDataset *poSourceDS,
      99             :                                 CSLConstList papszVectorTranslateArguments,
     100             :                                 char ***ppapszFailureReasons);
     101             : 
     102             :     /**
     103             :      * \brief Returns TRUE if the given open option is supported by the driver.
     104             :      * @param pszOpenOptionName name of the open option to be checked
     105             :      * @return TRUE if the driver supports the open option
     106             :      * @since GDAL 3.11
     107             :      */
     108             :     bool HasOpenOption(const char *pszOpenOptionName) const;
     109             : 
     110             :     GDALDataset *
     111             :     VectorTranslateFrom(const char *pszDestName, GDALDataset *poSourceDS,
     112             :                         CSLConstList papszVectorTranslateArguments,
     113             :                         GDALProgressFunc pfnProgress,
     114             :                         void *pProgressData) CPL_WARN_UNUSED_RESULT;
     115             : 
     116             :     /* -------------------------------------------------------------------- */
     117             :     /*      The following are semiprivate, not intended to be accessed      */
     118             :     /*      by anyone but the formats instantiating and populating the      */
     119             :     /*      drivers.                                                        */
     120             :     /* -------------------------------------------------------------------- */
     121             :     //! @cond Doxygen_Suppress
     122             : 
     123             :     // Not aimed at being used outside of GDAL. Use GDALDataset::Open() instead
     124             :     GDALDataset *Open(GDALOpenInfo *poOpenInfo, bool bSetOpenOptions);
     125             : 
     126             :     typedef GDALDataset *(*OpenCallback)(GDALOpenInfo *);
     127             : 
     128             :     OpenCallback pfnOpen = nullptr;
     129             : 
     130      450479 :     virtual OpenCallback GetOpenCallback()
     131             :     {
     132      450479 :         return pfnOpen;
     133             :     }
     134             : 
     135             :     typedef GDALDataset *(*CreateCallback)(const char *pszName, int nXSize,
     136             :                                            int nYSize, int nBands,
     137             :                                            GDALDataType eType,
     138             :                                            char **papszOptions);
     139             : 
     140             :     CreateCallback pfnCreate = nullptr;
     141             : 
     142       23371 :     virtual CreateCallback GetCreateCallback()
     143             :     {
     144       23371 :         return pfnCreate;
     145             :     }
     146             : 
     147             :     GDALDataset *(*pfnCreateEx)(GDALDriver *, const char *pszName, int nXSize,
     148             :                                 int nYSize, int nBands, GDALDataType eType,
     149             :                                 char **papszOptions) = nullptr;
     150             : 
     151             :     typedef GDALDataset *(*CreateMultiDimensionalCallback)(
     152             :         const char *pszName, CSLConstList papszRootGroupOptions,
     153             :         CSLConstList papszOptions);
     154             : 
     155             :     CreateMultiDimensionalCallback pfnCreateMultiDimensional = nullptr;
     156             : 
     157         474 :     virtual CreateMultiDimensionalCallback GetCreateMultiDimensionalCallback()
     158             :     {
     159         474 :         return pfnCreateMultiDimensional;
     160             :     }
     161             : 
     162             :     typedef CPLErr (*DeleteCallback)(const char *pszName);
     163             :     DeleteCallback pfnDelete = nullptr;
     164             : 
     165        5222 :     virtual DeleteCallback GetDeleteCallback()
     166             :     {
     167        5222 :         return pfnDelete;
     168             :     }
     169             : 
     170             :     typedef GDALDataset *(*CreateCopyCallback)(const char *, GDALDataset *, int,
     171             :                                                char **,
     172             :                                                GDALProgressFunc pfnProgress,
     173             :                                                void *pProgressData);
     174             : 
     175             :     CreateCopyCallback pfnCreateCopy = nullptr;
     176             : 
     177       11118 :     virtual CreateCopyCallback GetCreateCopyCallback()
     178             :     {
     179       11118 :         return pfnCreateCopy;
     180             :     }
     181             : 
     182             :     void *pDriverData = nullptr;
     183             : 
     184             :     void (*pfnUnloadDriver)(GDALDriver *) = nullptr;
     185             : 
     186             :     /** Identify() if the file is recognized or not by the driver.
     187             : 
     188             :        Return GDAL_IDENTIFY_TRUE (1) if the passed file is certainly recognized
     189             :        by the driver. Return GDAL_IDENTIFY_FALSE (0) if the passed file is
     190             :        certainly NOT recognized by the driver. Return GDAL_IDENTIFY_UNKNOWN (-1)
     191             :        if the passed file may be or may not be recognized by the driver, and
     192             :        that a potentially costly test must be done with pfnOpen.
     193             :     */
     194             :     int (*pfnIdentify)(GDALOpenInfo *) = nullptr;
     195             :     int (*pfnIdentifyEx)(GDALDriver *, GDALOpenInfo *) = nullptr;
     196             : 
     197             :     typedef CPLErr (*RenameCallback)(const char *pszNewName,
     198             :                                      const char *pszOldName);
     199             :     RenameCallback pfnRename = nullptr;
     200             : 
     201         175 :     virtual RenameCallback GetRenameCallback()
     202             :     {
     203         175 :         return pfnRename;
     204             :     }
     205             : 
     206             :     typedef CPLErr (*CopyFilesCallback)(const char *pszNewName,
     207             :                                         const char *pszOldName);
     208             :     CopyFilesCallback pfnCopyFiles = nullptr;
     209             : 
     210          12 :     virtual CopyFilesCallback GetCopyFilesCallback()
     211             :     {
     212          12 :         return pfnCopyFiles;
     213             :     }
     214             : 
     215             :     // Used for legacy OGR drivers, and Python drivers
     216             :     GDALDataset *(*pfnOpenWithDriverArg)(GDALDriver *,
     217             :                                          GDALOpenInfo *) = nullptr;
     218             : 
     219             :     /* For legacy OGR drivers */
     220             :     GDALDataset *(*pfnCreateVectorOnly)(GDALDriver *, const char *pszName,
     221             :                                         char **papszOptions) = nullptr;
     222             :     CPLErr (*pfnDeleteDataSource)(GDALDriver *, const char *pszName) = nullptr;
     223             : 
     224             :     /** Whether pfnVectorTranslateFrom() can be run given the source dataset
     225             :      * and the non-positional arguments of GDALVectorTranslate() stored
     226             :      * in papszVectorTranslateArguments.
     227             :      */
     228             :     bool (*pfnCanVectorTranslateFrom)(
     229             :         const char *pszDestName, GDALDataset *poSourceDS,
     230             :         CSLConstList papszVectorTranslateArguments,
     231             :         char ***ppapszFailureReasons) = nullptr;
     232             : 
     233             :     /** Creates a copy from the specified source dataset, using the
     234             :      * non-positional arguments of GDALVectorTranslate() stored
     235             :      * in papszVectorTranslateArguments.
     236             :      */
     237             :     GDALDataset *(*pfnVectorTranslateFrom)(
     238             :         const char *pszDestName, GDALDataset *poSourceDS,
     239             :         CSLConstList papszVectorTranslateArguments,
     240             :         GDALProgressFunc pfnProgress, void *pProgressData) = nullptr;
     241             : 
     242             :     /**
     243             :      * Returns a (possibly null) pointer to the Subdataset informational function
     244             :      * from the subdataset file name.
     245             :      */
     246             :     GDALSubdatasetInfo *(*pfnGetSubdatasetInfoFunc)(const char *pszFileName) =
     247             :         nullptr;
     248             : 
     249             :     typedef GDALAlgorithm *(*InstantiateAlgorithmCallback)(
     250             :         const std::vector<std::string> &aosPath);
     251             :     InstantiateAlgorithmCallback pfnInstantiateAlgorithm = nullptr;
     252             : 
     253          56 :     virtual InstantiateAlgorithmCallback GetInstantiateAlgorithmCallback()
     254             :     {
     255          56 :         return pfnInstantiateAlgorithm;
     256             :     }
     257             : 
     258             :     /** Instantiate an algorithm by its full path (omitting leading "gdal").
     259             :      * For example {"driver", "pdf", "list-layers"}
     260             :      */
     261             :     GDALAlgorithm *
     262             :     InstantiateAlgorithm(const std::vector<std::string> &aosPath);
     263             : 
     264             :     /** Declare an algorithm by its full path (omitting leading "gdal").
     265             :      * For example {"driver", "pdf", "list-layers"}
     266             :      */
     267             :     void DeclareAlgorithm(const std::vector<std::string> &aosPath);
     268             : 
     269             :     //! @endcond
     270             : 
     271             :     /* -------------------------------------------------------------------- */
     272             :     /*      Helper methods.                                                 */
     273             :     /* -------------------------------------------------------------------- */
     274             :     //! @cond Doxygen_Suppress
     275             :     GDALDataset *DefaultCreateCopy(const char *, GDALDataset *, int,
     276             :                                    CSLConstList papszOptions,
     277             :                                    GDALProgressFunc pfnProgress,
     278             :                                    void *pProgressData) CPL_WARN_UNUSED_RESULT;
     279             : 
     280             :     static CPLErr DefaultCreateCopyMultiDimensional(
     281             :         GDALDataset *poSrcDS, GDALDataset *poDstDS, bool bStrict,
     282             :         CSLConstList /*papszOptions*/, GDALProgressFunc pfnProgress,
     283             :         void *pProgressData);
     284             : 
     285             :     static CPLErr DefaultCopyMasks(GDALDataset *poSrcDS, GDALDataset *poDstDS,
     286             :                                    int bStrict);
     287             :     static CPLErr DefaultCopyMasks(GDALDataset *poSrcDS, GDALDataset *poDstDS,
     288             :                                    int bStrict, CSLConstList papszOptions,
     289             :                                    GDALProgressFunc pfnProgress,
     290             :                                    void *pProgressData);
     291             : 
     292             :     CPLErr QuietDeleteForCreateCopy(const char *pszFilename,
     293             :                                     GDALDataset *poSrcDS);
     294             : 
     295             :     //! @endcond
     296             :     static CPLErr QuietDelete(const char *pszName,
     297             :                               CSLConstList papszAllowedDrivers = nullptr);
     298             : 
     299             :     //! @cond Doxygen_Suppress
     300             :     static CPLErr DefaultRename(const char *pszNewName, const char *pszOldName);
     301             :     static CPLErr DefaultCopyFiles(const char *pszNewName,
     302             :                                    const char *pszOldName);
     303             :     static void DefaultCopyMetadata(GDALDataset *poSrcDS, GDALDataset *poDstDS,
     304             :                                     CSLConstList papszOptions,
     305             :                                     CSLConstList papszExcludedDomains);
     306             : 
     307             :     //! @endcond
     308             : 
     309             :     /** Convert a GDALDriver* to a GDALDriverH.
     310             :      * @since GDAL 2.3
     311             :      */
     312      175112 :     static inline GDALDriverH ToHandle(GDALDriver *poDriver)
     313             :     {
     314      175112 :         return static_cast<GDALDriverH>(poDriver);
     315             :     }
     316             : 
     317             :     /** Convert a GDALDriverH to a GDALDriver*.
     318             :      * @since GDAL 2.3
     319             :      */
     320     3944439 :     static inline GDALDriver *FromHandle(GDALDriverH hDriver)
     321             :     {
     322     3944439 :         return static_cast<GDALDriver *>(hDriver);
     323             :     }
     324             : 
     325             :   private:
     326             :     CPL_DISALLOW_COPY_ASSIGN(GDALDriver)
     327             : };
     328             : 
     329             : // Macro used so that Identify and driver metadata methods in drivers built
     330             : // as plugin can be duplicated in libgdal core and in the driver under different
     331             : // names
     332             : #ifdef PLUGIN_FILENAME
     333             : #define PLUGIN_SYMBOL_NAME(x) GDAL_core_##x
     334             : #else
     335             : #define PLUGIN_SYMBOL_NAME(x) GDAL_driver_##x
     336             : #endif
     337             : 
     338             : #endif

Generated by: LCOV version 1.14