LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/generic - ogrsfdriver.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 34 67 50.7 %
Date: 2024-11-25 23:50:41 Functions: 4 10 40.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  The generic portions of the OGRSFDriver class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999,  Les Technologies SoftMap Inc.
       9             :  * Copyright (c) 2009-2011, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #include "ogrsf_frmts.h"
      15             : #include "ogr_api.h"
      16             : #include "ogr_p.h"
      17             : #include "ograpispy.h"
      18             : 
      19             : //! @cond Doxygen_Suppress
      20             : 
      21             : /************************************************************************/
      22             : /*                            ~OGRSFDriver()                            */
      23             : /************************************************************************/
      24             : 
      25           0 : OGRSFDriver::~OGRSFDriver()
      26             : 
      27             : {
      28           0 : }
      29             : 
      30             : /************************************************************************/
      31             : /*                          CreateDataSource()                          */
      32             : /************************************************************************/
      33             : 
      34           0 : OGRDataSource *OGRSFDriver::CreateDataSource(const char *, char **)
      35             : 
      36             : {
      37           0 :     CPLError(CE_Failure, CPLE_NotSupported,
      38             :              "CreateDataSource() not supported by this driver.\n");
      39             : 
      40           0 :     return nullptr;
      41             : }
      42             : 
      43             : /************************************************************************/
      44             : /*                      OGR_Dr_CreateDataSource()                       */
      45             : /************************************************************************/
      46             : 
      47          35 : OGRDataSourceH OGR_Dr_CreateDataSource(OGRSFDriverH hDriver,
      48             :                                        const char *pszName, char **papszOptions)
      49             : 
      50             : {
      51          35 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_CreateDataSource", nullptr);
      52             : 
      53          35 :     GDALDriver *poDriver = reinterpret_cast<GDALDriver *>(hDriver);
      54             : 
      55             :     /* MapServer had the bad habit of calling with NULL name for a memory
      56             :      * datasource */
      57          35 :     if (pszName == nullptr)
      58           0 :         pszName = "";
      59             : 
      60             :     OGRDataSourceH hDS = reinterpret_cast<OGRDataSourceH>(
      61          35 :         poDriver->Create(pszName, 0, 0, 0, GDT_Unknown, papszOptions));
      62             : 
      63             : #ifdef OGRAPISPY_ENABLED
      64          35 :     OGRAPISpyCreateDataSource(hDriver, pszName, papszOptions,
      65             :                               reinterpret_cast<OGRDataSourceH>(hDS));
      66             : #endif
      67             : 
      68          35 :     return hDS;
      69             : }
      70             : 
      71             : /************************************************************************/
      72             : /*                          DeleteDataSource()                          */
      73             : /************************************************************************/
      74             : 
      75           0 : OGRErr OGRSFDriver::DeleteDataSource(const char *pszDataSource)
      76             : 
      77             : {
      78             :     (void)pszDataSource;
      79           0 :     CPLError(CE_Failure, CPLE_NotSupported,
      80             :              "DeleteDataSource() not supported by this driver.");
      81             : 
      82           0 :     return OGRERR_UNSUPPORTED_OPERATION;
      83             : }
      84             : 
      85             : /************************************************************************/
      86             : /*                      OGR_Dr_DeleteDataSource()                       */
      87             : /************************************************************************/
      88             : 
      89           1 : OGRErr OGR_Dr_DeleteDataSource(OGRSFDriverH hDriver, const char *pszDataSource)
      90             : 
      91             : {
      92           1 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_DeleteDataSource",
      93             :                       OGRERR_INVALID_HANDLE);
      94             : 
      95             : #ifdef OGRAPISPY_ENABLED
      96           1 :     OGRAPISpyDeleteDataSource(hDriver, pszDataSource);
      97             : #endif
      98             : 
      99             :     CPLErr eErr =
     100           1 :         reinterpret_cast<GDALDriver *>(hDriver)->Delete(pszDataSource);
     101           1 :     if (eErr == CE_None)
     102           1 :         return OGRERR_NONE;
     103             :     else
     104           0 :         return OGRERR_FAILURE;
     105             : }
     106             : 
     107             : /************************************************************************/
     108             : /*                           OGR_Dr_GetName()                           */
     109             : /************************************************************************/
     110             : 
     111           0 : const char *OGR_Dr_GetName(OGRSFDriverH hDriver)
     112             : 
     113             : {
     114           0 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_GetName", nullptr);
     115             : 
     116           0 :     return reinterpret_cast<GDALDriver *>(hDriver)->GetDescription();
     117             : }
     118             : 
     119             : /************************************************************************/
     120             : /*                            OGR_Dr_Open()                             */
     121             : /************************************************************************/
     122             : 
     123          16 : OGRDataSourceH OGR_Dr_Open(OGRSFDriverH hDriver, const char *pszName,
     124             :                            int bUpdate)
     125             : 
     126             : {
     127          16 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_Open", nullptr);
     128             : 
     129          16 :     const char *const apszDrivers[] = {
     130          16 :         reinterpret_cast<GDALDriver *>(hDriver)->GetDescription(), nullptr};
     131             : 
     132             : #ifdef OGRAPISPY_ENABLED
     133          16 :     int iSnapshot = OGRAPISpyOpenTakeSnapshot(pszName, bUpdate);
     134             : #endif
     135             : 
     136             :     GDALDatasetH hDS =
     137          16 :         GDALOpenEx(pszName, GDAL_OF_VECTOR | ((bUpdate) ? GDAL_OF_UPDATE : 0),
     138          16 :                    apszDrivers, nullptr, nullptr);
     139             : 
     140             : #ifdef OGRAPISPY_ENABLED
     141          16 :     OGRAPISpyOpen(pszName, bUpdate, iSnapshot, &hDS);
     142             : #endif
     143             : 
     144          16 :     return reinterpret_cast<OGRDataSourceH>(hDS);
     145             : }
     146             : 
     147             : /************************************************************************/
     148             : /*                       OGR_Dr_TestCapability()                        */
     149             : /************************************************************************/
     150             : 
     151           6 : int OGR_Dr_TestCapability(OGRSFDriverH hDriver, const char *pszCap)
     152             : 
     153             : {
     154           6 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_TestCapability", 0);
     155           6 :     VALIDATE_POINTER1(pszCap, "OGR_Dr_TestCapability", 0);
     156             : 
     157           6 :     GDALDriver *poDriver = reinterpret_cast<GDALDriver *>(hDriver);
     158           6 :     if (EQUAL(pszCap, ODrCCreateDataSource))
     159             :     {
     160           1 :         return poDriver->GetMetadataItem(GDAL_DCAP_CREATE) ||
     161           1 :                poDriver->pfnCreate != nullptr ||
     162           1 :                poDriver->pfnCreateVectorOnly != nullptr;
     163             :     }
     164           5 :     else if (EQUAL(pszCap, ODrCDeleteDataSource))
     165             :     {
     166           1 :         return poDriver->pfnDelete != nullptr ||
     167           1 :                poDriver->pfnDeleteDataSource != nullptr;
     168             :     }
     169             :     else
     170           4 :         return FALSE;
     171             : }
     172             : 
     173             : /************************************************************************/
     174             : /*                       OGR_Dr_CopyDataSource()                        */
     175             : /************************************************************************/
     176             : 
     177           0 : OGRDataSourceH OGR_Dr_CopyDataSource(OGRSFDriverH hDriver,
     178             :                                      OGRDataSourceH hSrcDS,
     179             :                                      const char *pszNewName,
     180             :                                      char **papszOptions)
     181             : 
     182             : {
     183           0 :     VALIDATE_POINTER1(hDriver, "OGR_Dr_CopyDataSource", nullptr);
     184           0 :     VALIDATE_POINTER1(hSrcDS, "OGR_Dr_CopyDataSource", nullptr);
     185           0 :     VALIDATE_POINTER1(pszNewName, "OGR_Dr_CopyDataSource", nullptr);
     186             : 
     187           0 :     GDALDriver *poDriver = reinterpret_cast<GDALDriver *>(hDriver);
     188           0 :     if (!poDriver->GetMetadataItem(GDAL_DCAP_CREATE))
     189             :     {
     190           0 :         CPLError(CE_Failure, CPLE_NotSupported,
     191             :                  "%s driver does not support data source creation.",
     192           0 :                  poDriver->GetDescription());
     193           0 :         return nullptr;
     194             :     }
     195             : 
     196           0 :     GDALDataset *poSrcDS = GDALDataset::FromHandle(hSrcDS);
     197             :     GDALDataset *poODS =
     198           0 :         poDriver->Create(pszNewName, 0, 0, 0, GDT_Unknown, papszOptions);
     199           0 :     if (poODS == nullptr)
     200           0 :         return nullptr;
     201             : 
     202             :     /* -------------------------------------------------------------------- */
     203             :     /*      Process each data source layer.                                 */
     204             :     /* -------------------------------------------------------------------- */
     205           0 :     for (int iLayer = 0; iLayer < poSrcDS->GetLayerCount(); iLayer++)
     206             :     {
     207           0 :         OGRLayer *poLayer = poSrcDS->GetLayer(iLayer);
     208             : 
     209           0 :         if (poLayer == nullptr)
     210           0 :             continue;
     211             : 
     212           0 :         poODS->CopyLayer(poLayer, poLayer->GetLayerDefn()->GetName(),
     213           0 :                          papszOptions);
     214             :     }
     215             : 
     216           0 :     return reinterpret_cast<OGRDataSourceH>(poODS);
     217             : }
     218             : 
     219             : //! @endcond

Generated by: LCOV version 1.14